public bool CreateEvent(CreateEventModel createEventModel)
        {
            Event newEvent = new Event();
            newEvent.Title = createEventModel.Title;
            newEvent.Description = createEventModel.Description;
            newEvent.StartTime = createEventModel.StartTime;
            newEvent.EndTime = createEventModel.EndTime;
            newEvent.IsPrivate = createEventModel.IsPrivate;

            newEvent.Category = GetCategory(createEventModel.CategoryString);
            newEvent.Location = CreateLocation(createEventModel.Latitude, createEventModel.Longitude, createEventModel.LocationName, createEventModel.Address);

            newEvent.IsActive = true;
            newEvent.LastModified = DateTime.Now;
            newEvent.Created = System.DateTime.Now;
            newEvent.Rating = 0;
            newEvent.CreatedBy = db.UserProfiles.Where(up => up.UserProfileId == createEventModel.UserProfileId).FirstOrDefault();

            if (newEvent.CreatedBy != null)
            {
                db.AddToEvents(newEvent);
                db.SaveChanges();

                return true;
            }
            else
            {
                return false;
            }
        }
        public override bool Execute()
        {
            categoryModels = CategoryServices.GetInstance().GetAllCategories().ToArray();
            CreateEventModel c = new CreateEventModel();
            c.Title = "Test Event";
            c.Description = "This is a test event";
            c.StartTime = DateTime.Now;
            c.EndTime = DateTime.Now;
            c.CategoryString = categoryModels[random.Next(0, categoryModels.Length -1)].Name;
            c.IsPrivate = false;
            c.Latitude = 3.9 + (15.1*random.NextDouble()); // min : 18.812718 3.973861
            c.Longitude = 117 + (14*random.NextDouble()); // min: 117.13623 ,130.12207
            c.LocationName = "Ateneo";
            c.Address = "Katipunan Avenue";
            c.UserProfileId = random.Next(1, accountServices.GetAllUserProfiles().Count());

            return eventServices.CreateEvent(c);
        }
        public ActionResult New(CreateEventViewModel model)
        {
            UserModel um = accountServices.GetUserByUsername(User.Identity.Name);
            CreateEventModel cem = new CreateEventModel();
            cem.Address = model.Address;
            cem.CategoryString = model.CategoryString;
            cem.Description = model.Description;
            cem.EndTime = DateTime.Parse(model.EndMonth + "/" + model.EndDay + "/" + model.EndYear + " " + model.EndHour + ":" + model.EndMinute + " " + model.EndAMPM);
            cem.Latitude = model.Latitude;
            cem.Longitude = model.Longitude;
            cem.StartTime = DateTime.Parse(model.StartMonth + "/" + model.StartDay + "/" + model.StartYear + " " + model.StartHour + ":" + model.StartMinute + " " + model.StartAMPM);
            cem.Title = model.Title;
            string username = User.Identity.Name;
            cem.UserProfileId = accountServices.GetUserProfileByUsername(username).UserProfileId;
            try
            {
                eventServices.CreateEvent(cem);
            }
            catch (ConstraintException e)
            {
                ViewData["message"] = e.Message;

                if (e.Data.Contains("Entity"))
                {
                    ViewData["message"] = e.Data["Entity"] + " cannot be left blank!";
                }

                ProfileController.SetViewDataForDate(ViewData);
                ProfileController.SetViewDataForTime(ViewData);
                return View(model);
            }
            return Redirect("/");
        }