Example #1
0
        public ActionResult Edit(int id = 0)
        {
            if (!Authorized(RoleType.SystemManager))
            {
                return(Error(Loc.Dic.error_no_permission));
            }

            ApprovalRouteModel model = new ApprovalRouteModel();
            List <User>        usersSelectList;

            using (ApprovalRoutesRepository routesRep = new ApprovalRoutesRepository(CurrentUser.CompanyId))
                using (UsersRepository usersRep = new UsersRepository(CurrentUser.CompanyId))
                {
                    model.ApprovalRoute = routesRep.GetEntity(id, "Users_ApprovalStep.User");
                    if (model.ApprovalRoute == null)
                    {
                        return(Error(Loc.Dic.error_database_error));
                    }

                    usersSelectList =
                        usersRep.GetList()
                        .Where(user => ((RoleType)user.Roles & RoleType.OrdersApprover) == RoleType.OrdersApprover)
                        .ToList();
                }

            ViewBag.UsersSelectList = new SelectList(usersSelectList, "Id", "FullName");
            return(View(model));
        }
Example #2
0
        public ActionResult Create(ApprovalRouteModel model)
        {
            if (!Authorized(RoleType.SystemManager))
            {
                return(Error(Loc.Dic.error_no_permission));
            }

            Users_ApprovalRoutes newApprovalRoute = new Users_ApprovalRoutes();

            newApprovalRoute.Name = model.Name;

            using (ApprovalRoutesRepository routesRep = new ApprovalRoutesRepository(CurrentUser.CompanyId))
                using (UsersRepository usersRep = new UsersRepository(CurrentUser.CompanyId))
                {
                    var         usersIds       = model.Steps.Select(x => x.UserId).Distinct();
                    List <User> routeApprovers = usersRep.GetList().Where(x => usersIds.Contains(x.Id)).ToList();
                    if (usersIds.Count() != routeApprovers.Count)
                    {
                        return(Error(Loc.Dic.error_invalid_form));
                    }

                    foreach (var approver in routeApprovers)
                    {
                        if (!Roles.HasRole(approver.Roles, RoleType.OrdersApprover))
                        {
                            return(Error(Loc.Dic.error_invalid_form));
                        }
                    }

                    foreach (var step in model.Steps)
                    {
                        newApprovalRoute.Users_ApprovalStep.Add(
                            new Users_ApprovalStep()
                        {
                            UserId     = step.UserId,
                            StepNumber = step.StepNumber
                        }
                            );
                    }

                    if (!routesRep.Create(newApprovalRoute))
                    {
                        return(Error(Loc.Dic.error_database_error));
                    }
                }

            return(RedirectToAction("Index"));
        }
Example #3
0
 public ActionResult CreateApprovalRoute(ApprovalRouteModel model)
 {
     return(RedirectToAction("Index"));
 }