public IActionResult Update([FromBody] SupportUser user)
 {
     if (user == null)
     {
         return(BadRequest());
     }
     return(Ok(this._userService.UpdateUser(user)));
 }
        public IActionResult Create([FromBody] SupportUser user)
        {
            if (user == null)
            {
                return(BadRequest());
            }
            // Todo : Change thiis later - Use some logic like Ew

            var password = string.IsNullOrEmpty(user.Password) ? "DDdd@1234" : user.Password;

            user.Password = password;
            return(Ok(this._userService.CreateUser(user)));
        }
Example #3
0
        ApolloUser MapToUpdateEntity(SupportUser user)
        {
            var apolloUser = this._userRepository.Get(user.Id);

            // ApolloUser apolloUser = this._userRepository.FindById(user.Id).Result;
            //var apolloUser = new ApolloUser();
            // apolloUser.Id = user.Id;
            apolloUser.FirstName   = user.FirstName;
            apolloUser.LastName    = user.LastName;
            apolloUser.UserName    = user.UserName;
            apolloUser.Email       = user.Email;
            apolloUser.PhoneNumber = user.PhoneNumber;
            // apolloUser.UserTypeId = user.UserType;
            apolloUser.IsActive = user.IsActive;

            // apolloUser.CreatedBy = user.CreatedBy;
            // apolloUser.CreatedDate = DateTime.UtcNow;
            apolloUser.UpdatedBy   = user.UpdatedBy;
            apolloUser.UpdatedDate = DateTime.UtcNow;
            apolloUser.ObjectState = user.ObjectState;

            this._userAppRoleMappingRepository.RemoveAll(apolloUser.UserAppRoleMappings.ToArray());
            apolloUser.UserAppRoleMappings.Clear();

            foreach (var item in user.UserApplicationRole)
            {
                apolloUser.UserAppRoleMappings.Add(new Apollo.Domain.Entity.UserAppRoleMapping
                {
                    // Id = item.Id == null ? Guid.NewGuid() : item.Id.Value,
                    Id            = Guid.NewGuid(),
                    ApplicationId = item.ApplicationId,
                    RoleId        = item.RoleId,
                    IsActive      = true,
                    ObjectState   = item.ObjectState,
                    CreatedBy     = user.CreatedBy,
                    CreatedDate   = DateTime.UtcNow,
                    UpdatedBy     = user.UpdatedBy,
                    UpdatedDate   = DateTime.UtcNow
                });
            }

            return(apolloUser);
        }
Example #4
0
        ApolloUser MapToEntity(SupportUser user)
        {
            var apolloUser = new ApolloUser();

            apolloUser.FirstName   = user.FirstName;
            apolloUser.LastName    = user.LastName;
            apolloUser.UserName    = user.UserName;
            apolloUser.Email       = user.Email;
            apolloUser.PhoneNumber = user.PhoneNumber;
            apolloUser.UserTypeId  = user.UserType;
            apolloUser.IsActive    = user.IsActive;

            apolloUser.CreatedBy   = user.CreatedBy;
            apolloUser.CreatedDate = DateTime.UtcNow;
            apolloUser.UpdatedBy   = user.UpdatedBy;
            apolloUser.UpdatedDate = DateTime.UtcNow;
            apolloUser.ObjectState = user.ObjectState;


            apolloUser.UserAppRoleMappings.Clear();

            foreach (var item in user.UserApplicationRole)
            {
                apolloUser.UserAppRoleMappings.Add(new Apollo.Domain.Entity.UserAppRoleMapping
                {
                    Id            = Guid.NewGuid(),
                    ApplicationId = item.ApplicationId,
                    RoleId        = item.RoleId,
                    IsActive      = true,
                    ObjectState   = item.ObjectState,
                    CreatedBy     = user.CreatedBy,
                    CreatedDate   = DateTime.UtcNow,
                    UpdatedBy     = user.UpdatedBy,
                    UpdatedDate   = DateTime.UtcNow
                });
            }

            return(apolloUser);
        }
Example #5
0
 public Task <IdentityResult> UpdateUser(SupportUser user)
 {
     return(this._userRepository.Update(this.MapToUpdateEntity(user)));
 }
Example #6
0
 // Todo: User a single methods for Add and Update since they are same  or are they ??
 public Task <IdentityResult> CreateUser(SupportUser user)
 {
     // Map manually DTO --> Entity
     //Todo Handle Error from services            ;
     return(this._userRepository.Add(this.MapToEntity(user), user.Password));
 }