public ActionResult Edit(PersonalDayoffModel dayoffModel) { var userId = User.Identity.GetUserId(); if (dayoffModel.UserId == User.Identity.GetUserId() || User.IsInRole("Admin")) { var context = new VITVSecondContext(); if (ModelState.IsValid) { PersonalDayoff dayoff = context.PersonalDayoffs.Find(dayoffModel.Id); if (dayoffModel.TimeOption == "all") { dayoff.AllDay = true; dayoff.Title = dayoffModel.Title; dayoff.Start = dayoffModel.Date.AddHours(9); dayoff.End = dayoffModel.Date.AddHours(18); dayoff.EmployeeId = dayoffModel.UserId; } else if (dayoffModel.TimeOption == "morning") { dayoff.AllDay = false; dayoff.Title = dayoffModel.Title; dayoff.Start = dayoffModel.Date.AddHours(9); dayoff.End = dayoffModel.Date.AddHours(12); dayoff.EmployeeId = dayoffModel.UserId; } else if (dayoffModel.TimeOption == "afternoon") { dayoff.AllDay = false; dayoff.Title = dayoffModel.Title; dayoff.Start = dayoffModel.Date.AddHours(14); dayoff.End = dayoffModel.Date.AddHours(18); dayoff.EmployeeId = dayoffModel.UserId; } else if (dayoffModel.TimeOption == "custom" && dayoffModel.StartTime.HasValue && dayoffModel.EndTime.HasValue)//custom { dayoff.AllDay = false; dayoff.Title = dayoffModel.Title; dayoff.Start = dayoffModel.Date.AddHours(dayoffModel.StartTime.Value.Hour).AddMinutes(dayoffModel.StartTime.Value.Minute); dayoff.End = dayoffModel.Date.AddHours(dayoffModel.EndTime.Value.Hour).AddMinutes(dayoffModel.EndTime.Value.Minute); dayoff.EmployeeId = dayoffModel.UserId; } else { return(Json(new { success = false, error = "Có lỗi..." })); } context.SaveChanges(); //Utilities.SendDayoffPush(dayoff); //Utilities.SendDayoffPushAndroid(dayoff); return(Json(new { success = true })); } return(Json(new { success = false, error = "Chưa nhập đủ dữ liệu" })); } else { return(Json(new { success = false, error = "Không có quyền!!!" })); } }
// GET: PersonalDayoff/Create public ActionResult Edit(DateTime date, string userid, int dayoffid) { if (userid == User.Identity.GetUserId() || User.IsInRole("Admin")) { var context = new VITVSecondContext(); PersonalDayoff dayoff = context.PersonalDayoffs.FirstOrDefault(d => d.Id == dayoffid); var model = new PersonalDayoffModel() { Date = date, UserId = userid }; if (dayoff != null) { model.StartTime = dayoff.Start; model.EndTime = dayoff.End; model.Title = dayoff.Title; model.Id = dayoff.Id; if (dayoff.AllDay) { model.TimeOption = "all"; } else { if (dayoff.Start.Date.Hour >= 9 && dayoff.Start.Date.Hour <= 12) { model.TimeOption = "morning"; } else if (dayoff.Start.Date.Hour >= 14 && dayoff.Start.Date.Hour <= 18) { model.TimeOption = "afternoon"; } else { model.TimeOption = "custom"; } } } ViewBag.lstTimeOption = lstTimeOption; return(PartialView(model)); } else { return(Content("Bạn không có quyền!!!")); } }
public ActionResult Create(DateTime date, string userid) { if (userid == User.Identity.GetUserId() || User.IsInRole("Admin")) { //var date = DateTime.Parse(date,) var model = new PersonalDayoffModel() { Date = date, UserId = userid }; ViewBag.lstTimeOption = lstTimeOption; return(PartialView(model)); } else { return(Content("Bạn không có quyền!!!")); } }