public ActionResult Create() { RoleOrganizationModels model = new RoleOrganizationModels(); model.OrganizationId = CurrentUser.ListOrganizationId[0]; //model.GetListStore(lstStore); model.GetModule(); model.ListCompany = lstCompany; return(View(model)); }
public RoleOrganizationModels GetDetail(string id) { try { RoleOrganizationModels model = _ROfactory.GetDetail(id); model.OrganizationName = CurrentUser.OrganizationName; model.GetModule(); var listMP = _MPfactory.GetData(id); var modelListModule = model.ListModule; SetModulePermisson(ref modelListModule, listMP); //====== model.ListCompany = lstCompany; //model.GetListStore(lstStore); var listRO = _RoSfactory.GetData(id, lstStore); if (listRO != null) { model.ListCompany.ForEach(z => { z.ListStore.ForEach(x => { var RO = listRO.Where(o => o.StoreId.Equals(x.StoreId)).FirstOrDefault(); x.Checked = RO == null ? false : RO.IsActive; x.Id = RO == null ? "" : RO.Id; }); //==============checked for Parent(Company) int countStore = z.ListStore.Count(); int countStoreCheck = z.ListStore.Count(x => x.Checked); z.Checked = countStore == countStoreCheck; }); //model.ListStore.ForEach(x => //{ // var RO = listRO.Where(z => z.StoreId.Equals(x.StoreId)).FirstOrDefault(); // x.Checked = RO == null ? false : RO.IsActive; // x.Id = RO == null ? "" : RO.Id; //}); //=================== model.RO = string.Join("<br/>", listRO.Where(z => z.IsActive).Select(x => x.StoreName).ToList()); } //model.ListStore = model.ListStore.OrderByDescending(x => x.Checked).ToList(); return(model); } catch (Exception ex) { _logger.Error("G_Role_Detail: " + ex); return(null); } }
public ActionResult Delete(RoleOrganizationModels model) { try { string msg = ""; var result = _ROfactory.Delete(model.Id, ref msg); if (!result) { ModelState.AddModelError("Name", msg); Response.StatusCode = (int)HttpStatusCode.BadRequest; return(PartialView("_Delete", model)); } return(new HttpStatusCodeResult(HttpStatusCode.OK)); } catch (Exception ex) { _logger.Error("G_Role_Delete: " + ex); ModelState.AddModelError("Name", CurrentUser.GetLanguageTextFromKey("Have an error when you delete a role")); Response.StatusCode = (int)HttpStatusCode.BadRequest; return(PartialView("_Delete", model)); } }
public PartialViewResult Delete(string id) { RoleOrganizationModels model = GetDetail(id); return(PartialView("_Delete", model)); }
public ActionResult Edit(RoleOrganizationModels model) { try { //if (string.IsNullOrEmpty(model.Name)) // ModelState.AddModelError("Name", CurrentUser.GetLanguageTextFromKey("Role Name is required")); //========== //var countUnSelect = model.ListStore.Count(x => x.Checked == false); //if (countUnSelect == model.ListStore.Count) //{ // ModelState.AddModelError("ListStore", CurrentUser.GetLanguageTextFromKey("Please choose at least Store")); //} int countUnSelect = model.ListCompany .Select(x => x.ListStore.Count(z => z.Checked == false)) .Sum(); int countTotalStore = model.ListCompany .Select(x => x.ListStore.Count()) .Sum(); //var countUnSelect = model.ListStore.Count(x => x.Checked == false); if (countUnSelect == countTotalStore /*model.ListStore.Count*/) { ModelState.AddModelError("ListStore", CurrentUser.GetLanguageTextFromKey("Please choose at least Store")); } if (!ModelState.IsValid) { model = GetDetail(model.Id); Response.StatusCode = (int)HttpStatusCode.BadRequest; return(PartialView("_Edit", model)); } foreach (var item in model.ListCompany) { model.ListStore.AddRange(item.ListStore.Where(x => x.Checked || !string.IsNullOrEmpty(x.Id)).ToList()); } model.ModifiedUser = CurrentUser.UserName; model.CreatedUser = CurrentUser.UserName; model.ListModule.ForEach(x => { x.IsActive = true; if (string.IsNullOrEmpty(x.ModuleParentID)) { x.ModuleParentID = ""; } //======= if (x.Name.ToLower().Equals("reports")) { x.IsAction = x.IsView; if (x.ListChild != null && x.ListChild.Count > 0) { x.ListChild.ForEach(z => { z.IsAction = z.IsView; z.IsActive = z.IsView; }); } } }); string msg = ""; bool result = _ROfactory.Update(model, ref msg); if (result) { return(RedirectToAction("Index")); } else { model = GetDetail(model.Id); ModelState.AddModelError("Name", msg); Response.StatusCode = (int)HttpStatusCode.BadRequest; return(PartialView("_Edit", model)); } } catch (Exception ex) { _logger.Error("G_Role_Edit: " + ex); return(new HttpStatusCodeResult(400, ex.Message)); } }
public bool Insert(RoleOrganizationModels model, ref string msg) { bool result = true; using (NuWebContext cxt = new NuWebContext()) { try { var itemExsit = cxt.G_RoleOrganization.Any(x => x.Name.ToLower().Equals(model.Name.ToLower()) && x.OrganizationId == model.OrganizationId); if (itemExsit) { result = false; msg = "Role's name [" + model.Name + "] is duplicated"; } else { string RoleID = Guid.NewGuid().ToString(); string msgChild = ""; G_RoleOrganization item = new G_RoleOrganization(); item.Id = RoleID; item.Name = model.Name; item.IsActive = model.IsActive; item.OrganizationId = model.OrganizationId; item.CreatedDate = DateTime.Now; item.CreatedUser = model.CreatedUser; item.ModifiedDate = DateTime.Now; item.ModifiedUser = model.ModifiedUser; cxt.G_RoleOrganization.Add(item); cxt.SaveChanges(); //===========Get List Module Permission GetListModulePermission(model.ListModule, ""); ListModPer.ForEach(x => { x.Id = ""; x.RoleID = RoleID; x.CreatedDate = DateTime.Now; x.CreatedUser = model.CreatedUser; x.ModifiedDate = DateTime.Now; x.ModifiedUser = model.ModifiedUser; x.Status = (byte)Commons.EStatus.Actived; }); _MPFactory.InsertOrUpdate(ListModPer, ref msgChild); //=========== Get List Approval Store List <RoleOnStoreModels> listRoStore = new List <RoleOnStoreModels>(); foreach (var roleonStore in model.ListStore) { listRoStore.Add(new RoleOnStoreModels { CreatedDate = DateTime.Now, CreatedUser = model.CreatedUser, ModifiedUser = model.ModifiedUser, ModifiedDate = DateTime.Now, Id = roleonStore.Id, IsActive = roleonStore.Checked, StoreId = roleonStore.StoreId, RoleId = RoleID }); } _RoSfactory.InsertOrUpdate(listRoStore, ref msgChild); } } catch (Exception ex) { _logger.Error(ex); result = false; } finally { if (cxt != null) { cxt.Dispose(); } } } return(result); }
public bool Update(RoleOrganizationModels model, ref string msg) { bool result = true; using (NuWebContext cxt = new NuWebContext()) { try { var itemExsit = cxt.G_RoleOrganization.Where(x => x.Name.ToLower().Equals(model.Name.ToLower()) && x.OrganizationId == model.OrganizationId).FirstOrDefault(); bool isExsit = false; if (itemExsit != null) { if (!itemExsit.Id.Equals(model.Id)) { result = false; isExsit = true; msg = "Role's name [" + model.Name + "] is duplicated"; } } if (!isExsit) { var itemUpdate = (from tb in cxt.G_RoleOrganization where tb.Id == model.Id select tb).FirstOrDefault(); itemUpdate.Id = model.Id; itemUpdate.Name = model.Name; itemUpdate.IsActive = model.IsActive; itemUpdate.ModifiedUser = model.ModifiedUser; itemUpdate.ModifiedDate = DateTime.Now; cxt.SaveChanges(); //===========Get List Module Permission string RoleID = itemUpdate.Id; string msgChild = ""; GetListModulePermission(model.ListModule, ""); //Update var listMP = _MPFactory.GetData(RoleID); ListModPer.ForEach(x => { var itemExist = listMP.Where(z => z.RoleID.Equals(RoleID) && z.ModuleID.Equals(x.ModuleID)).FirstOrDefault(); x.Id = itemExist == null ? "" : itemExist.Id; x.RoleID = RoleID; x.CreatedDate = DateTime.Now; x.CreatedUser = model.CreatedUser; x.ModifiedDate = DateTime.Now; x.ModifiedUser = model.ModifiedUser; x.Status = (byte)Commons.EStatus.Actived; }); _MPFactory.InsertOrUpdate(ListModPer, ref msgChild); //=========== Get List Approval Store List <RoleOnStoreModels> listRoStore = new List <RoleOnStoreModels>(); foreach (var roleonStore in model.ListStore) { listRoStore.Add(new RoleOnStoreModels { CreatedDate = DateTime.Now, CreatedUser = model.CreatedUser, ModifiedUser = model.ModifiedUser, ModifiedDate = DateTime.Now, Id = roleonStore.Id, IsActive = roleonStore.Checked, StoreId = roleonStore.StoreId, RoleId = RoleID }); } _RoSfactory.InsertOrUpdate(listRoStore, ref msgChild); } } catch (Exception ex) { _logger.Error(ex); result = false; } finally { if (cxt != null) { cxt.Dispose(); } } } return(result); }