コード例 #1
0
ファイル: OrderController.cs プロジェクト: ucdavis/Purchasing
        public ActionResult AddAddress(int workgroupId, WorkgroupAddress workgroupAddress)
        {
            //TODO: Consider using same logic as workgroup: _workgroupAddressService.CompareAddress
            var workgroup = _repositoryFactory.WorkgroupRepository.GetById(workgroupId);

            Check.Require(_securityService.HasWorkgroupAccess(workgroup));

            workgroup.AddAddress(workgroupAddress);

            _repositoryFactory.WorkgroupRepository.EnsurePersistent(workgroup);

            return Json(new { id = workgroupAddress.Id });
        }
コード例 #2
0
        public static WorkgroupAddress WorkgroupAddress(int? counter)
        {
            var rtValue = new WorkgroupAddress();
            rtValue.Workgroup = new Workgroup();
            rtValue.Name = "Name" + counter.Extra();
            rtValue.Building = "Building" + counter.Extra();
            rtValue.Room = "Room" + counter.Extra();
            rtValue.Address = "Address" + counter.Extra();
            rtValue.City = "City" + counter.Extra();
            rtValue.State = "CA";
            rtValue.Zip = "95616";
            rtValue.Phone = "(530) 555-5555";

            return rtValue;
        }
コード例 #3
0
ファイル: DbHelper.cs プロジェクト: ucdavis/Purchasing
        /*
         * Demo Data
         */
        private static void InsertDemoData(ISession session)
        {
            // create the users
            var admin = new User("anlai") { FirstName = "Alan", LastName = "Lai", Email = "[email protected]", IsActive = true };

            var user1 = new User("pjfry") { FirstName = "Philip", LastName = "Fry", Email = "[email protected]", IsActive = true };
            var user2 = new User("hsimpson") { FirstName = "Homer", LastName = "Simpson", Email="[email protected]", IsActive = true};
            var user3 = new User("brannigan") { FirstName = "Zapp", LastName = "Brannigan", Email = "[email protected]", IsActive = true };
            var user4 = new User("awong") { FirstName = "Amy", LastName = "Wong", Email = "[email protected]", IsActive = true };
            var user5 = new User("zoidberg") { FirstName = "John", LastName = "Zoidberg", Email = "[email protected]", IsActive = true };
            var user6 = new User("moe") { FirstName = "Moe", LastName = "Szyslak", Email = "[email protected]", IsActive = true };
            var user7 = new User("burns") { FirstName = "Monty", LastName = "Burns", Email = "[email protected]", IsActive = true };
            var user8 = new User("flanders") { FirstName = "Ned", LastName = "Flanders", Email = "[email protected]", IsActive = true };
            var user9 = new User("grimes") { FirstName = "Frank", LastName = "Grimes", Email = "[email protected]", IsActive = true };
            var user10 = new User("bender") { FirstName = "Bender", LastName = "Rodriguez", Email = "[email protected]", IsActive = true };

            // setup the workgroup
            var org1 = session.Load<Organization>("APLS");
            var org2 = session.Load<Organization>("AINF");
            var org3 = session.Load<Organization>("ACRU");

            var orgset1 = new List<Organization>();
            orgset1.Add(org1);
            orgset1.Add(org2);
            var orgset2 = new List<Organization>();
            orgset2.Add(org2);
            orgset2.Add(org3);

            var workgroup = new Workgroup() { Name = "Legitimate Workgroup, Not a Front", IsActive = true, PrimaryOrganization = org1,  Organizations = orgset1};

            var acct1 = session.Load<Account>("3-APSAC37");
            var acct2 = session.Load<Account>("3-APSM170");
            var acct3 = session.Load<Account>("3-APSRSTR"); // has sub account
            var acct4 = session.Load<Account>("3-APSM152"); // has sub account
            var acct5 = session.Load<Account>("3-APSM326"); // has sub account

            workgroup.AddAccount(new WorkgroupAccount() { Account = acct1 });
            workgroup.AddAccount(new WorkgroupAccount() { Account = acct3 });
            workgroup.AddAccount(new WorkgroupAccount() { Account = acct5 });

            workgroup.AddAccount(new WorkgroupAccount() { Account = acct2 });
            workgroup.AddAccount(new WorkgroupAccount() { Account = acct4 });

            var vendor1 = session.Load<Vendor>("0000247673");
            var vendoraddr1 = session.QueryOver<VendorAddress>().Where(a => a.Vendor == vendor1).Take(1).SingleOrDefault();
            var wv1 = new WorkgroupVendor() { VendorId = vendor1.Id, VendorAddressTypeCode = vendoraddr1.TypeCode, Name = vendor1.Name, Line1 = vendoraddr1.Line1, City = vendoraddr1.City, State = vendoraddr1.State, Zip = vendoraddr1.Zip, CountryCode = vendoraddr1.CountryCode };
            workgroup.AddVendor(wv1);

            var vendor2 = session.Load<Vendor>("0000008573");
            var vendoraddr2 = session.QueryOver<VendorAddress>().Where(a => a.Vendor == vendor2).Take(1).SingleOrDefault();
            var wv2 = new WorkgroupVendor(){VendorId = vendor2.Id, VendorAddressTypeCode = vendoraddr2.TypeCode, Name = vendor2.Name, Line1 = vendoraddr2.Line1, City = vendoraddr2.City, State = vendoraddr2.State, Zip = vendoraddr2.Zip, CountryCode = vendoraddr2.CountryCode};
            workgroup.AddVendor(wv2);

            var vendor3 = session.Load<Vendor>("0000006849");
            var vendoraddr3 = session.QueryOver<VendorAddress>().Where(a => a.Vendor == vendor2).Take(1).SingleOrDefault();
            var wv3 = new WorkgroupVendor(){VendorId = vendor3.Id, VendorAddressTypeCode = vendoraddr3.TypeCode, Name = vendor3.Name, Line1 = vendoraddr3.Line1, City = vendoraddr3.City, State = vendoraddr3.State, Zip = vendoraddr3.Zip, CountryCode = vendoraddr3.CountryCode};
            workgroup.AddVendor(wv3);

            var wv4 = new WorkgroupVendor() { Name = "Legitimate Paper Mill", Line1 = "1 Fake Street.", City = "Davis", State = "CA", Zip = "95616", CountryCode = "US" };
            workgroup.AddVendor(wv4);
            var wv5 = new WorkgroupVendor() { Name = "Office Supplies", Line1 = "2 Fake Street.", City = "Davis", State = "CA", Zip = "95616", CountryCode = "US" };
            workgroup.AddVendor(wv5);
            var wv6 = new WorkgroupVendor() { Name = "Loads O Lab Equipment", Line1 = "5 Fake Street.", City = "Davis", State = "CA", Zip = "95616", CountryCode = "US" };
            workgroup.AddVendor(wv6);

            var addr1 = new WorkgroupAddress() { Name = "128 Fake Hall", Address = "Fake Hall Road", City = "Davis", State = "CA", Zip = "95616" };
            workgroup.AddAddress(addr1);
            var addr2 = new WorkgroupAddress() { Name = "10 Fake Hall", Address = "Fake Hall Road", City = "Davis", State = "CA", Zip = "95616"};
            workgroup.AddAddress(addr2);
            var addr3 = new WorkgroupAddress() { Name = "526 Fake Hall", Address = "Fake Hall Road", City = "Davis", State = "CA", Zip = "95616" };
            workgroup.AddAddress(addr3);

            //setup workgroup permissions
            var permission1 = new WorkgroupPermission() { User = user1, Workgroup = workgroup, Role = session.Load<Role>("RQ") };
            var permission2 = new WorkgroupPermission() { User = user2, Workgroup = workgroup, Role = session.Load<Role>("AP") };
            var permission3 = new WorkgroupPermission() { User = user3, Workgroup = workgroup, Role = session.Load<Role>("AM") };
            var permission4 = new WorkgroupPermission() { User = user4, Workgroup = workgroup, Role = session.Load<Role>("PR") };
            //var permission5 = new WorkgroupPermission() { User = user5, Workgroup = workgroup, Role = session.Load<Role>("CA") };  // conditional approver
            var permission6 = new WorkgroupPermission() { User = user6, Workgroup = workgroup, Role = session.Load<Role>("RQ") };
            var permission7 = new WorkgroupPermission() { User = user7, Workgroup = workgroup, Role = session.Load<Role>("AP") };
            var permission8 = new WorkgroupPermission() { User = user8, Workgroup = workgroup, Role = session.Load<Role>("AM") };
            var permission9 = new WorkgroupPermission() { User = user9, Workgroup = workgroup, Role = session.Load<Role>("PR") };
            var permission10 = new WorkgroupPermission() { User = user10, Workgroup = workgroup, Role = session.Load<Role>("RQ") };

            workgroup.AddPermission(permission1);
            workgroup.AddPermission(permission2);
            workgroup.AddPermission(permission3);
            workgroup.AddPermission(permission4);
            //workgroup.AddPermission(permission5);
            workgroup.AddPermission(permission6);
            workgroup.AddPermission(permission7);
            workgroup.AddPermission(permission8);
            workgroup.AddPermission(permission9);
            workgroup.AddPermission(permission10);

            // create some conditional approvals
            var ca1 = new ConditionalApproval() {Workgroup = workgroup, PrimaryApprover = user5, Question = "Is this an IT purchaser?"};

            // save all the objects
            session.Save(admin);
            session.Save(user1);
            session.Save(user2);
            session.Save(user3);
            session.Save(user4);
            session.Save(user5);
            session.Save(user6);
            session.Save(user7);
            session.Save(user8);
            session.Save(user9);
            session.Save(user10);

            session.Save(workgroup);

            session.Save(ca1);

            // generate a minimum of 10 for our target user
            for (var i = 0; i < 5; i++)
            {
                var order = GenderateRandomOrder(workgroup, session.Load<OrderStatusCode>("AP"), session, permission1);
                session.Save(order);
            }
            for (var i = 0; i < 5; i++)
            {
                var order = GenderateRandomOrder(workgroup, session.Load<OrderStatusCode>("AM"), session, permission1);
                session.Save(order);
            }
            for (var i = 0; i < 3; i++)
            {
                var order = GenderateRandomOrder(workgroup, session.Load<OrderStatusCode>("PR"), session, permission1);
                session.Save(order);
            }
            for (var i = 0; i < 2; i++)
            {
                var order = GenderateRandomOrder(workgroup, session.Load<OrderStatusCode>("CN"), session, permission1, excludeUser:permission1);
                session.Save(order);
            }

            // now generate another random 50 orders
            for (var i = 0; i < 50; i++)
            {
                var status = session.QueryOver<OrderStatusCode>().Skip(_random.Next()%4).Take(1).SingleOrDefault();
                var order = GenderateRandomOrder(workgroup, status, session, excludeUser:permission1);
                session.Save(order);
            }
        }
コード例 #4
0
ファイル: DbHelper.cs プロジェクト: ucdavis/Purchasing
        /*
         * Dev Data
         */
        private static void InsertData(ISession session)
        {
            //Now insert new data
            var scott = new User("postit") { FirstName = "Scott", LastName = "Kirkland", Email = "[email protected]", IsActive = true };
            var approverUser = new User("approver") { FirstName = "Approver", LastName = "Approver", Email = "[email protected]", IsActive = true };
            var acctMgrUser = new User("acctmgr") { FirstName = "Account", LastName = "Manager", Email = "[email protected]", IsActive = true };
            var alan = new User("anlai") { FirstName = "Alan", LastName = "Lai", Email = "[email protected]", IsActive = true };
            var ken = new User("taylorkj") { FirstName = "Ken", LastName = "Taylor", Email = "[email protected]", IsActive = true };
            var chris = new User("cthielen") { FirstName = "Christopher", LastName = "Thielen", Email = "[email protected]", IsActive = true };
            var scottd = new User("sadyer") { FirstName = "Scott", LastName = "Dyer", Email = "[email protected]", IsActive = true };
            var jscub = new User("jscub")
                            {
                                FirstName = "James",
                                LastName = "Cubbage",
                                Email = "[email protected]",
                                IsActive = true
                            };
            var jsylvest = new User("jsylvest")
            {
                FirstName = "Jason",
                LastName = "Sylvestre",
                Email = "[email protected]",
                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
        }