public async Task <int> Update(string id, MailTempContent mailTempContent) { return(await Context.SaveChangesAsync()); }
public async Task <ActionResultResponse> Insert(string tenantId, MailTempContentMeta mailTempContentMeta) { if (!mailTempContentMeta.MailTempContentTranslations.Any()) { return(new ActionResultResponse(-1, _sharedResourceService.GetString("Please enter at least one mailTempContentTranslation."))); } var mailTempContentId = Guid.NewGuid().ToString(); var mailTempContent = new MailTempContent { Id = mailTempContentId, TenantId = tenantId, MailTempGroupId = mailTempContentMeta.MailTempGroupId, IsDelete = mailTempContentMeta.IsDelete, IsActive = mailTempContentMeta.IsActive, IsDefault = mailTempContentMeta.IsDefault, StartTime = mailTempContentMeta.StartTime, EndTime = mailTempContentMeta.EndTime, }; var itemActive = await _mailTempContentRepository.MailTempContentActive(tenantId, mailTempContentMeta.MailTempGroupId); if (itemActive != null) { if (mailTempContentMeta.IsActive) { itemActive.IsActive = false; await _mailTempContentRepository.Update(itemActive.Id, itemActive); } } var result = await _mailTempContentRepository.Insert(mailTempContent); if (result <= 0) { return(new ActionResultResponse(result, _sharedResourceService.GetString("Something went wrong. Please contact with administrator."))); } var mailTempContentTranslations = new List <MailTempContentTranslation>(); foreach (var mailTempContentTranslation in mailTempContentMeta.MailTempContentTranslations) { mailTempContentTranslations.Add(new MailTempContentTranslation { MailTempContentId = mailTempContentId, TenantId = tenantId, LanguageId = mailTempContentTranslation.LanguageId, Title = mailTempContentTranslation.Title, UnsignTitle = mailTempContentTranslation.Title.Trim().StripVietnameseChars().ToUpper(), ContentMail = mailTempContentTranslation.ContentMail, Description = mailTempContentTranslation.Description, }); } var resultInsertDetail = await _mailTempContentTranslationRepository.Inserts(mailTempContentTranslations); if (resultInsertDetail > 0) { return(new ActionResultResponse(resultInsertDetail, _resourceService.GetString("Add new MailTempContentTranslation successful."))); } await RollbackInsert(mailTempContentId); return(new ActionResultResponse(-5, _resourceService.GetString("Can not insert new MailTempContent. Please contact with administrator."))); }
public async Task <int> Insert(MailTempContent mailTempContent) { _mailTempContentRepository.Create(mailTempContent); return(await Context.SaveChangesAsync()); }