public ActionResult Edit([Bind(Include = "ID,Name,UserLogin,UserPassword,UgID,TelNo,Email")] Staff staff) { if (ModelState.IsValid) { db.Entry(staff).State = EntityState.Modified; db.SaveChanges(); StaffID = staff.ID; //Delete old data StaffWarehouse sf = db.StaffWarehouses.Find(StaffID); db.StaffWarehouses.Remove(sf); db.SaveChanges(); staff.StWh.RemoveAt(0); foreach (var a in staff.StWh) { StaffWarehouse SW = new StaffWarehouse(); SW.StID = StaffID; SW.WhID = a.WhID; SW.IsManager = a.IsManager; db.StaffWarehouses.Add(SW); db.SaveChanges(); } return(Json("success")); } ViewBag.ID = new SelectList(db.UserGroups, "ID", "Name", staff.ID); return(View(staff)); }
public ActionResult Edit([Bind(Include = "ID,DocNo,DocDate,CreateBy,DocType,WhID,SpID,Remark,Status,ApproveDate,ApproveBy,ProcessDate,ProcessBy,ToWhID")] Document document) { if (ModelState.IsValid) { db.Entry(document).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CreateBy = new SelectList(db.Staffs, "ID", "Name", document.CreateBy); ViewBag.SpID = new SelectList(db.Suppliers, "ID", "Name", document.SpID); return(View(document)); }
public ActionResult Edit([Bind(Include = "ID,Subject,Symptom,Cause,Solving,CreateBy,CreateDate,TgID,LocationID")] Topic topic) { if (ModelState.IsValid) { db.Entry(topic).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ID = new SelectList(db.Issues, "ID", "Subject", topic.ID); ViewBag.ID = new SelectList(db.TopicGroups, "ID", "Name", topic.ID); return(View(topic)); }
public ActionResult Edit([Bind(Include = "ID,Name")] TopicGroup topicGroup) { if (ModelState.IsValid) { var context = new DLSMEntities(); TopicGroup t = context.TopicGroups.Where(p => p.Name == topicGroup.Name && p.ID != topicGroup.ID).FirstOrDefault(); if (t != null) { // Cannot delete becasue Topic group is using another process TempData["Msg"] = "ชื่อกลุ่มปัญหานี้มีอยู่แล้วในระบบ"; return(RedirectToAction("Edit", new { id = topicGroup.ID, ViewBag.Msg })); } else { db.Entry(topicGroup).State = EntityState.Modified; db.SaveChanges(); } return(RedirectToAction("Index")); } ViewBag.ID = new SelectList(db.Issues, "ID", "Subject", topicGroup.ID); ViewBag.ID = new SelectList(db.Topics, "ID", "Subject", topicGroup.ID); return(View(topicGroup)); }
public ActionResult Edit([Bind(Include = "ID,CreateBy,CreateDate,TgID,Subject,Description,Picture,TpID,Status,WhID,CommendDescription,CommendList")] Issue issue) { if (ModelState.IsValid) { issue.Status = "1"; db.Entry(issue).State = EntityState.Modified; db.SaveChanges(); int isid = issue.ID; if (issue.CommendDescription != null && issue.CommendDescription != "") { Commend c = new Commend(); c.CreateBy = issue.CreateBy; c.CreateDate = issue.CreateDate; c.Description = issue.CommendDescription; c.Status = issue.Status; c.IsID = isid; db.Commends.Add(c); db.SaveChanges(); } return(RedirectToAction("Index")); } ViewBag.CommendList = new SelectList(db.Commends, "ID", "Description"); ViewBag.TgList = new SelectList(db.TopicGroups, "ID", "Name"); ViewBag.WhList = db.Warehouses.ToList(); ViewBag.StList = db.Staffs.ToList(); //because DB Topic has no name but has subject but Viewbag for dropdownlist must has name var listT = db.Topics.ToList(); foreach (var i in listT) { i.Name = i.Subject; } ViewBag.TpList = listT; return(View(issue)); }
public ActionResult Edit([Bind(Include = "WhID,PdID,Qty,Borrow,Transfer,CheckStatus")] Stock stock) { if (ModelState.IsValid) { db.Entry(stock).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.PdID = new SelectList(db.Products, "ID", "Code", stock.PdID); ViewBag.WhID = new SelectList(db.Warehouses, "ID", "Code", stock.WhID); return(View(stock)); }
public ActionResult Edit([Bind(Include = "ID,Code,Name,NameEN,TelNo,Email,IsMain,LocationName,Latitude,Longitude,BackgroundPicture,PvID")] Warehouse warehouse) { if (ModelState.IsValid) { var context = new DLSMEntities(); Warehouse w = context.Warehouses.Where(p => p.Name.Equals(warehouse.Name) && p.ID != warehouse.ID).FirstOrDefault(); if (w != null) { // Cannot delete becasue Topic group is using another process //TempData["Msg"] = "ชื่อคลังวัสดุอุปกรณ์นี้มีอยู่แล้วในระบบ"; //return RedirectToAction("Edit", new { id = warehouse.ID, ViewBag.Msg }); return(Json("รหัส หรือ ชื่อสำนักงานขนส่งนี้มีอยู่แล้วในระบบ")); } else { db.Entry(warehouse).State = EntityState.Modified; db.SaveChanges(); int WarehouseID = warehouse.ID; return(Json(WarehouseID)); } } return(View(warehouse)); }
public ActionResult Edit(Permission p) { using (var dbContextTransaction = db.Database.BeginTransaction()) { try { UserGroup ug = new UserGroup(); ug.ID = p.UserGroupID; ug.Name = p.UserGroupName; db.Entry(ug).State = EntityState.Modified; db.SaveChanges(); int UgID = ug.ID; db.Permissions.RemoveRange(db.Permissions.Where(x => x.UgID == p.UserGroupID)); db.SaveChanges(); if (p.Menu != null && p.Menu.Count() > 0) { foreach (var i in p.Menu) { var mod = db.Modules.SingleOrDefault(x => x.Name == i.ModuleName); Permission per = new Permission(); per.MdCode = mod.Code; per.UgID = UgID; per.Active = 1; db.Permissions.Add(per); db.SaveChanges(); } } db.SaveChanges(); dbContextTransaction.Commit(); return(Json("success")); } catch (Exception ex) { dbContextTransaction.Rollback(); return(Json("failed")); } } }
public ActionResult Edit(Category category) { var context = new DLSMEntities(); Category c = context.Categories.Where(p => p.Name == category.Name && p.ID != category.ID).FirstOrDefault(); if (c != null) { // Cannot delete becasue Topic group is using another process //TempData["Msg"] = "ชื่อกลุ่มวัสดุอุปกรณ์นี้มีอยู่แล้วในระบบ"; //return RedirectToAction("Edit", new { id = category.ID, ViewBag.Msg }); return(Json("ชื่อกลุ่มวัสดุนี้มีอยู่แล้วในระบบ")); } else { db.Entry(category).State = EntityState.Modified; db.SaveChanges(); return(Json("success")); } }
public ActionResult InsertMinStock(int whid, int pdid, int minstock, int predict) { using (DLSMEntities context = new DLSMEntities()) { using (var dbContextTransaction = context.Database.BeginTransaction()) { try { var wh = context.WarehouseMinimums.SingleOrDefault(x => x.WhID == whid && x.PdID == pdid); if (wh == null) { //insert WarehouseMinimum min = new WarehouseMinimum(); min.WhID = whid; min.PdID = pdid; min.MinStock = minstock; min.PredictMonth = (predict == 0 ? min.PredictMonth : predict); context.WarehouseMinimums.Add(min); context.SaveChanges(); } else { var mm = context.WarehouseMinimums.Where(o => o.PdID == pdid && o.WhID == whid).FirstOrDefault(); WarehouseMinimum min = context.WarehouseMinimums.Find(mm.ID); min.WhID = whid; min.PdID = pdid; min.MinStock = minstock; min.PredictMonth = (predict == 0 ? min.PredictMonth : (int?)predict); context.Entry(min).State = EntityState.Modified; context.SaveChanges(); } dbContextTransaction.Commit(); return(Json("success", JsonRequestBehavior.AllowGet)); } catch (Exception ex) { dbContextTransaction.Rollback(); return(Json("fail", JsonRequestBehavior.AllowGet)); } } } }
public ActionResult Edit(Supplier supplier) { if (ModelState.IsValid) { var context = new DLSMEntities(); Supplier c = context.Suppliers.Where(p => p.Name == supplier.Name && p.ID != supplier.ID).FirstOrDefault(); if (c != null) { // Cannot delete becasue Topic group is using another process //TempData["Msg"] = "ชื่อผู้จำหน่ายนี้มีอยู่แล้วในระบบ"; //return RedirectToAction("Edit", new { id = supplier.ID, ViewBag.Msg }); return(Json("ชื่อผู้ประกอบการนี้มีอยู่แล้วในระบบ")); } else { db.Entry(supplier).State = EntityState.Modified; db.SaveChanges(); } return(Json("success")); } return(View(supplier)); }
public ActionResult Edit(Product product) { var context = new DLSMEntities(); Product pp = context.Products.Where(p => p.Name == product.Name && p.ID != product.ID).FirstOrDefault(); if (pp != null) { return(Json("ชื่อวัสดุนี้มีอยู่แล้วในระบบ")); } else { bool check = product.SerialControl.ToLower() == "true" ? true : false; if (check == true) { product.SerialControl = "Y"; } else { product.SerialControl = "N"; } bool check2 = product.IsAsset.ToLower() == "true" ? true : false; if (check2 == true) { product.IsAsset = "Y"; } else { product.IsAsset = "N"; } product.MinStock = 0; db.Entry(product).State = EntityState.Modified; db.SaveChanges(); return(Json("success")); } }
public ActionResult Edit(TransferStaff transferStaff) { if (ModelState.IsValid) { transferStaff.IsActive = 1; db.Entry(transferStaff).State = EntityState.Modified; db.SaveChanges(); return(Json("success")); } var lst = new[] { new { Id = 1, Name = "ผู้จัดการ" }, new { Id = 2, Name = "เจ้าหน้าที่" }, }; transferStaff.EffectiveDate = transferStaff.EffectiveDate.Value.AddYears(543); ViewBag.IsManager = new SelectList(lst, "Id", "Name"); ViewBag.StID = db.Staffs.ToList(); ViewBag.WhID = db.Warehouses.ToList(); ViewBag.ToWhID = db.Warehouses.ToList(); return(View(transferStaff)); }
public ActionResult Edit(WorkStation workStation) { using (DLSMEntities context = new DLSMEntities()) { using (var dbContextTransaction = context.Database.BeginTransaction()) { try { var wk = context.WorkStations.SingleOrDefault(w => w.WhID == workStation.WhID && w.Name == workStation.Name && (w.ID != workStation.ID)); if (wk != null) { return(Json("มีชื่อ WorkStation นี้แล้ว กรุณาเปลี่ยนชื่อ")); } else { context.Entry(workStation).State = EntityState.Modified; int WsID = workStation.ID; //WorkSationDetail wd = context.WorkSationDetails.Find(WsID); context.WorkSationDetails.RemoveRange(context.WorkSationDetails.Where(x => x.WsID == WsID)); context.SaveChanges(); workStation.WorkStationDetailList.RemoveAt(0); foreach (var i in workStation.WorkStationDetailList) { WorkSationDetail dd = new WorkSationDetail(); dd.PdID = i.PdID; dd.WsID = WsID; dd.SerialNO = i.SerialNO; context.WorkSationDetails.Add(dd); // Find Product Serial //Update var upd = (from d in context.StockSerials where d.WhID == workStation.WhID && d.PdID == i.PdID && d.SerialBegin == i.SerialNO select d).ToList().SingleOrDefault(); upd.IpProperty = i.IP; upd.Name = i.Name; context.SaveChanges(); } //WorkSationStaff wf = context.WorkSationStaffs.Find(WsID); context.WorkSationStaffs.RemoveRange(context.WorkSationStaffs.Where(x => x.WsID == WsID)); context.SaveChanges(); workStation.WorkStationStaffList.RemoveAt(0); foreach (var e in workStation.WorkStationStaffList) { WorkSationStaff ee = new WorkSationStaff(); ee.WsID = WsID; ee.StID = e.StID; context.WorkSationStaffs.Add(ee); } context.SaveChanges(); dbContextTransaction.Commit(); return(Json("success")); } } catch (Exception ex) { dbContextTransaction.Rollback(); return(Json(ex.InnerException.Message)); } } } ViewBag.WhID = db.Warehouses.ToList(); return(View(workStation)); }
public JsonResult EditStaff(Staff staff) { using (DLSMEntities context = new DLSMEntities()) { using (var dbContextTransaction = context.Database.BeginTransaction()) { try { if (staff != null && staff.ID != 0) { Staff w = context.Staffs.Where(p => (p.UserLogin == staff.UserLogin) && (p.ID != staff.ID)).FirstOrDefault(); if (w != null) { return(Json("UserLogin นี้มีอยู่แล้วในระบบ")); } if (staff.NewUserPassword != null && staff.NewUserPassword != "") { staff.UserPassword = Hash(staff.NewUserPassword); } context.Entry(staff).State = EntityState.Modified; context.SaveChanges(); StaffID = staff.ID; context.StaffWarehouses.RemoveRange(context.StaffWarehouses.Where(x => x.StID == StaffID)); context.SaveChanges(); staff.StWh.RemoveAt(0); foreach (var a in staff.StWh) { StaffWarehouse SW = new StaffWarehouse(); SW.StID = StaffID; SW.WhID = a.WhID; SW.IsManager = a.IsManager; context.StaffWarehouses.Add(SW); } context.SaveChanges(); //Update some data Referance with Authorize var updRef = (from rf in context.Staffs where rf.RefAuthorize == staff.ID select rf).ToList(); foreach (var i in updRef) { i.TitleTH = staff.TitleTH; i.AuthorizeNameTH = staff.AuthorizeNameTH; i.AuthorizeLastNameTH = staff.AuthorizeLastNameTH; i.TitleEN = staff.TitleEN; i.AuthorizeNameEN = staff.AuthorizeNameEN; i.AuthorizeLastNameEN = staff.AuthorizeLastNameEN; i.Signature = staff.Signature; i.AuthorityType = staff.AuthorityType; i.AuthorizeIdCard = staff.AuthorizeIdCard; } context.SaveChanges(); dbContextTransaction.Commit(); } } catch (Exception ex) { dbContextTransaction.Rollback(); return(Json(ex.InnerException.Message)); } } } return(Json(StaffID)); }