public IActionResult DeleteEvent(Guid id) { var eventFromRepository = _calendarRepository.GetEvent(id); if (eventFromRepository == null) { return(NotFound()); } _calendarRepository.DeleteEvent(eventFromRepository); if (!_calendarRepository.Save()) { throw new Exception("Failed to delete EventEntity on save."); } return(NoContent()); }
public IActionResult ScheduleNewEvent(ScheduleCalendarEventDto scheduleCalendarEventDto) { if (!ModelState.IsValid) { return(View(scheduleCalendarEventDto)); } var mappedCalendarEvent = Mapper.Map <CalendarEvent>(scheduleCalendarEventDto); _calendarEventRepository.AddEvent(mappedCalendarEvent); if (!_calendarEventRepository.Save()) { return(View(scheduleCalendarEventDto)); } return(RedirectToAction("Week", "Calendar")); }
public async Task <int> Handle(AddNewCalendarEventCommand command, CancellationToken cancellationToken) { var calendarEvent = new CalendarEvent( command.Name, command.Time, command.Location, command.EventOrganizer ); foreach (var memberName in command.Members) { calendarEvent.AddMember(memberName); } await _calendarEventRepository.Save(calendarEvent); return(calendarEvent.Id); }
public async Task <Unit> Handle(EditCalendarEventCommand command, CancellationToken cancellationToken) { var calendarEvent = await _calendarEventRepository.FindOne(command.Id); if (calendarEvent == null) { throw new ResourceNotFoundException(); } calendarEvent.Edit( command.Name, command.Time, command.Location, command.EventOrganizer ); calendarEvent.EditMembers(command.Members); await _calendarEventRepository.Save(calendarEvent); return(Unit.Value); }