Example #1
0
        public async Task <GroupDTO> PatchAsync(GroupUpdateDTO group)
        {
            this.Logger.LogTrace($"{nameof(this.PutAsync)} called");

            var result = await this.GroupUpdateService.UpdateAsync(this.Mapper.Map <GroupUpdateModel>(group));

            return(this.Mapper.Map <GroupDTO>(result));
        }
Example #2
0
 public async Task <ActionResult <GroupDTO> > UpdateAsync([FromBody] GroupUpdateDTO model)
 {
     try
     {
         return(Ok(await groupService.UpdateAsync(model)));
     }
     catch (NotFoundException e)
     {
         return(NotFound(new { Id = e.Key, e.Message }));
     }
     catch (ValidationException e)
     {
         return(BadRequest(e.ValidationErrors));
     }
 }
Example #3
0
        public async Task <ActionResult> UpdateGroup([FromBody] GroupUpdateDTO model)
        {
            if (ModelState.IsValid)
            {
                var groupApplicationUser = _userManager.Users.SingleOrDefault(u => u.UserName == model.Name);

                //check if group exists
                if (groupApplicationUser == null)
                {
                    return(Ok(
                               new
                    {
                        Message = "Groep niet teruggevonden."
                    }));
                }

                var group = await _groupRepository.GetById(model.GroupId);

                // name was updated.
                if (!group.Name.ToLower().Equals(model.Name.ToLower()))
                {
                    groupApplicationUser.UserName = model.Name;
                    group.Name = model.Name;
                }

                // password was updated.
                if (!string.IsNullOrWhiteSpace(model.Password))
                {
                    groupApplicationUser.PasswordHash = model.Password;
                }

                if (model.Members != null && model.Members.Count > 0)
                {
                    group.Members = model.Members;
                }

                group = _groupRepository.Update(group);
                await _groupRepository.SaveChanges();

                return(Ok(group));
            }

            return(Ok(
                       new
            {
                Message = "Zorg dat naam ingevuld is."
            }));
        }