public async Task Remove(CommandAktivitaRemove cmd) { var remove = db.Aktivity.Find(cmd.AktivitaId); db.Aktivity.Remove(remove); var ev = new EventAktivitaRemoved() { Generation = remove.Generation + 1, EventId = Guid.NewGuid(), UzivatelId = cmd.AktivitaId, }; await _handler.PublishEvent(ev, MessageType.AktivitaRemoved, ev.EventId, null, ev.Generation, ev.AktivitaId); await db.SaveChangesAsync(); }
public async Task DeleteByAktivita(EventAktivitaRemoved evt) { var interval = (evt.DatumDo - evt.DatumOd).TotalDays; var _tmpYear = evt.DatumOd.Year; var item = db.Kalendare.FirstOrDefault(k => k.UzivatelId == evt.UzivatelId && k.Rok == _tmpYear); var kalendar = JsonConvert.DeserializeObject <Year>(item.Body); for (int i = 0; i <= interval; i++) { var focus = evt.DatumOd.AddDays(i); if (_tmpYear != focus.Year) { _tmpYear = focus.Year; item = db.Kalendare.FirstOrDefault(k => k.UzivatelId == evt.UzivatelId && k.Rok == _tmpYear); kalendar = JsonConvert.DeserializeObject <Year>(item.Body); } var mesic = kalendar.Months[focus.Month - 1]; var den = mesic.Days[focus.Day - 1]; var polozka = den.Polozky.Where(p => p.Id == evt.AktivitaId).FirstOrDefault(); if (polozka != null) { den.Polozky.Remove(polozka); var result = JsonConvert.SerializeObject(kalendar); item.DatumAktualizace = evt.EventCreated; item.Body = result; item.EventGuid = evt.EventId; item.Generation = evt.Generation; db.Kalendare.Update(item); await db.SaveChangesAsync(); var ev = new EventKalendarUpdated() { CeleJmeno = item.UzivatelCeleJmeno, EventCreated = DateTime.Now, EventId = Guid.NewGuid(), Generation = item.Generation + 1, SourceGuid = evt.EventId, UzivatelId = evt.UzivatelId, Body = item.Body, }; await _handler.PublishEvent(ev, MessageType.KalendarUpdated, ev.EventId, null, ev.Generation, item.KalendarId); } } await db.SaveChangesAsync(); }
public async Task DeleteByAktivita(EventAktivitaRemoved evt) { await db.SaveChangesAsync(); }
private void RemoveByAktivita(EventAktivitaRemoved evt) { _repository.DeleteByAktivita(evt); }