예제 #1
0
        public ActionResult CreateBranch(string id)
        {
            int BranchId    = string.IsNullOrEmpty(id.DecryptString()) ? default(int) : Convert.ToInt32(id.DecryptString());
            var branchDto   = new BranchDto();
            var branchModel = new BranchModel();

            if (BranchId > 0)
            {
                branchDto   = _branchService.GetByID(BranchId);
                branchModel = Mapper.Map <BranchDto, BranchModel>(branchDto);
            }

            //List<SelectListDto> employeeSelectListDto = _employeeService.GetEmployeeSelectList();
            //SelectList employeeSelectList = new SelectList(employeeSelectListDto, "ID", "Text", "Select Employee");
            //ViewBag.employeeSelectList = employeeSelectList;

            ViewBag.Result = new ResultDto();
            return(View(branchModel));
        }
예제 #2
0
        public JsonResult ChangeBranch(long branchID)
        {
            if (!SmsCache.UserContext.AllowBranches.Select(x => x.ID).Contains(branchID))
            {
                return(Json(JsonModel.Create(false)));
            }

            var branch = BranchService.GetByID(branchID);

            if (branch.Data == null || !branch.Success)
            {
                return(Json(JsonModel.Create(false)));
            }

            SmsCache.UserContext.CurrentBranchId          = branchID;
            CommonObjects.PreviousSelectedBranch          = branchID;
            SmsCache.UserAccesses.Current.CurrentBranchId = branchID;

            return(Json(JsonModel.Create(true)));
        }
예제 #3
0
        public JsonResult GetBranchName(int id)
        {
            BranchDto BranchDtoDto = _branchService.GetByID(id);

            return(Json(new { BranchName = BranchDtoDto.BranchName }));
        }
예제 #4
0
        public ActionResult Login(LoginModel model)
        {
            if (SmsCache.UserContext != null && SmsCache.UserContext.UserID != 0)
            {
                return(RedirectToAction("Index", "Home"));
            }

            if (ModelState.IsValid)
            {
                var response = UserService.Get <UserDto>(model.Username, model.Password);
                if (!response.Success)
                {
                    var branches = GetBranchList();
                    if (branches == null)
                    {
                        return(ErrorPage(errors));
                    }

                    model.ShowError    = true;
                    model.ErrorMessage = response.Errors[0].ErrorMessage;
                    model.ListBranch   = branches;
                    return(View(model));
                }

                var user = response.Data;
                if (!user.Branches.Select(x => x.ID).Contains(model.SelectedBranch) && !user.IsSystemAdmin)
                {
                    var branches = GetBranchList();
                    if (branches == null)
                    {
                        return(ErrorPage(errors));
                    }

                    model.ShowError    = true;
                    model.ErrorMessage = SmsCache.Message.Get(ConstMessageIds.Login_NoPermissionOnBranch);
                    model.ListBranch   = branches;
                    return(View(model));
                }

                BranchDto branch;
                if (user.IsSystemAdmin || user.UseSystemConfig)
                {
                    branch = BranchService.GetByID(model.SelectedBranch).Data;
                }
                else
                {
                    branch = user.Branches.First(x => x.ID == model.SelectedBranch);
                }

                if (branch == null)
                {
                    var branches = GetBranchList();
                    if (branches == null)
                    {
                        return(ErrorPage(errors));
                    }

                    model.ShowError    = true;
                    model.ErrorMessage = SmsCache.Message.Get(ConstMessageIds.Login_BranchNotAvailable);
                    model.ListBranch   = branches;
                    return(View(model));
                }

                var userConfig = UserConfigService.GetUserConfig(user.ID, branch.ID);
                if (!userConfig.Success || userConfig.Data == null)
                {
                    var branches = GetBranchList();
                    if (branches == null)
                    {
                        return(ErrorPage(errors));
                    }

                    model.ShowError    = true;
                    model.ErrorMessage = SmsCache.Message.Get(ConstMessageIds.Login_CanNotGetUserConfig);
                    model.ListBranch   = branches;
                    return(View(model));
                }

                if (userConfig.Data.IsSuspended)
                {
                    var branches = GetBranchList();
                    if (branches == null)
                    {
                        return(ErrorPage(errors));
                    }

                    model.ShowError    = true;
                    model.ErrorMessage = SmsCache.Message.Get(ConstMessageIds.Login_UserSuspended);
                    model.ListBranch   = branches;
                    return(View(model));
                }

                if (!SetSessionData(user, userConfig.Data, branch.ID))
                {
                    Session.Abandon();
                    return(ErrorPage(errors));
                }

                CommonObjects.PreviousSelectedBranch = branch.ID;

                return(RedirectToAction("Index", "Home"));
            }

            return(View(model));
        }
예제 #5
0
        public ActionResult Edit(int id)
        {
            var post = branchService.GetByID(id);

            return(View(post));
        }