示例#1
0
        public ActionResult RoleSetup(RoleSetupViewModel model, ServiceResult msgresult)
        {
            var uService = new UserService();
            var prole    = uService.ValidatePageRole(User.Identity.GetUserId(), Page_Code.P0000);

            if (prole == null)
            {
                return(RedirectToAction("ErrorPage", "Account", new ErrorViewModel()
                {
                    Message = Resource.Message_Access_Denied
                }));
            }
            if (prole.View == null || prole.View == false)
            {
                return(RedirectToAction("ErrorPage", "Account", new ErrorViewModel()
                {
                    Message = Resource.Message_Access_Denied
                }));
            }

            ModelState.Clear();
            if (model.operation == Operation.D)
            {
                return(RoleSetup(model));
            }

            model.result = msgresult;
            model.Modify = prole.Modify;
            model.View   = prole.View;

            var cbService = new ComboService();
            var rService  = new RoleService();

            model.cPageList = cbService.LstPage();
            model.cRoleList = cbService.LstRole(true);

            var rcri = new RoleCriteria();

            rcri.Role_ID = model.sRole_ID;
            var result = rService.GetPageRole(rcri);

            if (result.Code == ReturnCode.SUCCESS)
            {
                model.PageRoleList = result.Object as List <Page_Role>;
            }

            return(View(model));
        }
示例#2
0
        public ActionResult RoleSetup(RoleSetupViewModel model)
        {
            var rService = new RoleService();

            if (model.tabAction == "pagerole")
            {
                if (model.Role_ID.HasValue && model.Page_ID.HasValue)
                {
                    var cri = new RoleCriteria();
                    cri.Role_ID = model.Role_ID;
                    cri.Page_ID = model.Page_ID;
                    var result = rService.GetPageRole(cri);
                    if (result.Code == ReturnCode.SUCCESS)
                    {
                        var dup  = new Page_Role();
                        var dups = result.Object as List <Page_Role>;
                        if (dups != null && dups.Count() != 0)
                        {
                            if (model.operation == Operation.C)
                            {
                                ModelState.AddModelError("Page_ID", Resource.The + " " + Resource.Page + " " + Resource.Field + " " + Resource.Is_Duplicated);
                            }
                            else if (model.operation == Operation.U)
                            {
                                dup = dups.FirstOrDefault();
                                if (dup.Page_Role_ID != model.Page_Role_ID)
                                {
                                    ModelState.AddModelError("Page_ID", Resource.The + " " + Resource.Page + " " + Resource.Field + " " + Resource.Is_Duplicated);
                                }
                            }
                        }
                    }
                }

                if (ModelState.IsValid)
                {
                    var prole = new Page_Role();
                    if (model.operation == Operation.U || model.operation == Operation.D)
                    {
                        var cri = new RoleCriteria();
                        cri.Page_Role_ID = model.Page_Role_ID;
                        var result = rService.GetPageRole(cri);
                        if (result.Code == ReturnCode.SUCCESS)
                        {
                            var proles = result.Object as List <Page_Role>;
                            if (proles != null && proles.Count() == 1)
                            {
                                prole = proles.FirstOrDefault();
                            }
                        }
                    }

                    if (model.operation != Operation.D)
                    {
                        prole.Role_ID = model.Role_ID;
                        prole.Page_ID = model.Page_ID;
                        prole.Modify  = (model.Modify.HasValue && model.Modify.Value ? true : false);
                        prole.View    = (model.View.HasValue && model.View.Value ? true : false);
                        prole.Close   = (model.Close.HasValue && model.Close.Value ? true : false);

                        if (prole.Modify.HasValue && prole.Modify.Value)
                        {
                            prole.View = true;
                        }

                        if (prole.Page_ID == 9 && prole.Role_ID == 5)
                        {
                            prole.View   = true;
                            prole.Modify = true;
                        }
                    }

                    if (model.operation == Operation.C)
                    {
                        model.result = rService.InsertPageRole(prole);
                    }

                    else if (model.operation == Operation.U)
                    {
                        model.result = rService.UpdatePageRole(prole);
                    }

                    else if (model.operation == Operation.D)
                    {
                        prole.Record_Status = Record_Status.Delete;
                        model.result        = rService.UpdatePageRole(prole);
                        if (model.result.Code == ReturnCode.SUCCESS)
                        {
                            model.result = new ServiceResult()
                            {
                                Code = ReturnCode.SUCCESS, Msg = Success.GetMessage(ReturnCode.SUCCESS_DELETE), Field = Resource.Page_Role
                            }
                        }
                        ;
                        else
                        {
                            model.result = new ServiceResult()
                            {
                                Code = ReturnCode.ERROR_DELETE, Msg = Error.GetMessage(ReturnCode.ERROR_DELETE), Field = Resource.Page_Role
                            }
                        };

                        return(RedirectToAction("RoleSetup", new AppRouteValueDictionary(model)));
                    }

                    if (model.result.Code == ReturnCode.SUCCESS)
                    {
                        return(RedirectToAction("RoleSetup", new AppRouteValueDictionary(model)));
                    }
                }
            }

            var cbService = new ComboService();

            model.cPageList = cbService.LstPage();
            model.cRoleList = cbService.LstRole(true);

            var rcri = new RoleCriteria();

            rcri.Role_ID = model.Role_ID;
            var result2 = rService.GetPageRole(rcri);

            if (result2.Code == ReturnCode.SUCCESS)
            {
                model.PageRoleList = result2.Object as List <Page_Role>;
            }
            return(View(model));
        }
    }
示例#3
0
        public ActionResult Users(UserViewModel model, ServiceResult msgresult)
        {
            var uService = new UserService(User.Identity.GetUserId());
            var prole    = uService.ValidatePageRole(User.Identity.GetUserId(), Page_Code.P0010);

            if (prole == null)
            {
                return(RedirectToAction("ErrorPage", "Account", new ErrorViewModel()
                {
                    Message = Resource.Message_Access_Denied
                }));
            }
            if (prole.View == null || prole.View == false)
            {
                return(RedirectToAction("ErrorPage", "Account", new ErrorViewModel()
                {
                    Message = Resource.Message_Access_Denied
                }));
            }

            ModelState.Clear();
            if (model.operation == Operation.D)
            {
                var dcri = new UserCriteria();
                dcri.Profile_ID = model.Profile_ID;
                var result = uService.GetUser(dcri);
                if (result.Code == ReturnCode.SUCCESS)
                {
                    var users = result.Object as List <User_Profile>;
                    if (users != null && users.Count() == 1)
                    {
                        var user = new User_Profile();
                        user = users.FirstOrDefault();
                        user.Record_Status = Record_Status.Delete;
                        model.result       = uService.UpdateUser(user);
                        if (model.result.Code == ReturnCode.SUCCESS)
                        {
                            msgresult = new ServiceResult()
                            {
                                Code = ReturnCode.SUCCESS, Msg = Success.GetMessage(ReturnCode.SUCCESS_DELETE), Field = Resource.User
                            }
                        }
                        ;
                        else
                        {
                            msgresult = new ServiceResult()
                            {
                                Code = ReturnCode.ERROR_DELETE, Msg = Error.GetMessage(ReturnCode.ERROR_DELETE), Field = Resource.User
                            }
                        };
                    }
                }
            }

            model.result = msgresult; // return result from http post
            model.Modify = prole.Modify;
            model.View   = prole.View;

            var cri     = new UserCriteria();
            var uresult = uService.GetUser(cri);

            if (uresult.Code == ReturnCode.SUCCESS)
            {
                model.Userlist = uresult.Object as List <User_Profile>;
            }

            var cbService = new ComboService();

            model.cRole = cbService.LstRole();

            return(View(model));
        }
示例#4
0
        public async Task <ActionResult> Users(UserViewModel model)
        {
            var uService = new UserService(GetUser());

            if (model.operation != Operation.C)
            {
                List <string> formatTemp = new List <string>();
                formatTemp.AddRange(new string[] { "Password", "Confirm_Password" });

                foreach (var key in ModelState.Keys.ToList().Where(key => ModelState.ContainsKey(key) && (formatTemp.Contains(key))))
                {
                    ModelState[key].Errors.Clear();
                }
            }
            var errs = GetErrorModelState();

            var guser = uService.getUserByEmail(model.Email_Address);

            if (guser != null)
            {
                if (model.operation == Operation.C)
                {
                    ModelState.AddModelError("Email_Address", Resource.The + " " + Resource.Email + " " + Resource.Is_Rrequired);
                }
                else if (model.operation == Operation.U && model.Profile_ID != guser.Profile_ID)
                {
                    ModelState.AddModelError("Email_Address", Resource.The + " " + Resource.Email + " " + Resource.Is_Rrequired);
                }
            }

            if (ModelState.IsValid)
            {
                var user = new User_Profile();
                if (model.operation == Operation.U)
                {
                    var cri = new UserCriteria();
                    cri.Profile_ID = model.Profile_ID;
                    var result = uService.GetUser(cri);
                    if (result.Code == ReturnCode.SUCCESS)
                    {
                        var users = result.Object as List <User_Profile>;
                        if (users != null && users.Count() == 1)
                        {
                            user = users.FirstOrDefault();
                        }
                    }
                }

                user.Email_Address      = model.Email_Address;
                user.Name               = model.Name;
                user.LDAP_Username      = model.LDAP_Username;
                user.Role_ID            = model.Role_ID;
                user.Email_Notification = model.Email_Notification;

                if (model.operation == Operation.C)
                {
                    user.Activated = true;
                    var uService2 = new UserService(user);
                    user.PWD     = model.Password;
                    model.result = uService2.InsertUser(user);
                    if (model.result.Code == ReturnCode.SUCCESS)
                    {
                        UserManager <ApplicationUser> userManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(new AgnosDBContext()));
                        userManager.UserValidator = new UserValidator <ApplicationUser>(userManager)
                        {
                            AllowOnlyAlphanumericUserNames = false
                        };
                        IdentityResult iresult = await userManager.RemovePasswordAsync(user.ApplicationUser_Id);

                        if (iresult.Succeeded)
                        {
                            iresult = await userManager.AddPasswordAsync(user.ApplicationUser_Id, model.Password);

                            if (iresult.Succeeded)
                            {
                            }
                        }
                    }
                }
                else if (model.operation == Operation.U)
                {
                    model.result = uService.UpdateUser(user);
                }

                if (model.result.Code == ReturnCode.SUCCESS)
                {
                    return(RedirectToAction("Users", new AppRouteValueDictionary(model)));
                }
            }

            var cri2    = new UserCriteria();
            var uresult = uService.GetUser(cri2);

            if (uresult.Code == ReturnCode.SUCCESS)
            {
                model.Userlist = uresult.Object as List <User_Profile>;
            }

            var cbService = new ComboService();

            model.cRole = cbService.LstRole();

            var prole = uService.ValidatePageRole(User.Identity.GetUserId(), Page_Code.P0010);

            if (prole != null)
            {
                model.Modify = prole.Modify;
            }

            return(View(model));
        }