public MessageReport DeleteById(string id, ref tblLED obj)
        {
            var re = new MessageReport();

            re.Message   = "Error";
            re.isSuccess = false;

            try
            {
                obj = GetById(Convert.ToInt32(id));
                if (obj != null)
                {
                    _tblLEDRepository.Delete(n => n.LEDID.ToString() == id);

                    Save();

                    re.Message   = FunctionHelper.GetLocalizeDictionary("Home", "notification")["DeleteSuccess"];;
                    re.isSuccess = true;
                }
                else
                {
                    re.Message   = FunctionHelper.GetLocalizeDictionary("Home", "notification")["record_does_not_exist"];;
                    re.isSuccess = false;
                }
            }
            catch (Exception ex)
            {
                re.Message   = ex.Message;
                re.isSuccess = false;
            }

            return(re);
        }
Example #2
0
        public JsonResult Delete(string id)
        {
            var obj = new tblLED();

            var result = _tblLEDService.DeleteById(id, ref obj);

            if (result.isSuccess)
            {
                WriteLog.Write(result, GetCurrentUser.GetUser(), obj.LEDID.ToString(), obj.LEDName, "tblLED", ConstField.ParkingCode, ActionConfigO.Delete);
            }

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
        public MessageReport Create(tblLED obj)
        {
            var re = new MessageReport();

            re.Message   = "Error";
            re.isSuccess = false;

            try
            {
                _tblLEDRepository.Add(obj);

                Save();

                re.Message   = FunctionHelper.GetLocalizeDictionary("Home", "notification")["addSuccess"];
                re.isSuccess = true;
            }
            catch (Exception ex)
            {
                re.Message   = ex.Message;
                re.isSuccess = false;
            }

            return(re);
        }
Example #4
0
        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));
            }
        }