Exemplo n.º 1
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");
        }
Exemplo n.º 2
0
 /// <summary>
 /// Create a new Users_ApprovalRoutes object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="name">Initial value of the Name property.</param>
 /// <param name="companyId">Initial value of the CompanyId property.</param>
 public static Users_ApprovalRoutes CreateUsers_ApprovalRoutes(global::System.Int32 id, global::System.String name, global::System.Int32 companyId)
 {
     Users_ApprovalRoutes users_ApprovalRoutes = new Users_ApprovalRoutes();
     users_ApprovalRoutes.Id = id;
     users_ApprovalRoutes.Name = name;
     users_ApprovalRoutes.CompanyId = companyId;
     return users_ApprovalRoutes;
 }
Exemplo n.º 3
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Users_ApprovalRoutes EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToUsers_ApprovalRoutes(Users_ApprovalRoutes users_ApprovalRoutes)
 {
     base.AddObject("Users_ApprovalRoutes", users_ApprovalRoutes);
 }
Exemplo n.º 4
0
 public ActionResult PartialDetails(Users_ApprovalRoutes route)
 {
     return PartialView(route);
 }