Exemplo n.º 1
0
        public MessageReport DeleteById(string id, ref tblCompartment obj)
        {
            var re = new MessageReport();

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

            try
            {
                obj = GetById(Guid.Parse(id));
                if (obj != null)
                {
                    _tblCompartmentRepository.Delete(n => n.CompartmentID.ToString() == id);

                    Save();

                    re.Message   = "Xóa thành công";
                    re.isSuccess = true;
                }
                else
                {
                    re.Message   = "Bản ghi không tồn tại";
                    re.isSuccess = false;
                }
            }
            catch (Exception ex)
            {
                re.Message   = ex.Message;
                re.isSuccess = false;
            }

            return(re);
        }
        public ActionResult Update(tblCompartment obj, int page = 1, string group = "", string key = "")
        {
            //
            ViewBag.PN         = page;
            ViewBag.groupValue = group;
            ViewBag.keyValue   = key;

            //Kiểm tra
            var oldObj = _tblCompartmentService.GetById(obj.CompartmentID);

            if (oldObj == null)
            {
                ViewBag.Error = "Bản ghi không tồn tại";
                return(View(obj));
            }

            if (string.IsNullOrWhiteSpace(obj.CompartmentName))
            {
                ModelState.AddModelError("CompartmentName", "Vui lòng căn hộ");
                return(View(oldObj));
            }

            if (!ModelState.IsValid)
            {
                return(View(oldObj));
            }

            var objExisted = _tblCompartmentService.GetByName(obj.CompartmentName);

            if (objExisted.Where(n => !n.CompartmentID.Equals(obj.CompartmentID)).Any())
            {
                ViewBag.Error = "Bản ghi đã tồn tại";
                return(View(oldObj));
            }

            oldObj.CompartmentName = obj.CompartmentName;
            oldObj.SortOrder       = obj.SortOrder;

            //Thực hiện cập nhật
            var result = _tblCompartmentService.Update(oldObj);

            if (result.isSuccess)
            {
                WriteLog.Write(result, GetCurrentUser.GetUser(), obj.CompartmentID.ToString(), obj.CompartmentName, "tblCompartment", ConstField.ParkingCode, ActionConfigO.Update);

                return(RedirectToAction("Index", new { group = group, key = key, page = page, selectedId = obj.CompartmentID }));
            }
            else
            {
                ModelState.AddModelError("", result.Message);
                return(View(oldObj));
            }
        }
        /// <summary>
        /// Xóa
        /// </summary>
        /// <modified>
        /// Author              Date            Comments
        /// TrungNQ             01/09/2017      Tạo mới
        /// </modified>
        /// <param name="id">Id bản ghi</param>
        /// <returns></returns>
        public JsonResult Delete(string id)
        {
            var obj = new tblCompartment();

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

            if (result.isSuccess)
            {
                WriteLog.Write(result, GetCurrentUser.GetUser(), obj.CompartmentID.ToString(), obj.CompartmentName, "tblCompartment", ConstField.ParkingCode, ActionConfigO.Delete);
            }

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
        public ActionResult Create(tblCompartment obj, bool SaveAndCountinue = false, string group = "", string key = "")
        {
            ViewBag.groupValue = group;
            ViewBag.keyValue   = key;

            //Kiểm tra
            if (!ModelState.IsValid)
            {
                return(View(obj));
            }

            if (string.IsNullOrWhiteSpace(obj.CompartmentName))
            {
                ModelState.AddModelError("CompartmentName", "Vui lòng căn hộ");
                return(View(obj));
            }

            var objExisted = _tblCompartmentService.GetByName(obj.CompartmentName);

            if (objExisted.Any())
            {
                ViewBag.Error = "Bản ghi đã tồn tại";
                return(View(obj));
            }
            //Tạo guid
            obj.CompartmentID = Guid.NewGuid();

            //Thực hiện thêm mới
            var result = _tblCompartmentService.Create(obj);

            if (result.isSuccess)
            {
                WriteLog.Write(result, GetCurrentUser.GetUser(), obj.CompartmentID.ToString(), obj.CompartmentName, "tblCompartment", ConstField.ParkingCode, ActionConfigO.Create);

                if (SaveAndCountinue)
                {
                    TempData["Success"] = result.Message;
                    return(RedirectToAction("Create", new { group = group, key = key, selectedId = obj.CompartmentID }));
                }

                return(RedirectToAction("Index", new { group = group, key = key, selectedId = obj.CompartmentID }));
            }
            else
            {
                return(View(obj));
            }
        }
Exemplo n.º 5
0
        public MessageReport Update(tblCompartment obj)
        {
            var re = new MessageReport();

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

            try
            {
                _tblCompartmentRepository.Update(obj);

                Save();

                re.Message   = "Cập nhật thành công";
                re.isSuccess = true;
            }
            catch (Exception ex)
            {
                re.Message   = ex.Message;
                re.isSuccess = false;
            }

            return(re);
        }