public async Task <ServiceResult> AddMailingGroup(MailingGroupCreateModel model) { try { var duplicatedName = await _context .MailingGroups .AnyAsync(x => !x.IsDeleted && x.Name == model.Name); if (duplicatedName) { return(ServiceResult.Failed(ServiceMessages.ErrorOnAddDuplicateName)); } var newEntity = _mapper.Map <MailingGroup>(model); _context .MailingGroups .Add(newEntity); await _context.SaveChangesAsync(); return(ServiceResult.Succeed()); } catch (Exception) { return(ServiceResult.Failed(ServiceMessages.ErrorOnAdd)); } }
public async Task <IActionResult> AddMailingGroup(MailingGroupCreateModel data) { var result = await _mailingGroupService.AddMailingGroup(data); if (result.Success) { return(Ok()); } return(BadRequest(result.GetErrors())); }