예제 #1
0
        public bool AcceptUser(string UserId, int? EventId)
        {
            try
            {
                if (UserId == "" || EventId == null)
                {
                    return false;
                }

                EventVsWaitingApprovalUser eventVsWaitingApprovalUser = db.EventVsWaitingApprovalUsers.SingleOrDefault(x => x.Event.Id == EventId && x.WaitingApprovalUser.Id == UserId);
                if (eventVsWaitingApprovalUser != null)
                {
                    Event @event = db.Events.SingleOrDefault(x => x.Id == EventId);
                    if (@event == null)
                    {
                        return false;
                    }
                    ApplicationUser user = db.Users.SingleOrDefault(x => x.Id == UserId);
                    if (user == null)
                    {
                        return false;
                    }

                    EventVsAttendingUser eventVsAttendingUser = new EventVsAttendingUser { EventId = @event.Id, UserId = user.Id, Event = @event, AttendingUser = user };
                    db.EventVsAttendingUsers.Add(eventVsAttendingUser);

                    db.EventVsWaitingApprovalUsers.Remove(eventVsWaitingApprovalUser);
                    db.SaveChanges();

                }

                return true;
            }
            catch
            {
                return false;
            }
        }
예제 #2
0
 public bool JoinEvent(int? id)
 {
     try
     {
         if (id == null)
         {
             return false;
         }
         ApplicationUser user = UserManager.FindById(User.Identity.GetUserId());
         Event @event = db.Events.Find(id);
         if (@event == null)
         {
             return false;
         }
         if (@event.PrivacyType == e_PrivacyType.Public)
         {
             EventVsAttendingUser eventVsAttendingUser = new EventVsAttendingUser { EventId = @event.Id, UserId = user.Id, Event = @event, AttendingUser = user };
             db.EventVsAttendingUsers.Add(eventVsAttendingUser);
         }
         else
         {
             EventVsWaitingApprovalUser eventVsWaitingApprovalUser = new EventVsWaitingApprovalUser { EventId = @event.Id, UserId = user.Id, Event = @event, WaitingApprovalUser = user };
             db.EventVsWaitingApprovalUsers.Add(eventVsWaitingApprovalUser);
         }
         db.SaveChanges();
         return true;
     }
     catch
     {
         return false;
     }
 }
예제 #3
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);
        }