public async Task <ActionResult> EditEditWork(int?id, int workid) { if (Session["LoginUserID"] == null) { return(RedirectToAction("Login", "Account")); } if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } DailyWork dailyWork = await db.DailyWorks.FindAsync(id); if (dailyWork == null) { return(HttpNotFound()); } WorkUnit workUnit = await db.WorkUnits.FindAsync(workid); if (workUnit == null) { return(HttpNotFound()); } var dailyWorkUnitData = new DailyWorkUnitData(); dailyWorkUnitData.DailyWork = dailyWork; dailyWorkUnitData.WorkUnit = workUnit; ViewBag.WorkUnits = db.WorkUnits.Where(w => w.ProjectID == dailyWork.ProjectID && w.StartDate <= dailyWork.Date && (w.Complete == false || w.EndDate >= dailyWork.Date)).ToList(); return(View(dailyWorkUnitData)); }
public async Task <ActionResult> EditEditWork(int id, int workid, DailyWorkUnitData dailyWorkUnitData) { if (Session["LoginUserID"] == null) { return(RedirectToAction("Login", "Account")); } if (ModelState.IsValid) { // db.Entry(materialBuyData).State = EntityState.Modified; DailyWork dailyWork = db.DailyWorks.FirstOrDefault(m => m.ID == dailyWorkUnitData.DailyWork.ID); WorkUnit workUnit = await db.WorkUnits.FindAsync(workid); if (workUnit.WorkNameVn != dailyWorkUnitData.WorkUnit.WorkNameVn) { workUnit.Translate = false; } if (workUnit.NoteVn != dailyWorkUnitData.WorkUnit.NoteVn) { workUnit.Translate = false; } workUnit.StartDate = dailyWorkUnitData.WorkUnit.StartDate; workUnit.EndDate = dailyWorkUnitData.WorkUnit.EndDate; workUnit.Complete = dailyWorkUnitData.WorkUnit.Complete; workUnit.WorkNameVn = dailyWorkUnitData.WorkUnit.WorkNameVn; workUnit.NoteVn = dailyWorkUnitData.WorkUnit.NoteVn; await db.SaveChangesAsync(); return(RedirectToAction("EditAddWork", new { id = dailyWorkUnitData.DailyWork.ID })); } return(View(dailyWorkUnitData)); }
public async Task <ActionResult> EditAddWork(DailyWorkUnitData dailyWorkUnitData) { if (Session["LoginUserID"] == null) { return(RedirectToAction("Login", "Account")); } if (ModelState.IsValid) { // db.Entry(materialBuyData).State = EntityState.Modified; DailyWork dailyWork = db.DailyWorks.FirstOrDefault(m => m.ID == dailyWorkUnitData.DailyWork.ID); dailyWorkUnitData.WorkUnit.WorkNameKr = dailyWorkUnitData.WorkUnit.WorkNameVn; dailyWorkUnitData.WorkUnit.NoteKr = dailyWorkUnitData.WorkUnit.NoteVn; db.WorkUnits.Add(dailyWorkUnitData.WorkUnit); dailyWork.Project.WorkUnits.Add(dailyWorkUnitData.WorkUnit); await db.SaveChangesAsync(); return(RedirectToAction("EditAddWork", new { id = dailyWorkUnitData.DailyWork.ID })); } return(View(dailyWorkUnitData)); }