예제 #1
0
        //
        // GET: /Right/Details/By ID

        public ActionResult Details(int id)
        {
            var errorViewModel = new ErrorViewModel();

            try
            {
                //var right = _rightRepository.GetById(id);
                var right = _rightRepository.GetAll().SingleOrDefault(x => x.RightId == id);
                if (right != null)
                {
                    var singleOrDefaultApplication = _applicationRepository.GetAll().SingleOrDefault(x => x.ApplicationId == right.ApplicationId);

                    var singleOrDefaultModule = _moduleRepository.GetAll().SingleOrDefault(x => x.ModuleId == right.ModuleId);

                    if (singleOrDefaultApplication != null && singleOrDefaultModule != null)
                    {
                        var viewModel = new RightViewModel()
                        {
                            RightId = right.RightId, RightName = right.RightName, RightTitle = right.RightTitle, Description = right.Description, ApplicationId = Convert.ToInt32(right.ApplicationId), ApplicationName = singleOrDefaultApplication.ApplicationName, ModuleId = Convert.ToInt32(right.ModuleId), ModuleName = singleOrDefaultModule.ModuleName
                        };

                        return(PartialView("_Details", viewModel));
                    }
                }

                errorViewModel = ExceptionHelper.ExceptionErrorMessageForNullObject();
            }
            catch (Exception ex)
            {
                errorViewModel = ExceptionHelper.ExceptionErrorMessageFormat(ex);
            }

            return(PartialView("_ErrorPopup", errorViewModel));
        }
        public ActionResult Create(RightViewModel model)
        {
            if (ModelState.IsValid)
            {
                BORight right = new BORight();
                Mapper.Map<RightViewModel, BORight>(model, right);

                RightResult rightResult = _rightService.Save(right);
                if (rightResult == RightResult.Success)
                    _cacheService.Remove<MenuStructure>(CacheKeys.MenuStructure);

                switch (rightResult)
                {
                    case RightResult.Success:
                        return RedirectToAction("Index");
                    case RightResult.RightNameAlreadyExists:
                        ModelState.AddModelError("Message", GlobalResource(GlobalResourceUser.RightNameAlreadyExists));
                        break;
                    case RightResult.RightKeyAlreadyExists:
                        ModelState.AddModelError("Message", GlobalResource(GlobalResourceUser.RightKeyAlreadyExists));
                        break;
                    default:
                        ModelState.AddModelError("Message", GlobalResource(GlobalResourceUser.Unknown));
                        break;
                }
            }

            return View(model);
        }
예제 #3
0
        // GET: Right/Create
        public ActionResult Create()
        {
            ViewBag.LastNameUser = lastName;
            var model = new RightViewModel();

            return(View(model));
        }
예제 #4
0
        public ActionResult ReadRolesToRight([DataSourceRequest] DataSourceRequest request)
        {
            var rolesToRights = new List <RightViewModel>();
            var rights        = Manager.Rights();
            var roles         = Manager.Roles();

            foreach (var right in rights)
            {
                var rightViewModel = new RightViewModel
                {
                    Id               = right.Id,
                    RightName        = right.RightName,
                    RightDescription = right.RightDescription,
                    Roles            = new List <RoleViewModel>()
                };
                var rightRoles = Manager.RolesForRight(right);
                foreach (var rightRole in rightRoles)
                {
                    var role = roles.First(r => r.Name == rightRole);
                    rightViewModel.Roles.Add(new RoleViewModel
                    {
                        Id   = role.Id,
                        Name = role.Name
                    });
                }
                rolesToRights.Add(rightViewModel);
            }

            return(JsonDataSourceResult(request, rolesToRights.AsEnumerable()));
        }
예제 #5
0
        public SwitcherViewModel(IScreen screen)
        {
            this.Log(false);

            HostScreen = screen;

            LeftViewModel  = new LeftViewModel(screen);
            RightViewModel = new RightViewModel(screen);
        }
예제 #6
0
        public ActionResult Save(RightViewModel rightViewModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    //add
                    if (rightViewModel.RightId == 0 && rightViewModel.ActionName == "Add")
                    {
                        var model = new TblRight()
                        {
                            RightId       = rightViewModel.RightId,
                            RightName     = rightViewModel.RightName,
                            RightTitle    = rightViewModel.RightTitle,
                            Description   = rightViewModel.Description,
                            ApplicationId = rightViewModel.ApplicationId,
                            ModuleId      = rightViewModel.ModuleId
                        };

                        _rightRepository.Insert(model);
                    }
                    else if (rightViewModel.ActionName == "Edit") //edit
                    {
                        TblRight right = _rightRepository.GetById(rightViewModel.RightId);

                        if (right != null)
                        {
                            right.RightId     = rightViewModel.RightId;
                            right.RightName   = rightViewModel.RightName;
                            right.RightTitle  = rightViewModel.RightTitle;
                            right.Description = rightViewModel.Description;

                            right.ApplicationId = rightViewModel.ApplicationId;
                            right.ModuleId      = rightViewModel.ModuleId;

                            _rightRepository.Update(right);
                        }
                        else
                        {
                            return(Content(KendoUiHelper.GetKendoUiWindowAjaxSuccessMethod(Boolean.FalseString, rightViewModel.ActionName, MessageType.warning.ToString(), ExceptionHelper.ExceptionMessageForNullObject())));
                        }
                    }

                    _rightRepository.Save();

                    return(Content(KendoUiHelper.GetKendoUiWindowAjaxSuccessMethod(Boolean.TrueString, rightViewModel.ActionName, MessageType.success.ToString(), "Saved Successfully.")));
                }

                return(Content(KendoUiHelper.GetKendoUiWindowAjaxSuccessMethod(Boolean.FalseString, rightViewModel.ActionName, MessageType.warning.ToString(), ExceptionHelper.ModelStateErrorFormat(ModelState))));
            }
            catch (Exception ex)
            {
                return(Content(KendoUiHelper.GetKendoUiWindowAjaxSuccessMethod(Boolean.FalseString, rightViewModel.ActionName, MessageType.warning.ToString(), ExceptionHelper.ExceptionMessageFormat(ex))));
            }
        }
예제 #7
0
 public ActionResult Delete(int id, RightViewModel model)
 {
     ViewBag.LastNameUser = lastName;
     try
     {
         rightManager.DeleteRight(id);
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View(model));
     }
 }
예제 #8
0
 public ActionResult Edit(int id, RightViewModel model)
 {
     ViewBag.LastNameUser = lastName;
     try
     {
         var right = Mapper.Map <RightViewModel, Right>(model);
         rightManager.StoreRight(right);
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View(model));
     }
 }
예제 #9
0
        //
        // GET: /Right/Add

        public ActionResult Add()
        {
            var applicationList = SelectListItemExtension.PopulateDropdownList(_applicationRepository.GetAll().ToList <TblApplication>(), "ApplicationId", "ApplicationName").ToList();

            var moduleList = SelectListItemExtension.PopulateDropdownList(_moduleRepository.GetAll().ToList <TblModule>(), "ModuleId", "ModuleTitle").ToList();

            var viewModel = new RightViewModel()
            {
                RightId = 0, ddlApplications = applicationList, ddlModules = moduleList
            };

            //return View();
            return(PartialView("_AddOrEdit", viewModel));
        }
예제 #10
0
        // return a fully populated view model
        private RightViewModel GetViewModel(int id, List <IModelError> errors)
        {
            var rtn = new RightViewModel();

            rtn.Load(service.Get(id, errors));

            var rolerightModel = service.GetSingleRightByRoleForRoleRight(id);

            if (rolerightModel != null)
            {
                rtn.RoleRightId = rolerightModel.Id;
            }

            return(rtn);
        }
예제 #11
0
        //
        // GET: /Right/Edit/By ID

        public ActionResult Edit(int id)
        {
            var errorViewModel = new ErrorViewModel();

            try
            {
                //var right = _rightRepository.GetById(id);
                var right = _rightRepository.GetAll().SingleOrDefault(x => x.RightId == id);
                if (right != null)
                {
                    var moduleList = SelectListItemExtension.PopulateDropdownList(_moduleRepository.GetAll().ToList <TblModule>(), "ModuleId", "ModuleName", isEdit: true, selectedValue: right.ModuleId.ToString()).ToList();

                    var applicationList = SelectListItemExtension.PopulateDropdownList(_applicationRepository.GetAll().ToList <TblApplication>(), "ApplicationId", "ApplicationName", isEdit: true, selectedValue: right.ApplicationId.ToString()).ToList();


                    var singleOrDefaultApplication = _applicationRepository.GetAll().SingleOrDefault(x => x.ApplicationId == right.ApplicationId);

                    var singleOrDefaultModule = _moduleRepository.GetAll().SingleOrDefault(x => x.ModuleId == right.ModuleId);

                    if (singleOrDefaultApplication != null && singleOrDefaultModule != null)
                    {
                        var viewModel = new RightViewModel()
                        {
                            RightId         = right.RightId,
                            RightName       = right.RightName,
                            RightTitle      = right.RightTitle,
                            Description     = right.Description,
                            ApplicationId   = Convert.ToInt32(right.ApplicationId),
                            ApplicationName = singleOrDefaultApplication != null ? singleOrDefaultApplication.ApplicationName : null,
                            ddlApplications = applicationList,
                            ModuleId        = Convert.ToInt32(right.ModuleId),
                            ModuleName      = singleOrDefaultModule != null ? singleOrDefaultModule.ModuleName : null,
                            ddlModules      = moduleList
                        };
                        return(PartialView("_AddOrEdit", viewModel));
                    }
                }

                errorViewModel = ExceptionHelper.ExceptionErrorMessageForNullObject();
            }
            catch (Exception ex)
            {
                errorViewModel = ExceptionHelper.ExceptionErrorMessageFormat(ex);
            }

            return(PartialView("_ErrorPopup", errorViewModel));
        }
예제 #12
0
        public ActionResult Create(RightViewModel model)
        {
            var errors = new List <IModelError>();

            service.TrySave(model, errors);
            if (errors.Any())
            {
                this.AddModelErrors(errors);
                ViewBag.Readonly   = false;
                ViewBag.ButtonFlag = "S"; // Submit
                ViewBag.Title      = "New Right";
                return(View("Form", model));
            }
            else
            {
                return(RedirectToAction("index", new { creaated = model.Id }));
            }
        }
예제 #13
0
 public MainViewModel()
 {
     Caption        = "MainViewModel";
     RightViewModel = new RightViewModel()
     {
         Caption = "RightViewModel"
     };
     ((ISupportParentViewModel)RightViewModel).ParentViewModel = this;
     LeftViewModel = new LeftViewModel()
     {
         Caption = "LeftViewModel"
     };
     ((ISupportParentViewModel)LeftViewModel).ParentViewModel = this;
     SplashScreenViewModel = new SplashScreenViewModel()
     {
         Caption = "SplashScreenViewModel"
     };
     ((ISupportParentViewModel)SplashScreenViewModel).ParentViewModel = this;
 }
예제 #14
0
        public ActionResult Create(RightViewModel model, HttpPostedFileBase file)
        {
            ViewBag.LastNameUser = lastName;
            string archivo      = (DateTime.Now.ToString("yyyyMMddHHmmss") + "-" + file.FileName).ToLower();
            string pathPlusFile = string.Format("~/Uploads/" + archivo);

            file.SaveAs(Server.MapPath(pathPlusFile));
            model.FilePdf = archivo;

            try
            {
                var right = Mapper.Map <RightViewModel, Right>(model);
                rightManager.StoreRight(right);
                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
예제 #15
0
        public ActionResult Delete(RightViewModel model, int _post)
        {
            var errors = new List <IModelError>();
            var result = service.TryDelete(model.Id, errors);

            ViewBag.Title = "Delete Right";
            if (errors.Any())
            {
                model = GetViewModel(model.Id, errors);
                this.AddModelErrors(errors);
                ViewBag.Readonly   = false;
                ViewBag.ButtonFlag = "S"; // Submit
                ViewBag.Title      = "Delete Right";
                return(View("Form", model));
            }
            else
            {
                return(RedirectToAction("index", new { deleted = model.Id }));
            }
        }
예제 #16
0
        public async Task <IActionResult> Data(RightViewModel viewModel)
        {
            #region Login Information
            LoginInit(Constants.Rights.System, (int)ERights.Add);
            if (!(bool)ViewData[Constants.ActionViews.IsLogin])
            {
                await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);

                return(RedirectToAction(Constants.ActionViews.Login, Constants.Controllers.Account));
            }
            var  loginId = User.Identity.Name;
            var  loginE  = dbContext.Employees.Find(m => m.Id.Equals(loginId)).FirstOrDefault();
            bool isRight = (bool)ViewData[Constants.ActionViews.IsRight];
            if (!isRight)
            {
                return(RedirectToAction("Index", "Home"));
            }
            #endregion

            var entity = viewModel.Right;

            if (string.IsNullOrEmpty(entity.Id))
            {
                dbContext.Rights.InsertOne(entity);
            }
            else
            {
                var builder = Builders <Right> .Filter;
                var filter  = builder.Eq(m => m.Id, entity.Id);
                var update  = Builders <Right> .Update
                              .Set(m => m.RoleId, entity.RoleId)
                              .Set(m => m.ObjectId, entity.ObjectId)
                              .Set(m => m.Action, entity.Action)
                              .Set(m => m.Type, entity.Type)
                              .Set(m => m.Enable, entity.Enable);

                dbContext.Rights.UpdateOne(filter, update);
            }

            return(Redirect("/" + Constants.Link.Right));
        }
예제 #17
0
        public async Task <IActionResult> Data(string id)
        {
            #region Login Information
            LoginInit(Constants.Rights.System, (int)ERights.Add);
            if (!(bool)ViewData[Constants.ActionViews.IsLogin])
            {
                await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);

                return(RedirectToAction(Constants.ActionViews.Login, Constants.Controllers.Account));
            }
            var  loginId = User.Identity.Name;
            var  loginE  = dbContext.Employees.Find(m => m.Id.Equals(loginId)).FirstOrDefault();
            bool isRight = (bool)ViewData[Constants.ActionViews.IsRight];
            if (!isRight)
            {
                return(RedirectToAction("Index", "Home"));
            }
            #endregion

            #region DLL
            var categories = dbContext.Categories.Find(m => m.Enable.Equals(true) && m.Type.Equals((int)ECategory.Role)).SortBy(m => m.Name).ToList();
            #endregion

            var entity = new Right();

            if (!string.IsNullOrEmpty(id))
            {
                entity = dbContext.Rights.Find(m => m.Id.Equals(id)).FirstOrDefault();
                if (entity == null)
                {
                    entity = new Right();
                }
            }

            var viewModel = new RightViewModel()
            {
                Right      = entity,
                Categories = categories
            };
            return(View(viewModel));
        }
예제 #18
0
 public ShellViewModel(LeftViewModel left, RightViewModel right) {
     Left = left;
     Right = right;
 }
예제 #19
0
        public async Task <IActionResult> Index(string role, string ob, int Trang, int Dong, string SapXep, string ThuTu)
        {
            var linkCurrent = string.Empty;

            #region Login Information
            LoginInit(Constants.Rights.System, (int)ERights.View);
            if (!(bool)ViewData[Constants.ActionViews.IsLogin])
            {
                await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);

                return(RedirectToAction(Constants.ActionViews.Login, Constants.Controllers.Account));
            }
            var  loginId = User.Identity.Name;
            var  loginE  = dbContext.Employees.Find(m => m.Id.Equals(loginId)).FirstOrDefault();
            bool isRight = (bool)ViewData[Constants.ActionViews.IsRight];
            if (!isRight)
            {
                return(RedirectToAction("Index", "Home"));
            }
            #endregion

            #region DLL
            var categories = dbContext.Categories.Find(m => m.Enable.Equals(true) && m.Type.Equals((int)ECategory.Role)).SortBy(m => m.Name).ToList();
            #endregion

            #region Filter
            var builder = Builders <Right> .Filter;
            var filter  = builder.Eq(m => m.Enable, true);

            if (!string.IsNullOrEmpty(role))
            {
                filter &= builder.Eq(x => x.RoleId, role);
            }
            if (!string.IsNullOrEmpty(ob))
            {
                filter &= builder.Eq(x => x.ObjectId, ob);
            }
            #endregion

            #region Sort
            var sortBuilder = Builders <Right> .Sort.Ascending(m => m.ModifiedOn);

            SapXep = string.IsNullOrEmpty(SapXep) ? "code" : SapXep;
            ThuTu  = string.IsNullOrEmpty(ThuTu) ? "asc" : ThuTu;
            switch (SapXep)
            {
            case "ob":
                sortBuilder = ThuTu == "asc" ? Builders <Right> .Sort.Ascending(m => m.ObjectId) : Builders <Right> .Sort.Descending(m => m.ObjectId);

                break;

            default:
                sortBuilder = ThuTu == "asc" ? Builders <Right> .Sort.Ascending(m => m.ModifiedOn) : Builders <Right> .Sort.Descending(m => m.ModifiedOn);

                break;
            }
            #endregion

            Trang = Trang == 0 ? 1 : Trang;
            int PageSize  = Dong;
            int PageTotal = 1;
            var Records   = dbContext.Rights.CountDocuments(filter);
            if (Records > 0 && Records > PageSize)
            {
                PageTotal = (int)Math.Ceiling((double)Records / (double)PageSize);
                if (Trang > PageTotal)
                {
                    Trang = 1;
                }
            }

            var list = dbContext.Rights.Find(filter).Sort(sortBuilder).Skip((Trang - 1) * PageSize).Limit(PageSize).ToList();

            var displays = new List <RightDisplay>();
            foreach (var item in list)
            {
                var roleName = string.Empty;
                var obName   = string.Empty;
                if (!string.IsNullOrEmpty(item.RoleId))
                {
                    roleName = dbContext.Categories.Find(m => m.Id.Equals(item.RoleId)).FirstOrDefault().Name;
                }
                if (!string.IsNullOrEmpty(item.ObjectId))
                {
                    switch (item.Type)
                    {
                    case (int)ERightType.User:
                        obName = dbContext.Employees.Find(m => m.Id.Equals(item.ObjectId)).FirstOrDefault().FullName;
                        break;

                    default:
                        obName = dbContext.Categories.Find(m => m.Id.Equals(item.ObjectId)).FirstOrDefault().Name;
                        break;
                    }
                }
                displays.Add(new RightDisplay()
                {
                    Right = item, Role = roleName, Object = obName
                });
            }

            var viewModel = new RightViewModel
            {
                Rights        = list,
                RightsDisplay = displays,
                Categories    = categories,
                Ob            = ob,
                Role          = role,
                LinkCurrent   = linkCurrent,
                ThuTu         = ThuTu,
                SapXep        = SapXep,
                Records       = (int)Records,
                PageSize      = PageSize,
                PageTotal     = PageTotal,
                PageCurrent   = Trang
            };
            return(View(viewModel));
        }
예제 #20
0
        public ActionResult UpdateRolesToRight([DataSourceRequest] DataSourceRequest request, RightViewModel viewModel)
        {
            var currentRolesForRight = Manager.RolesForRight(viewModel);
            var toAddRoles           = new List <string>();
            var toRemoveRoles        = new List <string>();

            foreach (var role in viewModel.Roles)
            {
                if (!currentRolesForRight.Contains(role.Name))
                {
                    toAddRoles.Add(role.Name);
                }
            }

            foreach (var role in currentRolesForRight)
            {
                if (viewModel.Roles.All(r => r.Name != role))
                {
                    toRemoveRoles.Add(role);
                }
            }

            foreach (var role in toRemoveRoles)
            {
                Manager.RemoveRoleFromRight(viewModel.Id, role);
            }
            foreach (var role in toAddRoles)
            {
                Manager.AddRoleToRight(viewModel.Id, role);
            }

            return(JsonDataSourceResult(request, viewModel));
        }
예제 #21
0
 public ActionResult UpdateRight([DataSourceRequest] DataSourceRequest request, RightViewModel viewModel)
 {
     Manager.EditRight(viewModel);
     return(JsonDataSourceResult(request, ModelState, viewModel));
 }
예제 #22
0
 public ActionResult DestroyRight([DataSourceRequest] DataSourceRequest request, RightViewModel viewModel)
 {
     Manager.RemoveRight(viewModel);
     return(JsonDataSourceResult(request, ModelState, viewModel));
 }