Exemplo n.º 1
0
 private void setSideOfText(string sideOfText, EventViewModel eventToShow)
 {
     eventToShow.SideOfTextOptions = new Dictionary<string, bool>();
     eventToShow.SideOfTextOptions.Add("Right", String.Equals("Right", sideOfText, StringComparison.OrdinalIgnoreCase));
     eventToShow.SideOfTextOptions.Add("Left", String.Equals("Left", sideOfText, StringComparison.OrdinalIgnoreCase));
     eventToShow.SideOfTextOptions.Add("Top", String.Equals("Top", sideOfText, StringComparison.OrdinalIgnoreCase));
     eventToShow.SideOfTextOptions.Add("Bottom", String.Equals("Bottom", sideOfText, StringComparison.OrdinalIgnoreCase));
 }
Exemplo n.º 2
0
 private void setSideOfTextDefault(ref EventViewModel model)
 {
     model.SideOfTextOptions = new Dictionary<string, bool>();
     model.SideOfTextOptions.Add("Right", String.Equals("Right", model.SideOfText, StringComparison.OrdinalIgnoreCase));
     model.SideOfTextOptions.Add("Left", String.Equals("Left", model.SideOfText, StringComparison.OrdinalIgnoreCase));
     model.SideOfTextOptions.Add("Top", String.Equals("Top", model.SideOfText, StringComparison.OrdinalIgnoreCase));
     model.SideOfTextOptions.Add("Bottom", String.Equals("Bottom", model.SideOfText, StringComparison.OrdinalIgnoreCase));
 }
Exemplo n.º 3
0
 private void setGenderOptions(EventViewModel model)
 {
     setGenderOptions(model.GenderParticipant, model);
 }
Exemplo n.º 4
0
 private void setPrivacyTypeOptions(e_PrivacyType PrivacyType, EventViewModel model)
 {
     model.PrivacyTypeOptions = new Dictionary<e_PrivacyType, bool>();
     model.PrivacyTypeOptions.Add(e_PrivacyType.Public, PrivacyType == e_PrivacyType.Public);
     model.PrivacyTypeOptions.Add(e_PrivacyType.RequiresApproval, PrivacyType == e_PrivacyType.RequiresApproval);
 }
Exemplo n.º 5
0
 public string CheckIfUserCanEditEvent(EventViewModel model)
 {
     var user = UserManager.FindById(User.Identity.GetUserId());
     if (user.Id == model.CreatorUser.Id)
     {
         return string.Format("<a href=\"/Event/Edit?id=" + model.Id + "\">Edit event<a/>");
     }
     else
     {
         return "";
     }
 }
Exemplo n.º 6
0
 private void setGenderOptions(string GenderParticipant, EventViewModel model)
 {
     model.GenderParticipantOptions = new Dictionary<string, bool>();
     model.GenderParticipantOptions.Add("Both", String.Equals("Both", GenderParticipant, StringComparison.OrdinalIgnoreCase));
     model.GenderParticipantOptions.Add("Male", String.Equals("Male", GenderParticipant, StringComparison.OrdinalIgnoreCase));
     model.GenderParticipantOptions.Add("Female", String.Equals("Female", GenderParticipant, StringComparison.OrdinalIgnoreCase));
 }
Exemplo n.º 7
0
        public ActionResult Edit(EventViewModel model, HttpPostedFileBase ImageUrl, string selectedInterests)
        {
            List<ModelError> errors = ModelState.Values.SelectMany(v => v.Errors).ToList();
            Event @event = db.Events.Find(model.Id);
            if (selectedInterests == "")
            {
                ModelState.AddModelError("Interests select", "You need to select interests");
            }
            if (model.TimeSet == true && model.DateTimeOfTheEvent < DateTime.Now)
            {
                ModelState.AddModelError("Event Date time", "Event date cannot occur in the past.");
            }
            if (model.TimeSet == false && model.DateTimeOfTheEvent.Date < DateTime.Today)
            {
                ModelState.AddModelError("Event Date", "Event date cannot occur in the past.");
            }
            if (ModelState.IsValid)
            {
                var user = UserManager.FindById(User.Identity.GetUserId());
                @event.CreatorUser = user;
                @event.Title = model.Title;
                @event.SideOfText = model.SideOfText;
                @event.Place = model.Place;
                @event.isImageFromStock = model.isImageFromStock;
                if (model.ImageUrl != null)
                {
                    saveImage(ref @event, ImageUrl);
                }
                else
                {
                    if (@event.isImageFromStock)
                    {
                        @event.ImageUrl = model.ImageFromStock;
                    }
                }
                @event.AgeOfParticipantsMax = model.AgeOfParticipantsMax;
                @event.AgeOfParticipantsMin = model.AgeOfParticipantsMin;
                @event.BackroundColor = model.BackroundColor.Replace("rgb(", "");
                @event.BackroundColor = @event.BackroundColor.Replace(")", "");
                @event.BackroundColorOpacity = model.BackroundColorOpacity;
                @event.DateTimeOfTheEvent = model.DateTimeOfTheEvent;
                @event.Description = model.Description;
                @event.GenderParticipant = model.GenderParticipant;
                @event.PlaceLatitude = model.PlaceLatitude;
                @event.PlaceLongitude = model.PlaceLongitude;
                @event.Interests.Clear();
                @event.Interests = InterestsFromObjects.GetSelectedInterests(selectedInterests, db);
                @event.AgeOfParticipantsSet = true;
                @event.PrivacyType = model.PrivacyType;
                if (model.AgeOfParticipantsMax == null && model.AgeOfParticipantsMin == null)
                {
                    @event.AgeOfParticipantsSet = false;
                }
                @event.TimeSet = model.TimeSet;
                setSideOfText(@event.SideOfText, model);
                setGenderOptions(@event.GenderParticipant, model);
                setPrivacyTypeOptions((e_PrivacyType)@event.PrivacyType, model);
                db.Entry(@event).State = EntityState.Modified;
                try
                {
                    db.SaveChanges();
                    return RedirectToAction("Details", new { id = @event.Id });
                }
                catch (DbEntityValidationException ex)
                {
                    foreach (DbEntityValidationResult error in ex.EntityValidationErrors)
                    {
                        ModelState.AddModelError("", error.ValidationErrors.ToString());
                    }
                }

            }
            else
            {
                List<ApplicationUser> attendingUsers = db.EventVsAttendingUsers.Where
                 (e => e.EventId == @event.Id).Select(e => e.AttendingUser).Where(e => e.AccountIsActive).ToList();
                model.UsersAttending = attendingUsers;
                setSideOfText(model.SideOfText, model);
                setGenderOptions(model.GenderParticipant, model);
                setPrivacyTypeOptions((e_PrivacyType)model.PrivacyType, model);
                if (selectedInterests != "")
                {
                    List<Interest> interests = GetSelectedInterests(selectedInterests);
                    model.AllInterests = InterestsFromObjects.LoadInterestViewModelsFromInterests(interests, db);
                }
                else
                {
                    model.AllInterests = InterestsFromObjects.InitAllInterests(db);
                }
                model.InterestsToDisplay = selectedInterests;
                model.CreatorUser = @event.CreatorUser;
                if (model.isImageFromStock)
                {
                    model.ImageUrl = model.ImageFromStock;
                }
                else
                {
                    model.ImageUrl = @event.ImageUrl;
                }
                model.BackroundColor = model.BackroundColor.Replace("rgb(", "");
                model.BackroundColor = model.BackroundColor.Replace(")", "");
            }

            return View(model);
        }
Exemplo n.º 8
0
        public ActionResult Edit(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            Event @event = db.Events.Find(id);
            var user = UserManager.FindById(User.Identity.GetUserId());
            if (user.Id != @event.CreatorUser.Id)
            {
                return RedirectToAction("Index", "Home");
            }
            if (@event == null)
            {
                return HttpNotFound();
            }
            string hour = @event.DateTimeOfTheEvent.ToString("HH");
            string minute = @event.DateTimeOfTheEvent.ToString("mm");
            string dateString = @event.DateTimeOfTheEvent.Date.ToString();
            EventViewModel model = new EventViewModel()
            {
                Id = @event.Id,
                AgeOfParticipantsMax = @event.AgeOfParticipantsMax,
                AgeOfParticipantsMin = @event.AgeOfParticipantsMin,
                AgeOfParticipantsSet = @event.AgeOfParticipantsSet,
                BackroundColor = @event.BackroundColor,
                BackroundColorOpacity = @event.BackroundColorOpacity,
                DateOfTheEvent = @event.DateTimeOfTheEvent.ToShortDateString(),
                DateOfTheEventNoYear = string.Format("{0}.{1}",
                @event.DateTimeOfTheEvent.Day.ToString(), @event.DateTimeOfTheEvent.Month.ToString()),
                DateTimeOfTheEvent = @event.DateTimeOfTheEvent,
                HourTimeOfTheEvent = hour,
                MinuteTimeOfTheEvent = minute,
                CreatorUser = @event.CreatorUser,
                DateTimeCreated = @event.DateTimeCreated,
                Description = @event.Description,
                GenderParticipant = @event.GenderParticipant,
                ImageUrl = @event.ImageUrl,
                Place = @event.Place,
                SideOfText = @event.Place,
                Title = @event.Title,
                PlaceLongitude = @event.PlaceLongitude,
                PlaceLatitude = @event.PlaceLatitude,
                TimeSet = @event.TimeSet,
                AllInterests = InterestsFromObjects.LoadInterestViewModelsFromInterests(@event.Interests, db),
                InterestsToDisplay = InterestsFromObjects.GetInterestsForDisplay(@event.Interests.ToList()),
                PrivacyType = @event.PrivacyType
            };
            if (@event.isImageFromStock)
            {
                model.ImageFromStock = @event.ImageUrl;
                model.isImageFromStock = true;
            }
            List<ApplicationUser> attendingUsers = db.EventVsAttendingUsers.Where
                 (e => e.EventId == @event.Id).Select(e => e.AttendingUser).Where(e => e.AccountIsActive).ToList();
            model.UsersAttending = attendingUsers;

            setSideOfText(@event.SideOfText, model);
            setGenderOptions(@event.GenderParticipant, model);
            setPrivacyTypeOptions((e_PrivacyType)@event.PrivacyType, model);
            return View(model);
        }
Exemplo n.º 9
0
        public ActionResult Details(int? id)
        {
            ViewData["Id"] = id;
            ViewData["UserAlreadyAttending"] = false;
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            Event @event = db.Events.Find(id);
            if (@event == null)
            {
                return HttpNotFound();
            }
            if (@event.EventStatus == e_EventStatus.Deleted)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }

            EventViewModel eventToShow = new EventViewModel()
            {
                CreatorUser = @event.CreatorUser,
                AgeOfParticipantsMax = @event.AgeOfParticipantsMax,
                AgeOfParticipantsMin = @event.AgeOfParticipantsMin,
                ImageUrl = @event.ImageUrl,
                GenderParticipant = @event.GenderParticipant,
                BackroundColor = @event.BackroundColor,
                BackroundColorOpacity = @event.BackroundColorOpacity,
                DateOfTheEventNoYear = setDisplayDateFormat(@event.DateTimeOfTheEvent),
                DateTimeOfTheEvent = @event.DateTimeOfTheEvent,
                Place = @event.Place,
                Title = @event.Title,
                Description = @event.Description,
                Id = @event.Id,
                TimeSet = @event.TimeSet,
                AgeOfParticipantsSet = @event.AgeOfParticipantsSet,
                InterestsToDisplay = InterestsFromObjects.GetInterestsForDisplay(@event.Interests.ToList())
            };
            List<ApplicationUser> attendingUsers = db.EventVsAttendingUsers.Where
                (e => e.EventId == eventToShow.Id).Select(e => e.AttendingUser).Where(e => e.AccountIsActive).ToList();
            eventToShow.UsersAttending = attendingUsers;

            List<ApplicationUser> usersWaitingApproval = db.EventVsWaitingApprovalUsers.Where
                (e => e.EventId == eventToShow.Id).Select(e => e.WaitingApprovalUser).Where(e => e.AccountIsActive).ToList();
            eventToShow.UsersWaitingApproval = usersWaitingApproval;

            if (User.Identity.IsAuthenticated)
            {
                var user = UserManager.FindById(User.Identity.GetUserId());
                eventToShow.Comments = SetDeleteButtonsForComments(@event.Comments.ToList(), (ApplicationUser)user, eventToShow.CreatorUser);
                if (user.Id == eventToShow.CreatorUser.Id)
                {
                    eventToShow.CurrentUserIsCreator = true;
                    ViewData["UserAlreadyAttending"] = false;
                }
                else if (User.IsInRole("Admin"))
                { eventToShow.CurrentUserIsCreator = true; }
                else
                {
                    eventToShow.CurrentUserIsCreator = false;
                    if (eventToShow.UsersAttending.SingleOrDefault(x => x.Id == user.Id) != null)
                    {
                        ViewData["UserAlreadyAttending"] = true;
                    }
                    if (eventToShow.UsersWaitingApproval.SingleOrDefault(x => x.Id == user.Id) != null)
                    {
                        ViewData["UserAlreadyAttending"] = true;
                    }
                }
            }
            else
            {
                eventToShow.CurrentUserIsCreator = false;
                eventToShow.Comments = SetDeleteButtonsForComments(@event.Comments.ToList(), null, eventToShow.CreatorUser);
                ViewData["UserAlreadyAttending"] = false;
            }
            Statistics Statistics = LoadStatistics(attendingUsers);
            var json = new JavaScriptSerializer().Serialize(Statistics);
            ViewData["Statistics"] = json;
            return View(eventToShow);
        }
Exemplo n.º 10
0
        public ActionResult Create(EventViewModel model, HttpPostedFileBase ImageUrl, string selectedInterests)
        {
            List<ModelError> errors = ModelState.Values.SelectMany(v => v.Errors).ToList();
            if (model.isImageFromStock)
            {
                if (String.IsNullOrEmpty(model.ImageFromStock))
                {
                    ModelState.AddModelError("Image Upload", "Image Upload is required");
                }
            }
            else
            {
                if (ImageUrl == null)
                {
                    ModelState.AddModelError("Image Upload", "Image Upload is required");
                }
                else
                {
                    if (!ImageSaver.IsImage(ImageUrl))
                    {
                        ModelState.AddModelError("Image Upload", "You can upload only images");
                    }
                }
            }
            if (selectedInterests == "")
            {
                ModelState.AddModelError("Interests select", "You need to select interests");
            }
            if (model.TimeSet == true && model.DateTimeOfTheEvent < DateTime.Now)
            {
                ModelState.AddModelError("Event Date time", "Event date cannot occur in the past.");
            }
            if (model.TimeSet == false && model.DateTimeOfTheEvent.Date < DateTime.Today)
            {
                ModelState.AddModelError("Event Date", "Event date cannot occur in the past.");
            }

            if (ModelState.IsValid)
            {
                var user = UserManager.FindById(User.Identity.GetUserId());

                Event eventToCreate = new Event()
                {
                    CreatorUser = user,
                    AgeOfParticipantsMax = model.AgeOfParticipantsMax,
                    AgeOfParticipantsMin = model.AgeOfParticipantsMin,
                    AgeOfParticipantsSet = true,
                    GenderParticipant = model.GenderParticipant,
                    BackroundColor = model.BackroundColor,
                    BackroundColorOpacity = model.BackroundColorOpacity,
                    DateTimeCreated = DateTime.Now,
                    Place = model.Place,
                    Title = model.Title,
                    Description = model.Description,
                    SideOfText = model.SideOfText,
                    DateTimeOfTheEvent = model.DateTimeOfTheEvent,
                    TimeSet = model.TimeSet,
                    PlaceLatitude = model.PlaceLatitude,
                    PlaceLongitude = model.PlaceLongitude,
                    Interests = GetSelectedInterests(selectedInterests),
                    EventStatus = e_EventStatus.Active,
                    isImageFromStock = model.isImageFromStock,
                    PrivacyType = model.PrivacyType
                };
                if (model.AgeOfParticipantsMax == null && model.AgeOfParticipantsMin == null)
                {
                    eventToCreate.AgeOfParticipantsSet = false;
                }
                if (model.isImageFromStock)
                {
                    eventToCreate.ImageUrl = model.ImageFromStock;
                }
                else
                {
                    eventToCreate.ImageUrl = model.ImageUrl;
                }

                db.Events.Add(eventToCreate);
                try
                {
                    db.SaveChanges();
                    if (!model.isImageFromStock)
                    {
                        saveImage(ref eventToCreate, ImageUrl);
                    }
                    EventVsAttendingUser eventVsAttendingUser = new EventVsAttendingUser { EventId = eventToCreate.Id, UserId = user.Id, Event = eventToCreate, AttendingUser = user };
                    db.EventVsAttendingUsers.Add(eventVsAttendingUser);

                    db.SaveChanges();
                    return RedirectToAction("Details", new { id = eventToCreate.Id });
                }
                catch (DbEntityValidationException ex)
                {
                    foreach (DbEntityValidationResult error in ex.EntityValidationErrors)
                    {
                        ModelState.AddModelError("", error.ValidationErrors.ToString());
                    }
                }
            }
            else
            {
                if (selectedInterests != "")
                {
                    List<Interest> interests = GetSelectedInterests(selectedInterests);
                    model.AllInterests = InterestsFromObjects.LoadInterestViewModelsFromInterests(interests, db);
                }
                else
                {
                    model.AllInterests = InterestsFromObjects.InitAllInterests(db);
                }
                if (model.isImageFromStock)
                {
                    ViewBag.DraftImage = model.ImageFromStock;
                }
                else
                {
                    ViewBag.DraftImage = defaultDraftImage;
                }
            }
            return View(model);
        }
Exemplo n.º 11
0
 public ActionResult Create()
 {
     EventViewModel model = new EventViewModel();
     model.AllInterests = InterestsFromObjects.InitAllInterests(db);
     ViewBag.DraftImage = defaultDraftImage;
     return View(model);
 }