/// <summary>
        /// This action retrieves the details of an usher assignment
        /// </summary>
        /// <param name="id">Usher appointed id</param>
        /// <returns>Details view</returns>
        // GET: UsherAppointed/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            UsherAppointed usherAppointed = db.UsherAppointeds.Find(id);

            if (usherAppointed == null)
            {
                return(HttpNotFound());
            }

            var model = new UsherAppointedViewModel
            {
                UsherAppointedId = usherAppointed.UsherAppointedId,
                DateAppointed    = usherAppointed.DateAppointed,
                Usher            = usherAppointed.Usher.FullName,
                EventProject     = usherAppointed.EventProject.Name,
                Employee         = usherAppointed.Employee.FullName,
            };

            return(View(model));
        }
        public ActionResult Edit(int id, UsherAppointedViewModel model)
        {
            if (ModelState.IsValid)
            {
                var usherAppointed = db.UsherAppointeds.Find(id);
                if (usherAppointed == null)
                {
                    return(HttpNotFound());
                }
                //UsherAppointed usherAppointed = Mapper.Map<UsherAppointedViewModel, UsherAppointed>(model);
                usherAppointed.DateAppointed        = DateTime.Now;
                usherAppointed.UsherId              = model.UsherId;
                usherAppointed.EventProjectId       = model.EventProjectId;
                usherAppointed.ProductionEmployeeId = User.Identity.GetUserId <int>();

                db.Entry(usherAppointed).State = EntityState.Modified;
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            ViewBag.UsherId = new SelectList(db.Ushers, "UsherId", "FullName");
            ViewBag.ProductionEmployeeId = new SelectList(db.Employees, "Id", "FullName");
            ViewBag.EventProjectId       = new SelectList(db.EventProjects, "EventProjectId", "Name");

            return(View(model));
        }
        /// <summary>
        /// This action retrieves the deletion page
        /// </summary>
        /// <param name="id">Usher appointed id</param>
        /// <returns>Delete view or error view</returns>
        // GET: UsherAppointed/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            UsherAppointed usherAppointed = db.UsherAppointeds.Find(id);

            if (usherAppointed == null)
            {
                return(HttpNotFound());
            }

            UsherAppointedViewModel model = new UsherAppointedViewModel
            {
                EventProjectId = usherAppointed.EventProjectId,
                DateAppointed  = usherAppointed.DateAppointed,
                Usher          = usherAppointed.Usher.FullName,
                EventProject   = usherAppointed.EventProject.Name,
                Employee       = usherAppointed.Employee.FullName,
            };

            ViewBag.UsherId = new SelectList(db.Ushers, "UsherId", "FullName");
            ViewBag.ProductionEmployeeId = new SelectList(db.Employees, "Id", "FullName");
            ViewBag.EventProjectId       = new SelectList(db.EventProjects, "EventProjectId", "Name");

            return(View(model));
        }
        public ActionResult Create(int?id)
        {
            var model = new UsherAppointedViewModel();

            model.EventProjectId = id ?? default(int);

            ViewBag.UsherId = new SelectList(db.Ushers, "UsherId", "FullName");
            ViewBag.ProductionEmployeeId = new SelectList(db.Employees, "Id", "FullName");
            ViewBag.EventProjectId       = new SelectList(db.EventProjects, "EventProjectId", "Name");

            return(View(model));
        }
        public ActionResult Create(UsherAppointedViewModel model)
        {
            if (ModelState.IsValid)
            {
                //var project = db.EventProjects.Find(model.EventProjectId);

                //if (project == null)
                //{
                //    return HttpNotFound();
                //}

                var usherAppointed = new UsherAppointed
                {
                    DateAppointed        = DateTime.Now,
                    UsherId              = model.UsherId,
                    EventProjectId       = model.EventProjectId,
                    ProductionEmployeeId = User.Identity.GetUserId <int>(),
                };

                db.UsherAppointeds.Add(usherAppointed);
                db.SaveChanges();

                ViewBag.UsherId = new SelectList(db.Ushers, "UsherId", "FullName");
                ViewBag.ProductionEmployeeId = new SelectList(db.Employees, "Id", "FullName");
                ViewBag.EventProjectId       = new SelectList(db.EventProjects, "EventProjectId", "Name");

                return(RedirectToAction("Index"));
                //return RedirectToAction("Details", new { id = usherAppointed.UsherAppointedId });
            }
            else
            {
                ViewBag.UsherId = new SelectList(db.Ushers, "UsherId", "FullName");
                ViewBag.ProductionEmployeeId = new SelectList(db.Employees, "Id", "FullName");
                ViewBag.EventProjectId       = new SelectList(db.EventProjects, "EventProjectId", "Name");
                return(View());
            }
        }