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

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

            try
            {
                obj = GetById(Guid.Parse(id));
                if (obj != null)
                {
                    _BM_Apartment_MemberRepository.Delete(n => n.Id.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);
        }
        public MessageReport Create(BM_Apartment_Member obj)
        {
            var re = new MessageReport();

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

            try
            {
                _BM_Apartment_MemberRepository.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);
        }
Пример #3
0
        public ActionResult Create(BM_Apartment obj, string strEmployeeChoose = "", string strServiceChoose = "", string objId = "", string strfloor = "", bool SaveAndCountinue = false)
        {
            var result = new MessageReport(false, "Có lỗi xảy ra");

            ViewBag.Building = _BM_BuildingService.BuildingIdToDDL();
            ViewBag.Purpose  = BM_ApartmentUseToDDL();
            ViewBag.TypeElec = FunctionHelper.TypeElec();
            //Kiểm tra
            if (!ModelState.IsValid)
            {
                return(View(obj));
            }


            var model = _BM_ApartmentService.GetById(objId);

            //Kiểm tra
            if (model == null)
            {
                //Thêm mới
                model = new BM_Apartment
                {
                    Id             = Common.GenerateId(),
                    IsDeleted      = false,
                    DateCreated    = DateTime.Now,
                    Acreage        = obj.Acreage,
                    ApartmentUseId = obj.ApartmentUseId,
                    BuildingId     = obj.BuildingId,
                    FloorId        = strfloor,
                    Code           = obj.Code,
                    Description    = obj.Description,
                    ElecticityType = obj.ElecticityType,
                    Name           = obj.Name,
                    Note           = obj.Note
                };

                //Thực hiện thêm mới
                result = _BM_ApartmentService.Create(model);
            }
            else
            {
                //Cập nhật
                model.Acreage        = obj.Acreage;
                model.ApartmentUseId = obj.ApartmentUseId;
                model.BuildingId     = obj.BuildingId;
                model.FloorId        = strfloor;
                model.Code           = obj.Code;
                model.Description    = obj.Description;
                model.ElecticityType = obj.ElecticityType;
                model.Name           = obj.Name;

                //Thực hiện cập nhật
                result = _BM_ApartmentService.Update(model);
            }


            if (result.isSuccess)
            {
                //xóa danh sách thành viên cũ
                _BM_Apartment_MemberService.DeleteMemberApartment(model.Id);

                //xóa danh sách dịch vụ cũ
                _BM_Apartment_ServiceService.DeleteServiceApartment(model.Id);

                //thêm thành viên
                if (!string.IsNullOrEmpty(strEmployeeChoose))
                {
                    var listResident = JsonConvert.DeserializeObject <List <BM_ResidentCustom> >(strEmployeeChoose);
                    if (listResident != null && listResident.Count() > 0)
                    {
                        foreach (var item in listResident)
                        {
                            var objMB = new BM_Apartment_Member
                            {
                                Id          = Common.GenerateId(),
                                IsDeleted   = false,
                                ApartmentId = model.Id,
                                ResidentId  = item.Id,
                                RoleId      = ""
                            };
                            _BM_Apartment_MemberService.Create(objMB);
                        }
                    }
                }

                //thêm dịch vụ
                if (!string.IsNullOrEmpty(strServiceChoose))
                {
                    var listService = JsonConvert.DeserializeObject <List <BM_Building_ServiceCustom> >(strServiceChoose);
                    if (listService != null && listService.Count() > 0)
                    {
                        foreach (var item in listService)
                        {
                            var arr = item.SchedulePay.Split(';');

                            var objSV = new BM_Apartment_Service
                            {
                                Id           = Common.GenerateId(),
                                IsDeleted    = false,
                                ApartmentId  = model.Id,
                                Price        = item.Price,
                                SchedulePay  = arr.Length > 0 ? arr[0]: "",
                                ScheduleType = arr.Length > 0 && arr[1].Contains("hàng tháng") ? 1 : 2,
                                ServiceId    = item.Id,
                                StartDate    = Convert.ToDateTime(item.DateStart),
                                EndDate      = Convert.ToDateTime(item.DateEnd)
                            };
                            _BM_Apartment_ServiceService.Create(objSV);
                        }
                    }
                }

                if (SaveAndCountinue)
                {
                    TempData["Success"] = result.Message;
                    return(RedirectToAction("Create"));
                }

                if (!string.IsNullOrEmpty(url))
                {
                    return(Redirect(url));
                }
                else
                {
                    return(RedirectToAction("Index"));
                }
            }
            else
            {
                ModelState.AddModelError("", result.Message);
                return(View(obj));
            }
        }