Ejemplo n.º 1
0
        public GroupVM CreateOrUpdateGroup(GroupForCreateOrUpdateDTO groupForCreateOrUpdateDTO)
        {
            if (groupForCreateOrUpdateDTO == null)
            {
                throw new ArgumentNullException($"DTO is null");
            }
            var groupEntity = _mapper.Map <Group>(groupForCreateOrUpdateDTO);

            if (groupForCreateOrUpdateDTO.Id == null || groupForCreateOrUpdateDTO.Id == 0)
            {
                _dbContext.Groups.Add(groupEntity);
            }
            else
            {
                _dbContext.Groups.Update(groupEntity);
            }
            try
            {
                if (_dbContext.SaveChanges() < 1)
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                return(null);
            }
            var groupVM = _mapper.Map <GroupVM>(groupEntity);

            return(groupVM);
        }
 public IActionResult CreateOrUpdate(GroupForCreateOrUpdateDTO groupForCreateOrUpdateDTO)
 {
     if (ModelState.IsValid)
     {
         if (_groupService.CreateOrUpdateGroup(groupForCreateOrUpdateDTO) == null)
         {
             return(View("Error", new ErrorViewModel()
             {
                 Description = "This group already exists!"
             }));
         }
         return(RedirectToAction("Index"));
     }
     return(View());
 }