Source

main-vinayFork / Source / WebClient / Web.BizLogic / Services / ProfileService.cs

using DataUp.Web.DataLayer;

namespace DataUp.Web.BizLogic
{
    public class ProfileService : IProfileService
    {
        private readonly IUserRepository userRepository;

        public ProfileService(IUserRepository dataRepository)
        {
            userRepository = dataRepository;
        }

        public Model.User GetUser(string nameIdentifier, string identityProvider)
        {
            User dbUser = userRepository.GetUser(nameIdentifier, identityProvider);
            if (dbUser == null)
            {
                return null;
            }

            Model.User user = new Model.User()
            {
                Id = dbUser.Id,
                NameIdentifier = dbUser.NameIdentifier,
                IdentityProvider = dbUser.IdentityProvider,
                FirstName = dbUser.FirstName,
                LastName = dbUser.LastName,
                MiddleName = dbUser.MiddleName,
                Organization = dbUser.Organization,
                EmailId = dbUser.EmailId
            };

            return user;
        }

        public int AddUser(Model.User user)
        {
            User dbUser = new User()
            {
                NameIdentifier = user.NameIdentifier,
                IdentityProvider = user.IdentityProvider,
                FirstName = user.FirstName,
                Organization = user.Organization,
                LastName = user.LastName,
                MiddleName = user.MiddleName,
                EmailId = user.EmailId
            };

            userRepository.Add(dbUser);

            userRepository.SaveChanges();

            return user.Id;
        }


        public void UpdateUser(Model.User user)
        {
            User dbUser = userRepository.GetItem(item => item.Id == user.Id);

            dbUser.NameIdentifier = user.NameIdentifier;
            dbUser.IdentityProvider = user.IdentityProvider;
            dbUser.FirstName = user.FirstName;
            dbUser.Organization = user.Organization;
            dbUser.LastName = user.LastName;
            dbUser.MiddleName = user.MiddleName;
            dbUser.EmailId = user.EmailId;

            userRepository.Update(dbUser);

            userRepository.SaveChanges();
        }
    }
}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.