public ActionResult AddEvent(EventViewData model) { JsonViewData viewData = Validate <JsonViewData>( new Validation(() => string.IsNullOrWhiteSpace(model.EventLink.NullSafe()), "Link do wydarzenia nie może być pusty."), new Validation(() => string.IsNullOrWhiteSpace(model.EventName.NullSafe()), "Tytuł wydarzenia nie może być pusty."), new Validation(() => model.EventUserEmail.NullSafe().IsEmail() == false, "Nieprawidłowy adres e-mail."), new Validation(() => model.Id.ToGuid() != Guid.Empty, "Id wydarzenia nie może być podane"), new Validation(() => !model.EventEndDate.IsLaterThan(model.EventDate), "Nieprawidłowa data zakończenia wydarzenia.") ); if (viewData == null) { try { var eventApproveStatus = CurrentUser != null && CurrentUser.IsAdministrator() && model.IsApproved; if (eventApproveStatus) { model.GoogleEventId = _googleService.EventApproved(new CommingEvent(model.EventName, model.EventLink, model.GoogleEventId, model.EventDate, model.EventEndDate, model.EventCity, model.EventPlace, model.EventLead, model.IsOnline)); } using (IUnitOfWork unitOfWork = UnitOfWork.Begin()) { var commingEvent = _factory.CreateCommingEvent( model.EventUserEmail, model.EventLink, model.EventName, model.GoogleEventId, model.EventDate, model.EventEndDate, model.EventCity, model.EventPlace, model.EventLead, eventApproveStatus, model.IsOnline ); _commingEventRepository.Add(commingEvent); unitOfWork.Commit(); _aggregator.GetEvent <UpcommingEventEvent>() .Publish(new UpcommingEventEventArgs(model.EventName, model.EventLink)); Log.Info("Event registered: {0}", commingEvent.EventName); viewData = new JsonViewData { isSuccessful = true }; } } catch (Exception e) { Log.Exception(e); viewData = new JsonViewData { errorMessage = FormatStrings.UnknownError.FormatWith("dodawania wydarzenia") }; } } return(Json(viewData)); }
public ActionResult DeleteEvent(string id) { id = id.NullSafe(); JsonViewData viewData = Validate <JsonViewData>( new Validation(() => !CurrentUser.CanModerate(), "Nie masz praw do wołania tej metody."), new Validation(() => string.IsNullOrEmpty(id), "Identyfikator reklamy nie może być pusty."), new Validation(() => id.ToGuid().IsEmpty(), "Niepoprawny identyfikator wydarzenia."), new Validation(() => !IsCurrentUserAuthenticated, "Nie jesteś zalogowany.") ); if (viewData == null) { try { using (IUnitOfWork unitOfWork = UnitOfWork.Begin()) { ICommingEvent commingEvent = _commingEventRepository.FindById(id.ToGuid()); if (commingEvent == null) { viewData = new JsonViewData { errorMessage = "Wydarzenie nie istnieje." }; } else { _commingEventRepository.Remove(commingEvent); unitOfWork.Commit(); if (!string.IsNullOrEmpty(commingEvent.GoogleEventId)) { _googleService.DeleteEvent(commingEvent.GoogleEventId); } viewData = new JsonViewData { isSuccessful = true }; } } } catch (Exception e) { Log.Exception(e); viewData = new JsonViewData { errorMessage = FormatStrings.UnknownError.FormatWith("usuwania wydarzenia") }; } } return(Json(viewData)); }
public void Execute() { if (!_users.IsNullOrEmpty()) { using (IUnitOfWork unitOfWork = UnitOfWork.Begin()) { _users.ForEach(CreateUserIfNotExists); unitOfWork.Commit(); } } }
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)); }
public ActionResult EditAd(AdvertiseViewData model) { JsonViewData viewData = Validate <JsonViewData>( new Validation(() => CurrentUser.CanModerate() == false, "Nie masz praw do wykonowania tej operacji."), new Validation(() => string.IsNullOrEmpty(model.RecommendationLink.NullSafe()), "Link rekomendacji nie może być pusty."), new Validation(() => string.IsNullOrEmpty(model.RecommendationTitle.NullSafe()), "Tytuł rekomendacji nie może być pusty."), new Validation(() => string.IsNullOrEmpty(model.ImageLink.NullSafe()), "Link obrazka nie może być pusty."), new Validation(() => string.IsNullOrEmpty(model.ImageTitle.NullSafe()), "Tytuł obrazka nie może być pusty."), new Validation(() => model.StartTime >= model.EndTime, "Data zakończenia reklamy musi być większa od daty początkowej"), new Validation(() => string.IsNullOrEmpty(model.Email), "Adres e-mail nie może być pusty."), new Validation(() => !model.Email.NullSafe().IsEmail(), "Niepoprawny adres e-mail.") ); var bannerType = string.IsNullOrWhiteSpace(model.IsBanner) == false; if (viewData == null) { try { if (bannerType) { var request = WebRequest.Create(Server.MapPath(string.Format("/Assets/Images/{0}", model.ImageLink))); var response = request.GetResponse(); var image = Image.FromStream(response.GetResponseStream()); if (image.Width != 960) { viewData = new JsonViewData { errorMessage = string.Format("Oczekiwana szerokość banera to 960px, twoja to: {0}", image.Width) }; return(Json(viewData)); } } using (IUnitOfWork unitOfWork = UnitOfWork.Begin()) { if (model.Id == null || model.Id.IsEmpty()) { IRecommendation recommendation = _factory.CreateRecommendation( model.RecommendationLink.Trim(), model.RecommendationTitle.Trim(), model.ImageLink.Trim(), model.ImageTitle.Trim(), model.StartTime, model.EndTime, model.Email, model.Position, model.NotificationIsSent, bannerType); _recommendationRepository.Add(recommendation); unitOfWork.Commit(); Log.Info("Recommendation registered: {0}", recommendation.RecommendationTitle); viewData = new JsonViewData { isSuccessful = true }; } else { IRecommendation recommendation = _recommendationRepository.FindById(model.Id.ToGuid()); if (recommendation == null) { viewData = new JsonViewData { errorMessage = "Podana reklama nie istnieje." }; } else { _recommendationRepository.EditAd( recommendation, model.RecommendationLink.NullSafe(), model.RecommendationTitle.NullSafe(), model.ImageLink.NullSafe(), model.ImageTitle.NullSafe(), model.StartTime, model.EndTime, model.Email, model.Position, model.NotificationIsSent, bannerType); unitOfWork.Commit(); viewData = new JsonViewData { isSuccessful = true }; } } } } catch (ArgumentException argument) { viewData = new JsonViewData { errorMessage = argument.Message }; } catch (WebException e) { viewData = new JsonViewData { errorMessage = "Podany link do zdjęcia jest nieprawidłowy" }; } catch (Exception e) { Log.Exception(e); viewData = new JsonViewData { errorMessage = FormatStrings.UnknownError.FormatWith("") }; } } return(Json(viewData)); }