public ActionResult AssignStaff(JobDateUser jobDateUser) { if (ModelState.IsValid) { try { var date = db.JobDates.FirstOrDefault(x => x.id == jobDateUser.jobdateid)?.jobdate1.Date; if (db.JobDateUsers.ToList().Any(x => x.JobDate.jobdate1.Date == date && x.userstudioid == jobDateUser.userstudioid)) { return(RedirectToAction("Error500", "Home", new { errormsg = "Staff is busy on that date!" })); } db.JobDateUsers.Add(jobDateUser); db.SaveChanges(); return(RedirectToAction("detail/" + db.JobDates.FirstOrDefault(x => x.id == jobDateUser.jobdateid).jobid)); } catch (Exception e) { return(RedirectToAction("Error500", "Home", new { errormsg = e.Message })); } } else { return(RedirectToAction("Error500", "Home", new { errormsg = "There is an error processing your input/request!" })); } }
public ActionResult AssignStaff(int id, int jobid) { try { var jdu = new JobDateUser(); int stuid = ViewBag.StudioID; jdu.userstudioid = db.UserStudios.FirstOrDefault(x => x.userid == id && x.studioid == stuid).id; ViewBag.dropdown = db.JobDates.Where(x => x.jobid == jobid).ToList().Select(x => new SelectListItem { Text = x.jobdate1.ToString("dd/MM/yyyy hh:mm tt"), Value = x.id.ToString() }); return(View(jdu)); } catch (Exception e) { return(RedirectToAction("Error500", "Home", new { errormsg = e.Message })); } }