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

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

            try
            {
                obj = GetById(id);
                if (obj != null)
                {
                    obj.IsDeleted = true;
                    _BM_ResidentRepository.Update(obj);

                    Save();

                    re.Message   = FunctionHelper.GetLocalizeDictionary("Home", "notification")["DeleteSuccess"];
                    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 JsonResult Delete(string id)
        {
            var obj = new BM_Resident();

            //Check tồn tại trong cardcustomer
            //var existedInCard = _tblCardService.GetAllByCustomerId(id);
            //if (existedInCard.Any())
            //{
            //    var result1 = new MessageReport();
            //    result1.Message = "Khách hàng đang sử dụng thẻ. Không thể xóa.";
            //    result1.isSuccess = false;
            //}

            //Check tồn tại trong event
            //var existedInEvent = _PK_VehicleEventService.GetAllEventByCustomerId(id);
            //if (existedInEvent.Any())
            //{
            //    var result1 = new Result();
            //    result1.ErrorCode = 500;
            //    result1.Message = "Khách hàng đang tồn tại trong sự kiện. Không thể xóa.";
            //    result1.Success = false;
            //}

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

            if (result.isSuccess)
            {
                WriteLog.Write(result, GetCurrentUser.GetUser(), obj.Id.ToString(), obj.Name, "BM_Resident", ConstField.ResidentCode, ActionConfigO.Delete);
            }

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
        public ActionResult Update(BM_Resident obj, string key = "", string residentGroupIdSearch = "", int page = 1, string ResidentGroup = "")
        {
            ViewBag.keyValue             = key;
            ViewBag.residentGroupIdValue = residentGroupIdSearch;
            ViewBag.PN = page;

            ViewBag.CustomerGroups = GetMenuList();
            // ViewBag.ControllerList = _tblAccessControllerService.GetAllActive();
            //ViewBag.LevelList = _tblAccessLevelService.GetAllActive();

            //Kiểm tra
            var oldObj = _BM_ResidentService.GetById(obj.Id);

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

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

            //Gán giá trị
            oldObj.Name            = obj.Name;
            oldObj.Mobile          = obj.Mobile;
            oldObj.Email           = obj.Email;
            oldObj.CustomerId      = obj.CustomerId;
            oldObj.ResidentGroupId = ResidentGroup;
            oldObj.Note            = obj.Note;
            oldObj.Description     = obj.Description;
            oldObj.Description     = obj.Description;

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

            if (result.isSuccess)
            {
                WriteLog.Write(result, GetCurrentUser.GetUser(), obj.Id.ToString(), obj.Name, "BM_Resident", ConstField.ResidentCode, ActionConfigO.Update);

                return(RedirectToAction("Index", new { page = page, key = key, residentGroupId = residentGroupIdSearch, selectedId = oldObj.Id }));
            }
            else
            {
                ModelState.AddModelError("", result.Message);
                return(View(oldObj));
            }
        }
        public ActionResult Create(BM_Resident obj, bool SaveAndCountinue = false, string key = "", string residentGroupId = "", string ResidentGroup = "")
        {
            ViewBag.keyValue           = key;
            ViewBag.ResidentGroupValue = residentGroupId;
            ViewBag.ResidentGroups     = GetMenuList();
            // ViewBag.ControllerList = _tblAccessControllerService.GetAllActive();
            // ViewBag.LevelList = _tblAccessLevelService.GetAllActive();

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


            //Gán giá trị
            obj.Id = Guid.NewGuid().ToString();
            obj.ResidentGroupId = ResidentGroup;
            obj.DateCreated     = DateTime.UtcNow;
            obj.IsDeleted       = false;

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

            if (result.isSuccess)
            {
                WriteLog.Write(result, GetCurrentUser.GetUser(), obj.Id.ToString(), obj.Id.ToString(), "BM_Resident", ConstField.ResidentCode, ActionConfigO.Create);

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

                return(RedirectToAction("Index", new { key = key, residentGroupId = residentGroupId, selectedId = obj.Id }));
            }
            else
            {
                ModelState.AddModelError("", result.Message);
                return(View(obj));
            }
        }
        public MessageReport Create(BM_Resident obj)
        {
            var re = new MessageReport();

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

            try
            {
                _BM_ResidentRepository.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);
        }