Ejemplo n.º 1
0
        public static WorkgroupAccountModel Create(IRepository repository, Workgroup workgroup, WorkgroupAccount workgroupAccount = null)
        {
            Check.Require(repository != null, "repo null");
            Check.Require(workgroup != null, "workgroup null");

            var viewModel = new WorkgroupAccountModel { Workgroup = workgroup, WorkgroupAccount = workgroupAccount ?? new WorkgroupAccount()};

            viewModel.WorkGroupPermissions = repository.OfType<WorkgroupPermission>().Queryable.Where(a => a.Workgroup == workgroup && (!a.IsAdmin || (a.IsAdmin && a.IsFullFeatured))).ToList();
            viewModel.Accounts = workgroup.Organizations.SelectMany(x => x.Accounts).Distinct().ToList();

            viewModel.Approvers = viewModel.WorkGroupPermissions.Where(x => x.Role.Id == Role.Codes.Approver).Select(x => x.User).Distinct().ToList();
            viewModel.AccountManagers = viewModel.WorkGroupPermissions.Where(x => x.Role.Id == Role.Codes.AccountManager).Select(x => x.User).Distinct().ToList();
            viewModel.Purchasers = viewModel.WorkGroupPermissions.Where(x => x.Role.Id == Role.Codes.Purchaser).Select(x => x.User).Distinct().ToList();

            if (viewModel.WorkgroupAccount.Approver == null)
            {
                var approver = repository.OfType<WorkgroupPermission>().Queryable.SingleOrDefault(
                        a =>
                        a.Workgroup == workgroup && a.Role.Id == Role.Codes.Approver && !a.IsAdmin &&
                        a.IsDefaultForAccount);
                if (approver != null)
                {
                    viewModel.WorkgroupAccount.Approver = approver.User;
                }
            }

            if (viewModel.WorkgroupAccount.AccountManager == null)
            {
                var approver = repository.OfType<WorkgroupPermission>().Queryable.SingleOrDefault(
                        a =>
                        a.Workgroup == workgroup && a.Role.Id == Role.Codes.AccountManager && !a.IsAdmin &&
                        a.IsDefaultForAccount);
                if (approver != null)
                {
                    viewModel.WorkgroupAccount.AccountManager = approver.User;
                }
            }

            if (viewModel.WorkgroupAccount.Purchaser == null)
            {
                var approver = repository.OfType<WorkgroupPermission>().Queryable.SingleOrDefault(
                        a =>
                        a.Workgroup == workgroup && a.Role.Id == Role.Codes.Purchaser && !a.IsAdmin &&
                        a.IsDefaultForAccount);
                if (approver != null)
                {
                    viewModel.WorkgroupAccount.Purchaser = approver.User;
                }
            }

            return viewModel;
        }
Ejemplo n.º 2
0
        public static WorkgroupAccount WorkgroupAccount(int?counter, bool noNews = false)
        {
            var rtValue = new WorkgroupAccount();

            if (!noNews)
            {
                rtValue.AccountManager = new User();
                rtValue.Approver       = new User();
                rtValue.Purchaser      = new User();
            }
            rtValue.Account   = new Account();
            rtValue.Workgroup = new Workgroup();

            return(rtValue);
        }
Ejemplo n.º 3
0
        public static WorkgroupAccount WorkgroupAccount(int? counter, bool noNews = false)
        {
            var rtValue = new WorkgroupAccount();
            if(!noNews)
            {
                rtValue.AccountManager = new User();
                rtValue.Approver = new User();
                rtValue.Purchaser = new User();
            }
            rtValue.Account = new Account();
            rtValue.Workgroup = new Workgroup();

            return rtValue;
        }
        public static WorkgroupAccountModel Create(IRepository repository, Workgroup workgroup, WorkgroupAccount workgroupAccount = null)
        {
            Check.Require(repository != null, "repo null");
            Check.Require(workgroup != null, "workgroup null");

            var viewModel = new WorkgroupAccountModel {
                Workgroup = workgroup, WorkgroupAccount = workgroupAccount ?? new WorkgroupAccount()
            };

            viewModel.WorkGroupPermissions = repository.OfType <WorkgroupPermission>().Queryable.Where(a => a.Workgroup == workgroup && (!a.IsAdmin || (a.IsAdmin && a.IsFullFeatured))).ToList();
            viewModel.Accounts             = workgroup.Organizations.SelectMany(x => x.Accounts).Distinct().ToList();

            viewModel.Approvers       = viewModel.WorkGroupPermissions.Where(x => x.Role.Id == Role.Codes.Approver).Select(x => x.User).Distinct().ToList();
            viewModel.AccountManagers = viewModel.WorkGroupPermissions.Where(x => x.Role.Id == Role.Codes.AccountManager).Select(x => x.User).Distinct().ToList();
            viewModel.Purchasers      = viewModel.WorkGroupPermissions.Where(x => x.Role.Id == Role.Codes.Purchaser).Select(x => x.User).Distinct().ToList();

            if (viewModel.WorkgroupAccount.Approver == null)
            {
                var approver = repository.OfType <WorkgroupPermission>().Queryable.SingleOrDefault(
                    a =>
                    a.Workgroup == workgroup && a.Role.Id == Role.Codes.Approver && !a.IsAdmin &&
                    a.IsDefaultForAccount);
                if (approver != null)
                {
                    viewModel.WorkgroupAccount.Approver = approver.User;
                }
            }

            if (viewModel.WorkgroupAccount.AccountManager == null)
            {
                var approver = repository.OfType <WorkgroupPermission>().Queryable.SingleOrDefault(
                    a =>
                    a.Workgroup == workgroup && a.Role.Id == Role.Codes.AccountManager && !a.IsAdmin &&
                    a.IsDefaultForAccount);
                if (approver != null)
                {
                    viewModel.WorkgroupAccount.AccountManager = approver.User;
                }
            }

            if (viewModel.WorkgroupAccount.Purchaser == null)
            {
                var approver = repository.OfType <WorkgroupPermission>().Queryable.SingleOrDefault(
                    a =>
                    a.Workgroup == workgroup && a.Role.Id == Role.Codes.Purchaser && !a.IsAdmin &&
                    a.IsDefaultForAccount);
                if (approver != null)
                {
                    viewModel.WorkgroupAccount.Purchaser = approver.User;
                }
            }

            return(viewModel);
        }
Ejemplo n.º 5
0
        /*
         * Dev Data
         */
        private static void InsertData(ISession session)
        {
            //Now insert new data
            var scott = new User("postit") { FirstName = "Scott", LastName = "Kirkland", Email = "*****@*****.**", IsActive = true };
            var approverUser = new User("approver") { FirstName = "Approver", LastName = "Approver", Email = "*****@*****.**", IsActive = true };
            var acctMgrUser = new User("acctmgr") { FirstName = "Account", LastName = "Manager", Email = "*****@*****.**", IsActive = true };
            var alan = new User("anlai") { FirstName = "Alan", LastName = "Lai", Email = "*****@*****.**", IsActive = true };
            var ken = new User("taylorkj") { FirstName = "Ken", LastName = "Taylor", Email = "*****@*****.**", IsActive = true };
            var chris = new User("cthielen") { FirstName = "Christopher", LastName = "Thielen", Email = "*****@*****.**", IsActive = true };
            var scottd = new User("sadyer") { FirstName = "Scott", LastName = "Dyer", Email = "*****@*****.**", IsActive = true };
            var jscub = new User("jscub")
                            {
                                FirstName = "James",
                                LastName = "Cubbage",
                                Email = "*****@*****.**",
                                IsActive = true
                            };
            var jsylvest = new User("jsylvest")
            {
                FirstName = "Jason",
                LastName = "Sylvestre",
                Email = "*****@*****.**",
                IsActive = true
            };

            var admin = session.Load<Role>("AD");
            var deptAdmin = session.Load<Role>("DA");
            var user = session.Load<Role>("RQ");
            var approver = session.Load<Role>("AP");
            var acctMgr = session.Load<Role>("AM");
            var purchaser = session.Load<Role>("PR");

            scott.Organizations.Add(session.Load<Organization>("AANS"));
            scott.Organizations.Add(session.Load<Organization>("AAES"));
            ken.Organizations.Add(session.Load<Organization>("AANS"));
            ken.Organizations.Add(session.Load<Organization>("ABAE"));
            scottd.Organizations.Add(session.Load<Organization>("AANS"));
            scottd.Organizations.Add(session.Load<Organization>("AAES"));
            scottd.Organizations.Add(session.Load<Organization>("AFST"));
            chris.Organizations.Add(session.Load<Organization>("AANS"));
            chris.Organizations.Add(session.Load<Organization>("AAES"));
            chris.Organizations.Add(session.Load<Organization>("AFST"));
            jscub.Organizations.Add(session.Load<Organization>("AFST"));
            jscub.Organizations.Add(session.Load<Organization>("AAES"));
            jsylvest.Organizations.Add(session.Load<Organization>("AFST"));
            jsylvest.Organizations.Add(session.Load<Organization>("AAES"));
            alan.Organizations.Add(session.Load<Organization>("AANS"));
            alan.Organizations.Add(session.Load<Organization>("AAES"));

            var testWorkgroup = new Workgroup() { Name = "Test Workgroup", IsActive = true, };
            var workGroupAccount = new WorkgroupAccount() { };
            workGroupAccount.Account = session.Load<Account>("3-6851000");
            testWorkgroup.AddAccount(workGroupAccount);
            var workgroupAccountWithUsers = new WorkgroupAccount
                                                {
                                                    Account = session.Load<Account>("3-APSO013"),
                                                    Approver = approverUser,
                                                    AccountManager = acctMgrUser
                                                };
            testWorkgroup.AddAccount(workgroupAccountWithUsers);

            testWorkgroup.PrimaryOrganization = session.Load<Organization>("AAES");
            testWorkgroup.Organizations.Add(session.Load<Organization>("AAES"));
            testWorkgroup.Organizations.Add(session.Load<Organization>("APLS"));

            // Add a vendor to the test workgroup
            var testWorkgroupVendor = new WorkgroupVendor
            {
                Name = "Office Max Corp.",
                City = "Sacramento",
                CountryCode = "US",
                Line1 = "3 1/2 External Drive",// (get it?)
                State = "CA",
                Zip = "95616"
            };

            var testWorkgroupVendor2 = new WorkgroupVendor
                                          {
                                              Name = "Manually Added Vendor Corp.",
                                              City = "Sacramento",
                                              CountryCode = "US",
                                              Line1 = "5 1/4 External Drive",// (get it?)
                                              State = "CA",
                                              Zip = "95816"
                                          };

            testWorkgroup.AddVendor(testWorkgroupVendor);
            testWorkgroup.AddVendor(testWorkgroupVendor2);

            var testWorkgroupAddress = new WorkgroupAddress()
                                           {
                                               Name = "The Office",
                                               Address = "One Shields Ave",
                                               Building = "Mrak",
                                               City = "Davis",
                                               State = "CA",
                                               Zip = "95616",
                                               IsActive = true
                                           };

            testWorkgroup.AddAddress(testWorkgroupAddress);

            var workgroupPerm = new WorkgroupPermission() { User = scott, Role = deptAdmin, Workgroup = testWorkgroup };
            var workgroupPerm2 = new WorkgroupPermission() { User = jsylvest, Role = deptAdmin, Workgroup = testWorkgroup };
            var workgroupPerm3 = new WorkgroupPermission() { User = jsylvest, Role = user, Workgroup = testWorkgroup };
            var workgroupPerm4 = new WorkgroupPermission() { User = jscub, Role = deptAdmin, Workgroup = testWorkgroup };
            var workgroupPerm5 = new WorkgroupPermission() { User = alan, Role = deptAdmin, Workgroup = testWorkgroup };
            var workgroupPerm6 = new WorkgroupPermission() { User = chris, Role = acctMgr, Workgroup = testWorkgroup };
            var workgroupPerm7 = new WorkgroupPermission() { User = scott, Role = approver, Workgroup = testWorkgroup };
            var workgroupPerm8 = new WorkgroupPermission() { User = alan, Role = approver, Workgroup = testWorkgroup };

            var shippingType = session.Load<ShippingType>("ST");
            var orderType = session.Load<Role>("OR");

            var autoApproval = new AutoApproval //Approve anything scott sends to alan under $1000 for the next 2 years
                                   {
                                       TargetUser = scott,
                                       User = alan,
                                       IsActive = true,
                                       Expiration = DateTime.Now.AddYears(2),
                                       LessThan = true,
                                       MaxAmount = 1000.00M
                                   };

            var autoApprovalAccount = new AutoApproval //Approve anything from account 3-APSO013 associated with approverUser under $1000 for 2 years
            {
                Account = session.Load<Account>("3-APSO013"),
                User = approverUser,
                IsActive = true,
                Expiration = DateTime.Now.AddYears(2),
                LessThan = true,
                MaxAmount = 1000.00M
            };

            session.Save(testWorkgroup);

            session.Save(scott);
            session.Save(alan);
            session.Save(ken);
            session.Save(jscub);
            session.Save(chris);
            session.Save(scottd);
            session.Save(jsylvest);

            session.Save(approverUser);
            session.Save(acctMgrUser);

            session.Save(workgroupPerm);
            session.Save(workgroupPerm2);
            session.Save(workgroupPerm3);
            session.Save(workgroupPerm4);
            session.Save(workgroupPerm5);
            session.Save(workgroupPerm6);
            session.Save(workgroupPerm7);
            session.Save(workgroupPerm8);

            session.Save(autoApproval);
            session.Save(autoApprovalAccount);

            Roles.AddUsersToRole(new[] { "postit", "anlai", "cthielen" }, "AD");
            Roles.AddUserToRole("anlai", "RQ");
            Roles.AddUserToRole("anlai", "DA");
            Roles.AddUserToRole("anlai", "AP");
            Roles.AddUserToRole("taylorkj", "DA");
            Roles.AddUserToRole("postit", "DA");
            Roles.AddUserToRole("jscub", "DA");
            Roles.AddUserToRole("jsylvest", "DA");

            session.Flush(); //Flush out the changes
        }
Ejemplo n.º 6
0
        public ActionResult AddAccounts(int id, WorkgroupAccount workgroupAccount, string account_search)
        {
            ViewBag.StepNumber = 8;
            var workgroup = _workgroupRepository.GetNullableById(id);

            if (workgroup == null)
            {
                Message = "Workgroup not found.";
                this.RedirectToAction <WorkgroupController>(a => a.Index(false));
            }
            if (workgroupAccount != null && workgroupAccount.Account == null)
            {
                workgroupAccount.Account = _repositoryFactory.AccountRepository.GetNullableById(account_search);
            }


            if (workgroupAccount == null || workgroupAccount.Account == null || string.IsNullOrWhiteSpace(workgroupAccount.Account.Id))
            {
                if (workgroupAccount == null)
                {
                    workgroupAccount.Account = new Account();
                }
                ModelState.Clear();
                if (!string.IsNullOrWhiteSpace(account_search))
                {
                    ModelState.AddModelError("WorkgroupAccount.Account", "Account not found.");
                }
                else
                {
                    ModelState.AddModelError("WorkgroupAccount.Account", "Select Account or skip.");
                }
                var viewModel1 = WorkgroupAccountModel.Create(Repository, workgroup, workgroupAccount);
                return(View(viewModel1));
            }

            var workgroupAccountToCreate = new WorkgroupAccount {
                Workgroup = workgroup
            };

            //Mapper.Map(workgroupAccount, workgroupAccountToCreate);//Mapper was causing me an exception JCS
            workgroupAccountToCreate.Account        = workgroupAccount.Account;
            workgroupAccountToCreate.AccountManager = workgroupAccount.AccountManager;
            workgroupAccountToCreate.Approver       = workgroupAccount.Approver;
            workgroupAccountToCreate.Purchaser      = workgroupAccount.Purchaser;

            ModelState.Clear();
            workgroupAccountToCreate.TransferValidationMessagesTo(ModelState);

            if (_workgroupAccountRepository.Queryable.Any(a => a.Workgroup.Id == workgroup.Id && a.Account.Id == workgroupAccountToCreate.Account.Id))
            {
                ModelState.AddModelError("WorkgroupAccount.Account", "Account already exists for this workgroup.");
            }
            if (ModelState.IsValid)
            {
                _workgroupAccountRepository.EnsurePersistent(workgroupAccountToCreate);
                Message = "Workgroup account saved.";
                //return this.RedirectToAction("Accounts", new {id = id});
                return(this.RedirectToAction(a => a.Accounts(id)));
            }

            var viewModel = WorkgroupAccountModel.Create(Repository, workgroup, workgroupAccountToCreate);

            return(View(viewModel));
        }