Пример #1
0
        public ActionResult InsertEvent(EventInsertVM model)
        {
            string error = ValidatePhoto(model.Photo);

            if (error != null)
            {
                ModelState.AddModelError("Photo", error);
            }
            if (ModelState.IsValidField("startTime"))
            {
                if (model.startTime > model.endTime)
                {
                    ModelState.AddModelError("startTime", "start time cannot exceed or equal end time!");
                }
            }
            if (ModelState.IsValid)
            {
                var e = new Event
                {
                    name         = model.name,
                    des          = model.des,
                    price        = model.price,
                    participants = model.participants,
                    availability = model.participants,
                    date         = model.date,
                    startTime    = model.startTime,
                    endTime      = model.endTime,
                    approvalStat = true,
                    status       = true,
                    venueId      = model.venueId,
                    photoURL     = SavePhoto(model.Photo),
                    OrgId        = model.OrgId
                };
                try
                {
                    db.Events.Add(e);
                    db.SaveChanges();
                    TempData["info"] = "Event added successfully";
                    return(RedirectToAction("DisplayEvent", "Admin"));
                }
                catch (Exception ex)
                {
                    TempData["Info"] = ex;
                }
            }
            else
            {
                TempData["Error"] = "Error";
            }
            ViewBag.OrganizerList = new SelectList(db.Organisers.Where(o => o.status == true), "Id", "represent");
            ViewBag.VenueList     = new SelectList(db.Venues, "Id", "name");
            return(View(model));
        }
Пример #2
0
        public ActionResult ProposeEvent(EventInsertVM model)
        {
            string error = ValidatePhoto(model.Photo);

            if (error != null)
            {
                ModelState.AddModelError("Photo", error);
            }
            if (ModelState.IsValid)
            {
                int duration = ((int)model.endTime.TotalMinutes - (int)model.startTime.TotalMinutes) / 60;
                var e        = new Event
                {
                    name         = model.name,
                    des          = model.des,
                    price        = model.price,
                    availability = model.availability,
                    participants = model.participants,
                    startDate    = model.startDate,
                    endDate      = model.endDate,
                    startTime    = model.startTime,
                    endTime      = model.endTime,
                    duration     = duration.ToString(),
                    approvalStat = null,
                    status       = true,
                    venueId      = null,
                    photoURL     = SavePhoto(model.Photo),
                    OrgId        = model.OrgId
                };
                try {
                    db.Events.Add(e);
                    db.SaveChanges();
                }catch (Exception ex)
                {
                    TempData["Info"] = ex;
                }
                TempData["info"] = "Event proposed successfully";
            }
            else
            {
                TempData["Error"] = "Error";
            }
            ViewBag.OrganizerList = new SelectList(db.Organisers, "Id", "represent");
            return(View(model));
        }