public MessageReport DeleteById(string id, ref BM_Apartment obj) { var re = new MessageReport(); re.Message = "Error"; re.isSuccess = false; try { obj = GetById(id); if (obj != null) { obj.IsDeleted = true; _BM_ApartmentRepository.Update(obj); 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 ActionResult Create(string id) { ViewBag.Building = _BM_BuildingService.BuildingIdToDDL(); ViewBag.Purpose = BM_ApartmentUseToDDL(); ViewBag.TypeElec = FunctionHelper.TypeElec(); var model = _BM_ApartmentService.GetById(id); if (model != null) { var listMB = _BM_Apartment_MemberService.GetMemberApartment(model.Id); ViewBag.strEmployeeChoose = JsonConvert.SerializeObject(listMB); var listSV = _BM_Apartment_ServiceService.GetServiceApartment(model.Id); ViewBag.strServiceChoose = JsonConvert.SerializeObject(listSV); } else { model = new BM_Apartment(); } return(View(model)); }
/// <summary> /// Xóa /// </summary> /// <modified> /// Author Date Comments /// TrungNQ 18/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 BM_Apartment(); var result = _BM_ApartmentService.DeleteById(id, ref obj); return(Json(result, JsonRequestBehavior.AllowGet)); }
public ActionResult Update(BM_Apartment obj, string objId, int pageNumber = 1) { //Danh sách sử dụng ViewBag.Building = _BM_BuildingService.BuildingIdToDDL(); ViewBag.Purpose = BM_ApartmentUseToDDL(); ViewBag.TypeElec = FunctionHelper.TypeElec(); //Kiểm tra var oldObj = _BM_ApartmentService.GetById(objId); if (oldObj == null) { ViewBag.Error = "Thông tin không tồn tại"; return(View(obj)); } // if (string.IsNullOrWhiteSpace(obj.Name)) { ModelState.AddModelError("Name", "Vui lòng nhập tên"); return(View(obj)); } var existed = _BM_ApartmentService.GetByName(obj.Name); if (existed != null && existed.Id != objId) { ModelState.AddModelError("Name", "Thông tin đã tồn tại"); return(View(obj)); } //Gán giá trị oldObj.Name = obj.Name; oldObj.Description = obj.Description; //Thực hiện cập nhật var result = _BM_ApartmentService.Update(oldObj); if (result.isSuccess) { if (!string.IsNullOrEmpty(url)) { return(Redirect(url)); } else { return(RedirectToAction("Index")); } } else { ModelState.AddModelError("", result.Message); return(View(oldObj)); } }
public MessageReport Create(BM_Apartment obj) { var re = new MessageReport(); re.Message = "Error"; re.isSuccess = false; try { _BM_ApartmentRepository.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); }
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)); } }