public virtual async Task <HtmlEventMarkupModelDto> GetHtmlEventMarkupByEvent(Guid?eventId) { if (!eventId.HasValue || eventId == Guid.Empty) { throw new IdNullOrEmptyException(); } var model = await _notificationsContext.HtmlEventMarkups.FirstAsync(x => x.EventId == eventId); if (model == null) { throw new NotFoundException(typeof(HtmlEventMarkup).Name, eventId.ToString()); } var entity = new HtmlEventMarkupModelDto() { Id = model.Id, Subject = model.Subject, Name = model.Name, EventId = model.EventId, Subtitle = model.Subtitle, ChangesMarkup = model.ChangesMarkup }; return(entity); }
public virtual async Task UpdateHtmlEventMarkup(HtmlEventMarkupModelDto model) { var entity = await _notificationsContext.HtmlEventMarkups.FindAsync(model.Id); if (entity == null) { throw new NotFoundException(typeof(HtmlEventMarkup).Name, model.Id.ToString()); } entity.Name = model.Name; entity.Subject = model.Subject; entity.Subtitle = model.Subtitle; entity.ChangesMarkup = model.ChangesMarkup; _notificationsContext.Update(entity); await _notificationsContext.SaveChangesAsync(); }
public virtual async Task CreateHtmlEventMarkup(HtmlEventMarkupModelDto model) { var entity = new HtmlEventMarkup() { Id = Guid.NewGuid(), Name = model.Name, Subject = model.Subject, Subtitle = model.Subtitle, ChangesMarkup = model.ChangesMarkup, EventId = model.EventId }; await _notificationsContext.HtmlEventMarkups.AddAsync(entity); var eventEntity = await _notificationsContext.Events.FindAsync(entity.EventId); if (eventEntity == null) { throw new NotFoundException(typeof(Event).Name, entity.EventId.ToString()); } eventEntity.HtmlEventMarkupId = entity.Id; _notificationsContext.Events.Update(eventEntity); await _notificationsContext.SaveChangesAsync(); }