public async Task <ActionResult> Edit([Bind(Include = "ID,EmployeeID,TitleVn,TitleKr,NoteVn,NoteKr,Date,UploadFiles,Translate")] Board board) { if (Session["LoginUserID"] == null) { return(RedirectToAction("Login", "Account")); } Board sboard = await db.Boards.FindAsync(board.ID); if (sboard != null && ModelState.IsValid) { for (int i = 0; i < Request.Files.Count; i++) { var file = Request.Files[i]; if (file != null && file.ContentLength > 0) { var fileName = Path.GetFileName(file.FileName); UploadFile uploadFile = new UploadFile() { FileName = fileName, SaveFileName = Guid.NewGuid() + "_" + fileName, FolderName = "Board", Date = DateTime.Now }; var path = Path.Combine(Server.MapPath("~/UploadFile/"), uploadFile.FolderName + "/" + uploadFile.SaveFileName); file.SaveAs(path); db.Entry(uploadFile).State = EntityState.Added; sboard.UploadFiles.Add(uploadFile); } } sboard.TitleKr = board.TitleKr; sboard.TitleVn = board.TitleVn; sboard.NoteKr = board.NoteKr; sboard.NoteVn = board.NoteVn; sboard.Translate = board.Translate; db.Entry(sboard).State = EntityState.Modified; await db.SaveChangesAsync(); // return RedirectToAction("Index"); return(RedirectToAction("Index", new { translate = Session["Translate"] })); } ViewBag.EmployeeID = new SelectList(db.Employees, "ID", "Name", board.EmployeeID); return(View(board)); }
public async Task <ActionResult> Details([Bind(Include = "ID,CompanyID,NameVn,NameKr,Date,Company,Manager,ManagerID,Constructor,ConstructorID,UploadFiles,Translate")] Project project) { if (Session["LoginUserID"] == null) { return(RedirectToAction("Login", "Account")); } if (Convert.ToInt32(Session["LoginUserSecurity"]) < Convert.ToInt32(Security.Manager)) { return(RedirectToAction("Index", "Home")); } Project sproject = await db.Projects.FindAsync(project.ID); if (sproject != null && ModelState.IsValid) { for (int i = 0; i < Request.Files.Count; i++) { var file = Request.Files[i]; if (file != null && file.ContentLength > 0) { var fileName = Path.GetFileName(file.FileName); UploadFile uploadFile = new UploadFile() { FileName = fileName, SaveFileName = Guid.NewGuid() + "_" + fileName, FolderName = "Project", Date = DateTime.Now, Security = true }; var path = Path.Combine(Server.MapPath("~/UploadFile/"), uploadFile.FolderName + "/" + uploadFile.SaveFileName); file.SaveAs(path); db.Entry(uploadFile).State = EntityState.Added; sproject.UploadFiles.Add(uploadFile); } } await db.SaveChangesAsync(); // return RedirectToAction("Index"); return(RedirectToAction("Details", new { id = project.ID })); } // ViewBag.CompanyID = new SelectList(db.Companys, "ID", "Name", project.CompanyID); return(View(project)); }
public async Task <ActionResult> Edit([Bind(Include = "ID,ProjectID,ProparingPersonID,Date,PrrocessPerPlan,PrrocessPerResult,WeatherVn,WeatherKr,NoteVn,NoteKr,UploadFiles,Translate")] DailyWork dailyWork) { if (ModelState.IsValid) { db.Entry(dailyWork).State = EntityState.Modified; for (int i = 0; i < Request.Files.Count; i++) { var file = Request.Files[i]; if (file != null && file.ContentLength > 0) { var fileName = Path.GetFileName(file.FileName); UploadFile uploadFile = new UploadFile() { FileName = fileName, SaveFileName = Guid.NewGuid() + "_" + fileName, FolderName = "DailyWork", Date = DateTime.Now }; var path = Path.Combine(Server.MapPath("~/UploadFile/"), uploadFile.FolderName + "/" + uploadFile.SaveFileName); file.SaveAs(path); db.Entry(uploadFile).State = EntityState.Added; if (dailyWork.UploadFiles == null) { dailyWork.UploadFiles = new List <UploadFile>(); } dailyWork.UploadFiles.Add(uploadFile); } } await db.SaveChangesAsync(); return(RedirectToAction("Index", new { projectid = dailyWork.ProjectID, translate = Session["Translate"] })); } ViewBag.ProjectID = new SelectList(db.Projects, "ID", "NameVn", dailyWork.ProjectID); ViewBag.ProparingPersonID = new SelectList(db.Employees.Where(e => e.ResignID == null), "ID", "Name", dailyWork.ProparingPersonID); return(View(dailyWork)); }
public async Task <ActionResult> Edit([Bind(Include = "ID,ProjectID,StartDate,EndDate,Complete,WorkNameVn,WorkNameKr,NoteVn,NoteKr,Translate")] WorkUnit workUnit) { if (ModelState.IsValid) { db.Entry(workUnit).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index", new { translate = Session["Translate"] })); } ViewBag.ProjectID = new SelectList(db.Projects, "ID", "NameVn", workUnit.ProjectID); return(View(workUnit)); }
public async Task <ActionResult> Edit([Bind(Include = "ID,DailyWorkID,Date,NameVn,NameKr,NoteVn,NoteKr,EquipCount,Translate")] EquipmentUnit equipmentUnit) { if (ModelState.IsValid) { db.Entry(equipmentUnit).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index", new { translate = Session["Translate"] })); } ViewBag.DailyWorkID = new SelectList(db.DailyWorks, "ID", "WeatherVn", equipmentUnit.DailyWorkID); return(View(equipmentUnit)); }
public ActionResult Login(User model) { if (ModelState.IsValid) { var user = db.Users.FirstOrDefault(u => u.UserID.Equals(model.UserID)); if (user == null) { ModelState.AddModelError(string.Empty, "Notthing UserID"); } else { if (user.UserPassword == null || user.UserPassword.Equals("")) { return(RedirectToAction("Register", "Account", model)); } else if (user.UserPassword.Equals(model.UserPassword)) { Session["LoginUserID"] = user.ID; Session["LoginUserEmployeeID"] = user.EmployeeID; Session["LoginUserEmployeeName"] = user.Employee.Name; Session["LoginUserSecurity"] = user.Security; Session["LastLogin"] = user.LastLogin; user.LastLogin = DateTime.Now; db.Entry(user).State = EntityState.Modified; db.SaveChanges(); // return RedirectToAction("Index", "Home"); return(RedirectToAction("ChangeCurrentCulture", "Home", new { id = user.Language })); } else { ModelState.AddModelError(string.Empty, "Recheck UserPassword"); } } } return(View(model)); }
public async Task <ActionResult> Edit([Bind(Include = "ID,FactoryDailyWorkID,ProjectID,Type,EquipCount,NoteVn,NoteKr,Translate")] FactoryWorkUnit factoryWorkUnit) { if (ModelState.IsValid) { db.Entry(factoryWorkUnit).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index", new { translate = Session["Translate"] })); } ViewBag.FactoryDailyWorkID = new SelectList(db.FactoryDailyWorks, "ID", "NoteVn", factoryWorkUnit.FactoryDailyWorkID); ViewBag.ProjectID = new SelectList(db.Projects, "ID", "NameVn", factoryWorkUnit.ProjectID); return(View(factoryWorkUnit)); }
public async Task <ActionResult> Edit([Bind(Include = "ID,ProparingPersonID,Date,NoteVn,NoteKr,Translate")] FactoryDailyWork factoryDailyWork) { if (ModelState.IsValid) { db.Entry(factoryDailyWork).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index", new { translate = Session["Translate"] })); } var employees = db.Employees.Where(e => e.ResignID == null); ViewBag.ProparingPersonID = new SelectList(employees, "ID", "Name", factoryDailyWork.ProparingPersonID); return(View(factoryDailyWork)); }
public async Task <ActionResult> Edit([Bind(Include = "ID,EmployeeID,MaterialBuyID,CompanyID,ProjectID,Date,Amount,Currency,AmountString,Type,StatementType,NoteVn,NoteKr,Translate")] Payment payment) { if (ModelState.IsValid) { db.Entry(payment).State = EntityState.Modified; await db.SaveChangesAsync(); // return RedirectToAction("Index"); return(RedirectToAction("Index", new { translate = Session["Translate"] })); } ViewBag.CompanyID = new SelectList(db.Companys, "ID", "Name", payment.CompanyID); ViewBag.EmployeeID = new SelectList(db.Employees, "ID", "DepartmentVn", payment.EmployeeID); // ViewBag.MaterialBuyID = new SelectList(db.MaterialBuys, "ID", "NoteVn", payment.MaterialBuyID); return(View(payment)); }
public async Task <ActionResult> Edit([Bind(Include = "ID,Name,Address,Tel,Texcode,BankAccount,BankLocation")] Company company) { if (Session["LoginUserID"] == null) { return(RedirectToAction("Login", "Account")); } if (ModelState.IsValid) { db.Entry(company).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(company)); }
public ActionResult Edit([Bind(Include = "ID,EmployeeID,UserID,UserPassword,Security")] User user) { if (Session["LoginUserID"] == null) { return(RedirectToAction("Login", "Account")); } if (ModelState.IsValid) { db.Entry(user).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.EmployeeID = new SelectList(db.Employees, "ID", "Name", user.EmployeeID); return(View(user)); }
public async Task <ActionResult> Edit([Bind(Include = "ID,NameVn,NameKr,Sort,Translate")] MaterialName materialName) { if (Session["LoginUserID"] == null) { return(RedirectToAction("Login", "Account")); } if (ModelState.IsValid) { db.Entry(materialName).State = EntityState.Modified; await db.SaveChangesAsync(); // return RedirectToAction("Index"); return(RedirectToAction("Index", new { translate = Session["Translate"] })); } return(View(materialName)); }
public async Task <ActionResult> Edit([Bind(Include = "ID,EmployeeID,SendDate,ReasonVn,ReasonKr,StartDate,EndDate,HalfDay,Type,Translate")] Personnel personnel) { if (Session["LoginUserID"] == null) { return(RedirectToAction("Login", "Account")); } if (ModelState.IsValid) { db.Entry(personnel).State = EntityState.Modified; await db.SaveChangesAsync(); // return RedirectToAction("Index"); return(RedirectToAction("Index", new { translate = Session["Translate"] })); } ViewBag.EmployeeID = new SelectList(db.Employees, "ID", "Name", personnel.EmployeeID); return(View(personnel)); }
public async Task <ActionResult> Edit([Bind(Include = "ID,Company,ProjectID,Date,NoteVn,NoteKr,VAT,VATPer,Translate")] MaterialBuy materialBuy) { if (Session["LoginUserID"] == null) { return(RedirectToAction("Login", "Account")); } if (ModelState.IsValid) { MaterialBuy smb = await db.MaterialBuys.FindAsync(materialBuy.ID); smb.Company = db.Companys.FirstOrDefault(c => c.Name.Equals(materialBuy.Company.Name)); smb.CompanyID = smb.Company.ID; smb.Project = db.Projects.FirstOrDefault(p => p.ID == materialBuy.ProjectID); smb.ProjectID = smb.Project.ID; smb.Date = materialBuy.Date; smb.NoteVn = materialBuy.NoteVn; smb.NoteKr = materialBuy.NoteKr; smb.VATPer = materialBuy.VATPer; smb.Translate = materialBuy.Translate; db.Entry(smb).State = EntityState.Modified; await db.SaveChangesAsync(); // return RedirectToAction("Index"); return(RedirectToAction("Index", new { translate = Session["Translate"] })); } // ViewBag.CompanyID = new SelectList(db.Companys, "ID", "Name", materialBuy.CompanyID); if (Convert.ToInt32(Session["CurrentCulture"]) == 2) { ViewBag.ProjectID = new SelectList(db.Projects.OrderByDescending(p => p.Date), "ID", "NameKr", materialBuy.ProjectID); } else { ViewBag.ProjectID = new SelectList(db.Projects.OrderByDescending(p => p.Date), "ID", "NameVn", materialBuy.ProjectID); } return(View(materialBuy)); }
public async Task <ActionResult> Edit(int?id, byte[] rowVersion, HttpPostedFileBase image = null) { if (Session["LoginUserID"] == null) { return(RedirectToAction("Login", "Account")); } string[] fieldsToBind = new string[] { "DepartmentVn", "DepartmentKr", "Name", "EmployeeNo", "BankAccount", "BankLocation", "TexNo", "JobPosition", "Sex", "BirthDate", "RegistrationNo", "RegistrationDate", "RegistrationPosition", "Tel1", "Tel2", "Email", "Adress", "People", "Religion", "Country", "EducationLevel", "MajorVn", "MajorKr", "Marriage", "DependentChild", "DependentParents", "RowVersion", "Resign", "ImageData", "ImageMimeType", "Translate" }; if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } // var employeeToUpdate = await db.Employees.FindAsync(id); Employee employeeToUpdate = db.Employees .Include(e => e.Resign) .Where(e => e.ID == id) .Single(); if (employeeToUpdate == null) { Employee deleteEmployee = new Employee(); TryUpdateModel(deleteEmployee, fieldsToBind); ModelState.AddModelError(string.Empty, "Delete by another user."); return(View(deleteEmployee)); } if (image != null) { employeeToUpdate.ImageMimeType = image.ContentType; employeeToUpdate.ImageData = new byte[image.ContentLength]; image.InputStream.Read(employeeToUpdate.ImageData, 0, image.ContentLength); } if (TryUpdateModel(employeeToUpdate, fieldsToBind)) { try { if (employeeToUpdate.Resign.ResignDate == null) { employeeToUpdate.Resign = null; } else { employeeToUpdate.ResignID = employeeToUpdate.ID; } db.Entry(employeeToUpdate).OriginalValues["RowVersion"] = rowVersion; await db.SaveChangesAsync(); // return RedirectToAction("Index"); return(RedirectToAction("Index", new { translate = Session["Translate"] })); } catch (DbUpdateConcurrencyException ex) { var entry = ex.Entries.Single(); var clientValues = (Employee)entry.Entity; var databaseEntry = entry.GetDatabaseValues(); if (databaseEntry == null) { ModelState.AddModelError(string.Empty, "Delete by another user."); } else { var databaseValues = (Employee)databaseEntry.ToObject(); if (databaseValues.DepartmentVn != clientValues.DepartmentVn) { ModelState.AddModelError("DepartmentVn", "Current value: " + databaseValues.DepartmentVn); } if (databaseValues.DepartmentKr != clientValues.DepartmentKr) { ModelState.AddModelError("DepartmentKr", "Current value: " + databaseValues.DepartmentKr); } if (databaseValues.Name != clientValues.Name) { ModelState.AddModelError("Name", "Current value: " + databaseValues.Name); } if (databaseValues.EmployeeNo != clientValues.EmployeeNo) { ModelState.AddModelError("EmployeeNo", "Current value: " + databaseValues.EmployeeNo); } if (databaseValues.BankAccount != clientValues.BankAccount) { ModelState.AddModelError("BankAccount", "Current value: " + databaseValues.BankAccount); } if (databaseValues.BankLocation != clientValues.BankLocation) { ModelState.AddModelError("BankLocation", "Current value: " + databaseValues.BankLocation); } if (databaseValues.TexNo != clientValues.TexNo) { ModelState.AddModelError("TexNo", "Current value: " + databaseValues.TexNo); } if (databaseValues.JobPosition != clientValues.JobPosition) { ModelState.AddModelError("JobPosition", "Current value: " + databaseValues.JobPosition); } if (databaseValues.Sex != clientValues.Sex) { ModelState.AddModelError("Sex", "Current value: " + databaseValues.Sex); } if (databaseValues.BirthDate != clientValues.BirthDate) { ModelState.AddModelError("BirthDate", "Current value: " + String.Format("{0:d}", databaseValues.BirthDate)); } if (databaseValues.RegistrationNo != clientValues.RegistrationNo) { ModelState.AddModelError("RegistrationNo", "Current value: " + databaseValues.RegistrationNo); } if (databaseValues.RegistrationDate != clientValues.RegistrationDate) { ModelState.AddModelError("RegistrationDate", "Current value: " + String.Format("{0:d}", databaseValues.RegistrationDate)); } if (databaseValues.RegistrationPosition != clientValues.RegistrationPosition) { ModelState.AddModelError("RegistrationPosition", "Current value: " + databaseValues.RegistrationPosition); } if (databaseValues.Tel1 != clientValues.Tel1) { ModelState.AddModelError("Tel1", "Current value: " + databaseValues.Tel1); } if (databaseValues.Tel2 != clientValues.Tel2) { ModelState.AddModelError("Tel2", "Current value: " + databaseValues.Tel2); } if (databaseValues.Email != clientValues.Email) { ModelState.AddModelError("Email", "Current value: " + databaseValues.Email); } if (databaseValues.Adress != clientValues.Adress) { ModelState.AddModelError("Adress", "Current value: " + databaseValues.Adress); } if (databaseValues.People != clientValues.People) { ModelState.AddModelError("People", "Current value: " + databaseValues.People); } if (databaseValues.Religion != clientValues.Religion) { ModelState.AddModelError("Religion", "Current value: " + databaseValues.Religion); } if (databaseValues.Country != clientValues.Country) { ModelState.AddModelError("Country", "Current value: " + databaseValues.Country); } if (databaseValues.EducationLevel != clientValues.EducationLevel) { ModelState.AddModelError("EducationLevel", "Current value: " + databaseValues.EducationLevel); } if (databaseValues.MajorVn != clientValues.MajorVn) { ModelState.AddModelError("MajorVn", "Current value: " + databaseValues.MajorVn); } if (databaseValues.MajorKr != clientValues.MajorKr) { ModelState.AddModelError("MajorKr", "Current value: " + databaseValues.MajorKr); } if (databaseValues.Marriage != clientValues.Marriage) { ModelState.AddModelError("Marriage", "Current value: " + databaseValues.Marriage); } if (databaseValues.DependentChild != clientValues.DependentChild) { ModelState.AddModelError("DependentChild", "Current value: " + databaseValues.DependentChild); } if (databaseValues.DependentParents != clientValues.DependentParents) { ModelState.AddModelError("DependentParents", "Current value: " + databaseValues.DependentParents); } /* 동시성충돌 해결안됨 * if (databaseValues.Resign != null && clientValues.Resign != null && databaseValues.Resign.ResignDate != clientValues.Resign.ResignDate) * ModelState.AddModelError("ResignDate", "Current value: " + String.Format("{0:d}", databaseValues.Resign.ResignDate)); * if (databaseValues.Resign != null && clientValues.Resign != null && databaseValues.Resign.ResignNoteVn != clientValues.Resign.ResignNoteVn) * ModelState.AddModelError("ResignNoteVn", "Current value: " + databaseValues.Resign.ResignNoteVn); * if (databaseValues.Resign != null && clientValues.Resign != null && databaseValues.Resign.ResignNoteKr != clientValues.Resign.ResignNoteKr) * ModelState.AddModelError("ResignNoteKr", "Current value: " + databaseValues.Resign.ResignNoteKr); */ ModelState.AddModelError(string.Empty, "The record you attempted to edit " + "was modified by another user after you got the original value. The " + "edit operation was canceled and the current values in the database " + "have been displayed. If you still want to edit this record, click " + "the Save button again. Otherwise click the Back to List hyperlink."); employeeToUpdate.RowVersion = databaseValues.RowVersion; } } catch (RetryLimitExceededException /* dex */) { //Log the error (uncomment dex variable name and add a line here to write a log. ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator."); } } return(View(employeeToUpdate)); }