public IActionResult AddOrUpdateGroup(AddOrUpdateGroupDto addOrUpdateGroupDto) { if (ModelState.IsValid) { groupService.AddOrUpdate(addOrUpdateGroupDto); return(RedirectToAction("Index")); } return(View()); }
public GroupVm AddOrUpdateGroup(AddOrUpdateGroupDto addOrUpdateGroupDto) { if (addOrUpdateGroupDto == null) { throw new ArgumentNullException($"Dto of type is null"); } var groupEntity = Mapper.Map <Group>(addOrUpdateGroupDto); if (addOrUpdateGroupDto.Id == null || addOrUpdateGroupDto.Id == 0) { _dbContext.Groups.Add(groupEntity); } else { _dbContext.Groups.Update(groupEntity); } _dbContext.SaveChanges(); var groupVm = Mapper.Map <GroupVm>(groupEntity); return(groupVm); }
public GroupVm AddOrUpdate(AddOrUpdateGroupDto addOrUpdateGroupDto) { if (addOrUpdateGroupDto == null) { throw new Exception("Group null"); } var group = Mapper.Map <Group>(addOrUpdateGroupDto); if (addOrUpdateGroupDto.Id == 0) { _dbContext.Groups.Add(group); _dbContext.SaveChanges(); } if (addOrUpdateGroupDto.Name != null) { _dbContext.Groups.Update(group); } _dbContext.SaveChanges(); var groupVm = Mapper.Map <GroupVm>(group); return(groupVm); }