Ejemplo n.º 1
0
        public async Task <IActionResult> Patch(int id, UserToEditDto userDto)
        {
            try
            {
                if (!await _serviceManager.User.Update(id, userDto))
                {
                    return(BadRequest());
                }

                return(Ok());
            }
            catch (System.Exception e)
            {
                return(HandleException(e));
            }
        }
Ejemplo n.º 2
0
        public async Task <bool> Update(int id, UserToEditDto entity)
        {
            var entityToUpdate = await this._unitOfWork.User.GetAll()
                                 .Include(x => x.UserRole)
                                 .Where(x => x.Id == id)
                                 .SingleOrDefaultAsync();

            if (entityToUpdate == null)
            {
                throw new Exception("Not Found.");
            }

            entityToUpdate.UserRole = new List <UserRole>();

            if (entity.UserRole.Count() > 0)
            {
                foreach (var userRole in entity.UserRole)
                {
                    entityToUpdate.UserRole.Add(new UserRole {
                        RoleId = userRole, UserId = id
                    });
                }
            }

            entityToUpdate.UserName = entity.Username;
            entityToUpdate.IsActive = entity.IsActive;
            entityToUpdate.Phone    = entity.Phone;
            entityToUpdate.Email    = entity.Email;
            entityToUpdate.Name     = entity.Name;

            _unitOfWork.User.Update(entityToUpdate);


            if (_unitOfWork.Complete() > 0)
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 3
0
        public async Task <bool> Update(int id, UserToEditDto entity)
        {
            var entityToUpdate = await this._unitOfWork.User.Get(id);

            if (entityToUpdate == null)
            {
                throw new Exception("Not Found.");
            }

            entityToUpdate.Username = entity.Username;
            entityToUpdate.IsActive = entity.IsActive;
            entityToUpdate.Gender   = entity.Gender;
            entityToUpdate.Email    = entity.Email;
            entityToUpdate.Name     = entity.Name;

            _unitOfWork.User.Update(entityToUpdate);

            if (_unitOfWork.Complete() > 0)
            {
                return(true);
            }

            return(false);
        }