public ActionResult Update(string id, int page = 1, string key = "", string pc = "", string group = "") { ViewBag.PCs = GetPCList(); ViewBag.SideIndex = FunctionHelper.HubList1(); ViewBag.LedType = FunctionHelper.LEDType1(); ViewBag.keyValue = key; ViewBag.pcValue = pc; ViewBag.groupValue = group; ViewBag.PN = page; var obj = _tblLEDService.GetById(Convert.ToInt32(id)); tblLEDView objCreate = new tblLEDView(); objCreate.LEDID = obj.LEDID; objCreate.LEDName = obj.LEDName; objCreate.PCID = obj.PCID; objCreate.Comport = obj.Comport; objCreate.Baudrate = obj.Baudrate; objCreate.SideIndex = Convert.ToInt32(obj.SideIndex); objCreate.Address = Convert.ToInt32(obj.Address); objCreate.LedType = obj.LedType; objCreate.EnableLED = obj.EnableLED; return(View(objCreate)); }
public ActionResult Create(tblLEDView obj, string key, string pc, string group = "", bool SaveAndCountinue = false) { ViewBag.PCs = GetPCList(); ViewBag.SideIndex = FunctionHelper.HubList1(); ViewBag.LedType = FunctionHelper.LEDType1(); ViewBag.keyValue = key; ViewBag.pcValue = pc; ViewBag.groupValue = group; if (!ModelState.IsValid) { return(View(obj)); } if (string.IsNullOrWhiteSpace(obj.LEDName) || (obj.Address <= 0 || obj.Address == null) || obj.SideIndex == null) { if (string.IsNullOrWhiteSpace(obj.LEDName)) { ModelState.AddModelError("LEDName", FunctionHelper.GetLocalizeDictionary("Home", "notification")["LEDName"]); } if (obj.Address <= 0 || obj.Address == null) { ModelState.AddModelError("Address", FunctionHelper.GetLocalizeDictionary("Home", "notification")["addIp"]); } if (obj.SideIndex == null) { ModelState.AddModelError("SideIndex", FunctionHelper.GetLocalizeDictionary("Home", "notification")["interface"]); } return(View(obj)); } var existed = _tblLEDService.GetByName(obj.LEDName); if (existed != null) { ModelState.AddModelError("LEDName", FunctionHelper.GetLocalizeDictionary("Home", "notification")["LED_Name_already_exists"]); return(View(obj)); } //Thực hiện thêm mới tblLED objCreate = new tblLED(); objCreate.LEDName = obj.LEDName; objCreate.PCID = obj.PCID; objCreate.Comport = obj.Comport; objCreate.Baudrate = obj.Baudrate; objCreate.SideIndex = Convert.ToInt32(obj.SideIndex); objCreate.Address = Convert.ToInt32(obj.Address); objCreate.LedType = obj.LedType; objCreate.EnableLED = obj.EnableLED; var result = _tblLEDService.Create(objCreate); if (result.isSuccess) { WriteLog.Write(result, GetCurrentUser.GetUser(), obj.LEDID.ToString(), obj.LEDName, "tblLED", ConstField.ParkingCode, ActionConfigO.Create); if (SaveAndCountinue) { TempData["Success"] = result.Message; return(RedirectToAction("Create", new { group = group, key = key, pc = pc, selectedId = obj.LEDID })); } return(RedirectToAction("Index", new { group = group, key = key, pc = pc, selectedId = obj.LEDID })); } else { return(View(obj)); } }
public ActionResult Update(tblLEDView obj, int page = 1, string key = "", string pc = "", string group = "") { ViewBag.PCs = GetPCList(); ViewBag.SideIndex = FunctionHelper.HubList1(); ViewBag.LedType = FunctionHelper.LEDType1(); ViewBag.keyValue = key; ViewBag.pcValue = pc; ViewBag.groupValue = group; ViewBag.PN = page; var oldObj = _tblLEDService.GetById(obj.LEDID); if (oldObj == null) { ViewBag.Error = FunctionHelper.GetLocalizeDictionary("Home", "notification")["record_does_not_exist"]; return(View(obj)); } if (string.IsNullOrWhiteSpace(obj.LEDName) || (obj.Address <= 0 || obj.Address == null) || obj.SideIndex == null) { if (string.IsNullOrWhiteSpace(obj.LEDName)) { ModelState.AddModelError("LEDName", FunctionHelper.GetLocalizeDictionary("Home", "notification")["LEDName"]); } if (obj.Address <= 0 || obj.Address == null) { ModelState.AddModelError("Address", FunctionHelper.GetLocalizeDictionary("Home", "notification")["addIp"]); } if (obj.SideIndex == null) { ModelState.AddModelError("SideIndex", FunctionHelper.GetLocalizeDictionary("Home", "notification")["interface"]); } return(View(obj)); } var objExisted = _tblLEDService.GetByName_Id(obj.LEDName, obj.LEDID.ToString()); if (objExisted != null) { ViewBag.Error = FunctionHelper.GetLocalizeDictionary("Home", "notification")["LED_Name_already_exists"]; return(View(oldObj)); } //Gán giá trị oldObj.SideIndex = Convert.ToInt32(obj.SideIndex); oldObj.LedType = obj.LedType; oldObj.Address = Convert.ToInt32(obj.Address); oldObj.Baudrate = obj.Baudrate; oldObj.Comport = obj.Comport; oldObj.EnableLED = obj.EnableLED; oldObj.LEDName = obj.LEDName; //Thực hiện cập nhật var result = _tblLEDService.Update(oldObj); if (result.isSuccess) { WriteLog.Write(result, GetCurrentUser.GetUser(), obj.LEDID.ToString(), obj.LEDName, "tblLED", ConstField.ParkingCode, ActionConfigO.Update); return(RedirectToAction("Index", new { group = group, page = page, key = key, pc = pc, selectedId = obj.LEDID })); } else { ModelState.AddModelError("", result.Message); return(View(oldObj)); } }