public ActionResult EditEvent(EventViewData model) { if (model.EventLead == null) { model.EventLead = "Brak opisu"; } JsonViewData viewData = Validate <JsonViewData>( new Validation(() => string.IsNullOrEmpty(model.EventLink.NullSafe()), "Link wydarzenia nie może być pusty."), new Validation(() => string.IsNullOrEmpty(model.EventName.NullSafe()), "Tytuł wydarzenia nie może być pusty."), new Validation(() => !model.EventUserEmail.NullSafe().IsEmail(), "Niepoprawny adres e-mail."), new Validation(() => CurrentUser.IsAdministrator() == false, "Nie możesz edytować tego wydarzenia."), new Validation(() => model.Id.NullSafe().ToGuid().IsEmpty(), "Nieprawidłowy identyfikator wydarzenia."), new Validation(() => !model.EventEndDate.IsLaterThan(model.EventDate), "Nieprawidłowa data zakończenia wydarzenia.") ); if (viewData == null) { try { using (IUnitOfWork unitOfWork = UnitOfWork.Begin()) { ICommingEvent commingEvent = _commingEventRepository.FindById(model.Id.ToGuid()); var eventApproveStatus = CurrentUser.IsAdministrator() && model.IsApproved; if (commingEvent == null) { viewData = new JsonViewData { errorMessage = "Podane wydarzenie nie istnieje." }; } else { if (model.IsApproved) { if (string.IsNullOrEmpty(commingEvent.GoogleEventId)) { var upcomingEvent = new CommingEvent(commingEvent.EventName, commingEvent.EventLink, commingEvent.GoogleEventId, commingEvent.EventDate, commingEvent.EventEndDate.Value, commingEvent.EventCity, commingEvent.EventPlace, commingEvent.EventLead, model.IsOnline); model.GoogleEventId = _googleService.EventApproved(upcomingEvent); } else { var upcomingEvent = new CommingEvent(model.EventName, model.EventLink, commingEvent.GoogleEventId, model.EventDate, model.EventEndDate, model.EventCity, model.EventPlace, model.EventLead, model.IsOnline); model.GoogleEventId = _googleService.EditEvent(upcomingEvent); } } else if (!string.IsNullOrEmpty(commingEvent.GoogleEventId)) { _googleService.DeleteEvent(commingEvent.GoogleEventId); model.GoogleEventId = null; } _commingEventRepository.EditEvent( commingEvent, model.EventUserEmail.NullSafe(), model.EventLink.NullSafe(), model.GoogleEventId, model.EventName.NullSafe(), model.EventDate, model.EventEndDate, model.EventCity, model.EventPlace, model.EventLead, eventApproveStatus, model.IsOnline ); unitOfWork.Commit(); viewData = new JsonViewData { isSuccessful = true }; } } } catch (Exception e) { Log.Exception(e); viewData = new JsonViewData { errorMessage = FormatStrings.UnknownError.FormatWith("edycji wydarzenia.") }; } } return(Json(viewData)); }