public ICommingEvent CreateCommingEvent(string eventUserEmail, string eventLink, string eventName, string googleEventId, DateTime eventTime, DateTime eventEndTime, string eventCity, string eventPlace, string eventLead, bool isApproved, bool isOnline) { Check.Argument.IsNotEmpty(eventLink, "EventLink"); Check.Argument.IsNotEmpty(eventName, "EventName"); DateTime now = SystemTime.Now(); var commingEvent = new CommingEvent { Id = Guid.NewGuid(), EventLink = eventLink, EventName = eventName, GoogleEventId = googleEventId, EventDate = eventTime, EventEndDate = eventEndTime, EventCity = eventCity, EventPlace = eventPlace, EventLead = eventLead, CreatedAt = now, Email = eventUserEmail, IsApproved = isApproved, IsOnline = isOnline }; return(commingEvent); }
public string EditEvent(CommingEvent commingEvent) { if (!string.IsNullOrEmpty(commingEvent.GoogleEventId)) { var request1 = service.Events.Get(calendarId, commingEvent.GoogleEventId); var eventForEdit = request1.Execute(); eventForEdit.Summary = "[" + (commingEvent.IsOnline ? "ONLINE" : commingEvent.EventCity) + "] " + commingEvent.EventName; eventForEdit.Location = commingEvent.IsOnline ? commingEvent.EventLink : commingEvent.EventCity + ", " + commingEvent.EventPlace; eventForEdit.Description = commingEvent.EventLead; eventForEdit.Start = new EventDateTime() { DateTime = TimeZoneInfo.ConvertTime(commingEvent.EventDate, timeZoneInfo) }; eventForEdit.End = new EventDateTime() { DateTime = TimeZoneInfo.ConvertTime(commingEvent.EventEndDate, timeZoneInfo) }; var update = service.Events.Update(eventForEdit, calendarId, commingEvent.GoogleEventId); var updatedEvent = update.Execute(); return(updatedEvent.Id); } else { throw new ArgumentException("Event has to have Google ID."); } }
public string EventApproved(CommingEvent commingEvent) { var request = service.Events.Insert( new Event() { Summary = "[" + (commingEvent.IsOnline ? "ONLINE" : commingEvent.EventCity) + "] " + commingEvent.EventName, Location = commingEvent.IsOnline ? commingEvent.EventLink : commingEvent.EventCity + ", " + commingEvent.EventPlace, Description = commingEvent.EventLead, Start = new EventDateTime() { DateTime = TimeZoneInfo.ConvertTime(commingEvent.EventDate, timeZoneInfo) }, End = new EventDateTime() { DateTime = TimeZoneInfo.ConvertTime(commingEvent.EventEndDate, timeZoneInfo) }, }, calendarId); var createdEvent = request.Execute(); return(createdEvent.Id); }
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)); }