private Mail Modify(EventMailSenderUpdated evt, Mail item) { item.EventGuid = evt.EventId; item.Value1 = evt.MailSenderValue1; item.Value2 = evt.MailSenderValue2; return(item); }
public async Task Update(CommandMailSenderUpdate cmd) { var item = db.Mails.FirstOrDefault(u => u.MailId == cmd.MailSenderId); if (item != null) { var ev = new EventMailSenderUpdated() { EventId = Guid.NewGuid(), MailSenderValue1 = cmd.MailSenderValue1, MailSenderValue2 = cmd.MailSenderValue2, }; ev.Generation = item.Generation + 1; item = Modify(ev, item); await _handler.PublishEvent(ev, MessageType.MailSenderUpdated, ev.EventId, item.EventGuid, ev.Generation, cmd.MailSenderId); db.Mails.Update(item); await db.SaveChangesAsync(); } }