public async Task <ActionResult> EditAddWorkUnit(FactoryDailyWorkUnitData factoryDailyWorkUnitData) { if (Session["LoginUserID"] == null) { return(RedirectToAction("Login", "Account")); } if (ModelState.IsValid) { // db.Entry(materialBuyData).State = EntityState.Modified; FactoryDailyWork dailyWork = db.FactoryDailyWorks.FirstOrDefault(m => m.ID == factoryDailyWorkUnitData.DailyWork.ID); factoryDailyWorkUnitData.WorkUnit.FactoryDailyWorkID = factoryDailyWorkUnitData.DailyWork.ID; // factoryDailyWorkUnitData.WorkUnit.Date = (DateTime)factoryDailyWorkUnitData.DailyWork..Date; FactoryWorkUnit workTemp = db.FactoryWorkUnits.FirstOrDefault(e => e.NoteVn.Equals(factoryDailyWorkUnitData.WorkUnit.NoteVn)); if (workTemp != null) { factoryDailyWorkUnitData.WorkUnit.NoteKr = workTemp.NoteKr; } else { factoryDailyWorkUnitData.WorkUnit.NoteKr = factoryDailyWorkUnitData.WorkUnit.NoteVn; } db.FactoryWorkUnits.Add(factoryDailyWorkUnitData.WorkUnit); dailyWork.FactoryWorkUnits.Add(factoryDailyWorkUnitData.WorkUnit); await db.SaveChangesAsync(); return(RedirectToAction("EditAddWorkUnit", new { id = factoryDailyWorkUnitData.DailyWork.ID })); } return(View(factoryDailyWorkUnitData)); }
public async Task <ActionResult> EditAddWorkUnit(int?id) { if (Session["LoginUserID"] == null) { return(RedirectToAction("Login", "Account")); } if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } FactoryDailyWork dailyWork = await db.FactoryDailyWorks.FindAsync(id); if (dailyWork == null) { return(HttpNotFound()); } var factoryDailyWorkUnitData = new FactoryDailyWorkUnitData(); factoryDailyWorkUnitData.DailyWork = dailyWork; // ViewBag.WorkUnits = db.FactoryWorkUnits.Where(w => w.StartDate <= dailyWork.Date && (w.Complete == false || w.EndDate >= dailyWork.Date)).ToList(); if (Convert.ToInt32(Session["CurrentCulture"]) == 2) { ViewBag.ProjectID = new SelectList(db.Projects.OrderByDescending(p => p.Date), "ID", "NameKr"); } else { ViewBag.ProjectID = new SelectList(db.Projects.OrderByDescending(p => p.Date), "ID", "NameVn"); } return(View(factoryDailyWorkUnitData)); }
public async Task <ActionResult> EditEditWorkUnit(int id, int workunitid, FactoryDailyWorkUnitData factoryDailyWorkUnitData) { 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 == factoryDailyWorkUnitData.DailyWork.ID); FactoryWorkUnit workUnit = await db.FactoryWorkUnits.FindAsync(workunitid); // workUnit.Date = (DateTime)factoryDailyWorkUnitData.DailyWork.Date; workUnit.FactoryDailyWorkID = factoryDailyWorkUnitData.DailyWork.ID; workUnit.ProjectID = factoryDailyWorkUnitData.WorkUnit.ProjectID; // equipmentUnit.NameKr = factoryDailyWorkUnitData.WorkUnit.NameKr; // equipmentUnit.NameVn = factoryDailyWorkUnitData.WorkUnit.NameVn; if (Convert.ToInt32(Session["CurrentCulture"]) == 2) { if (!workUnit.NoteKr.Equals(factoryDailyWorkUnitData.WorkUnit.NoteVn)) { workUnit.NoteVn = factoryDailyWorkUnitData.WorkUnit.NoteVn; workUnit.NoteKr = factoryDailyWorkUnitData.WorkUnit.NoteVn; workUnit.Translate = false; } } else { if (!workUnit.NoteVn.Equals(factoryDailyWorkUnitData.WorkUnit.NoteVn)) { workUnit.NoteVn = factoryDailyWorkUnitData.WorkUnit.NoteVn; workUnit.NoteKr = factoryDailyWorkUnitData.WorkUnit.NoteVn; workUnit.Translate = false; } } workUnit.EquipCount = factoryDailyWorkUnitData.WorkUnit.EquipCount; await db.SaveChangesAsync(); return(RedirectToAction("EditAddWorkUnit", new { id = factoryDailyWorkUnitData.DailyWork.ID })); } return(View(factoryDailyWorkUnitData)); }