public async Task <ServiceResult> EditMailingGroup(MailingGroupUpdateModel model)
        {
            try
            {
                var duplicatedName = await _context
                                     .MailingGroups
                                     .AnyAsync(x => !x.IsDeleted && x.Name == model.Name && x.Id != model.Id);

                if (duplicatedName)
                {
                    return(ServiceResult.Failed(ServiceMessages.ErrorOnEditDuplicateName));
                }
                var updateEntry = _mapper.Map <MailingGroup>(model);

                _context
                .MailingGroups
                .Update(updateEntry);

                await _context.SaveChangesAsync();

                return(ServiceResult.Succeed());
            }
            catch (Exception)
            {
                return(ServiceResult.Failed(ServiceMessages.ErrorOnEdit));
            }
        }
Exemple #2
0
        public async Task <IActionResult> UpdateMailingGroup(MailingGroupUpdateModel data)
        {
            var result = await _mailingGroupService.EditMailingGroup(data);

            if (result.Success)
            {
                return(Ok());
            }
            return(BadRequest(result.GetErrors()));
        }