Ejemplo n.º 1
0
        /// <summary>
        /// Step 11
        /// </summary>
        /// <returns></returns>
        public ActionResult AddConditionalApproval(int id)
        {
            if (id == 0)
            {
                Message = "Workgroup must be created before proceeding";
                return(this.RedirectToAction(a => a.CreateWorkgroup()));
            }
            ViewBag.StepNumber = 11;
            var workgroup = _workgroupRepository.GetNullableById(id);

            if (workgroup == null)
            {
                Message = "Workgroup not found.";
                this.RedirectToAction <WorkgroupController>(a => a.Index(false));
            }
            if (workgroup.Administrative)
            {
                return(this.RedirectToAction <WorkgroupController>(a => a.Index(false)));
            }
            var model = new ConditionalApproval();

            model.Workgroup       = workgroup;
            ViewBag.IsAccountSync = workgroup.SyncAccounts;

            return(View(model));
        }
Ejemplo n.º 2
0
        public static ConditionalApproval ConditionalApproval(int?counter)
        {
            var rtValue = new ConditionalApproval();

            rtValue.Question        = "Question" + counter.Extra();
            rtValue.PrimaryApprover = new User();
            rtValue.Workgroup       = new Workgroup();

            return(rtValue);
        }
Ejemplo n.º 3
0
        public static ConditionalApproval ConditionalApproval(int? counter)
        {
            var rtValue = new ConditionalApproval();
            rtValue.Question = "Question" + counter.Extra();
            rtValue.PrimaryApprover = new User();
            rtValue.Workgroup = new Workgroup();

            return rtValue;
        }
Ejemplo n.º 4
0
        /*
         * Demo Data
         */
        private static void InsertDemoData(ISession session)
        {
            // create the users
            var admin = new User("anlai") { FirstName = "Alan", LastName = "Lai", Email = "*****@*****.**", IsActive = true };

            var user1 = new User("pjfry") { FirstName = "Philip", LastName = "Fry", Email = "*****@*****.**", IsActive = true };
            var user2 = new User("hsimpson") { FirstName = "Homer", LastName = "Simpson", Email="*****@*****.**", IsActive = true};
            var user3 = new User("brannigan") { FirstName = "Zapp", LastName = "Brannigan", Email = "*****@*****.**", IsActive = true };
            var user4 = new User("awong") { FirstName = "Amy", LastName = "Wong", Email = "*****@*****.**", IsActive = true };
            var user5 = new User("zoidberg") { FirstName = "John", LastName = "Zoidberg", Email = "*****@*****.**", IsActive = true };
            var user6 = new User("moe") { FirstName = "Moe", LastName = "Szyslak", Email = "*****@*****.**", IsActive = true };
            var user7 = new User("burns") { FirstName = "Monty", LastName = "Burns", Email = "*****@*****.**", IsActive = true };
            var user8 = new User("flanders") { FirstName = "Ned", LastName = "Flanders", Email = "*****@*****.**", IsActive = true };
            var user9 = new User("grimes") { FirstName = "Frank", LastName = "Grimes", Email = "*****@*****.**", IsActive = true };
            var user10 = new User("bender") { FirstName = "Bender", LastName = "Rodriguez", Email = "*****@*****.**", 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);
            }
        }
        public ActionResult Create(int?workgroupId, string orgId, ConditionalApprovalModifyModel modifyModel)
        {
            if (workgroupId.HasValue)
            {
                ViewBag.WorkgroupId      = workgroupId.Value;
                modifyModel.ApprovalType = WorkgroupType;
                modifyModel.Workgroup    = _workgroupRepository.GetNullableById(workgroupId.Value);
                var workgroup = _workgroupRepository.Queryable.Single(a => a.Id == workgroupId.Value);
                if (workgroup.Administrative)
                {
                    ErrorMessage = "Conditional Approval may not be added to an administrative workgroup.";
                    return(this.RedirectToAction <WizardController>(a => a.Details(workgroup.Id)));
                }
            }
            else if (!string.IsNullOrWhiteSpace(orgId))
            {
                modifyModel.ApprovalType = OrganizationType;
                modifyModel.Organization = _organizationRepository.GetNullableById(orgId);
                ViewBag.OrganizationId   = orgId;
            }

            var primaryApproverInDb   = GetUserBySearchTerm(modifyModel.PrimaryApprover);
            var secondaryApproverInDb = string.IsNullOrWhiteSpace(modifyModel.SecondaryApprover)
                                            ? null
                                            : GetUserBySearchTerm(modifyModel.SecondaryApprover);

            if (primaryApproverInDb == null)
            {
                DirectoryUser primaryApproverInLdap = _directorySearchService.FindUser(modifyModel.PrimaryApprover);

                if (primaryApproverInLdap == null)
                {
                    ModelState.AddModelError("primaryapprover",
                                             "No user could be found with the kerberos or email address entered");
                }
                else //found the primary approver in ldap
                {
                    primaryApproverInDb = new User(primaryApproverInLdap.LoginId)
                    {
                        FirstName = primaryApproverInLdap.FirstName,
                        LastName  = primaryApproverInLdap.LastName,
                        Email     = primaryApproverInLdap.EmailAddress,
                        IsActive  = true
                    };

                    _userRepository.EnsurePersistent(primaryApproverInDb, forceSave: true);
                }
            }

            if (!string.IsNullOrWhiteSpace(modifyModel.SecondaryApprover)) //only check if a value was provided
            {
                if (secondaryApproverInDb == null)
                {
                    DirectoryUser secondaryApproverInLdap = _directorySearchService.FindUser(modifyModel.SecondaryApprover);

                    if (secondaryApproverInLdap == null)
                    {
                        ModelState.AddModelError("secondaryapprover",
                                                 "No user could be found with the kerberos or email address entered");
                    }
                    else //found the secondary approver in ldap
                    {
                        secondaryApproverInDb = new User(secondaryApproverInLdap.LoginId)
                        {
                            FirstName = secondaryApproverInLdap.FirstName,
                            LastName  = secondaryApproverInLdap.LastName,
                            Email     = secondaryApproverInLdap.EmailAddress,
                            IsActive  = true
                        };

                        _userRepository.EnsurePersistent(secondaryApproverInDb, forceSave: true);
                    }
                }
            }

            if (!ModelState.IsValid)
            {
                return(View(CreateModifyModel(modifyModel.ApprovalType, modifyModel)));
            }

            Check.Require(modifyModel.Workgroup != null || modifyModel.Organization != null, "Must have a Workgroup or an Organization");

            var newConditionalApproval = new ConditionalApproval
            {
                Question          = modifyModel.Question,
                Organization      = modifyModel.Organization,
                Workgroup         = modifyModel.Workgroup,
                PrimaryApprover   = primaryApproverInDb,
                SecondaryApprover = secondaryApproverInDb
            };

            _conditionalApprovalRepository.EnsurePersistent(newConditionalApproval);

            Message = "Conditional approval added successfully";

            if (workgroupId.HasValue)
            {
                return(this.RedirectToAction(a => a.ByWorkgroup(workgroupId.Value)));
            }

            if (!string.IsNullOrWhiteSpace(orgId))
            {
                return(this.RedirectToAction(a => a.ByOrg(orgId)));
            }

            //return this.RedirectToAction(a => a.Index());
            return(this.RedirectToAction <ErrorController>(a => a.Index()));
        }
Ejemplo n.º 6
0
        public ActionResult AddConditionalApproval(int id, ConditionalApproval conditionalApproval, string primaryApproverParm, string secondaryApproverParm)
        {
            ViewBag.StepNumber = 11;
            // TODO Check that primary and secondary approvers are in db, add if not. Double check against ConditionalApprover controller
            var workgroup = _workgroupRepository.GetNullableById(id);

            if (workgroup == null)
            {
                Message = "Workgroup not found.";
                this.RedirectToAction <WorkgroupController>(a => a.Index(false));
            }
            ViewBag.IsAccountSync = workgroup.SyncAccounts;

            var primaryApproverInDb   = GetUserBySearchTerm(primaryApproverParm);
            var secondaryApproverInDb = string.IsNullOrWhiteSpace(secondaryApproverParm)
                                            ? null
                                            : GetUserBySearchTerm(secondaryApproverParm);

            if (primaryApproverInDb == null)
            {
                DirectoryUser primaryApproverInLdap = _searchService.FindUser(primaryApproverParm);

                if (primaryApproverInLdap == null)
                {
                    ModelState.AddModelError("primaryApproverParm",
                                             "No user could be found with the kerberos or email address entered");
                }
                else //found the primary approver in ldap
                {
                    primaryApproverInDb = new User(primaryApproverInLdap.LoginId)
                    {
                        FirstName = primaryApproverInLdap.FirstName,
                        LastName  = primaryApproverInLdap.LastName,
                        Email     = primaryApproverInLdap.EmailAddress,
                        IsActive  = true
                    };

                    _userRepository.EnsurePersistent(primaryApproverInDb, forceSave: true);
                }
            }

            if (!string.IsNullOrWhiteSpace(secondaryApproverParm)) //only check if a value was provided
            {
                if (secondaryApproverInDb == null)
                {
                    DirectoryUser secondaryApproverInLdap = _searchService.FindUser(secondaryApproverParm);

                    if (secondaryApproverInLdap == null)
                    {
                        ModelState.AddModelError("secondaryApproverParm",
                                                 "No user could be found with the kerberos or email address entered");
                    }
                    else //found the secondary approver in ldap
                    {
                        secondaryApproverInDb = new User(secondaryApproverInLdap.LoginId)
                        {
                            FirstName = secondaryApproverInLdap.FirstName,
                            LastName  = secondaryApproverInLdap.LastName,
                            Email     = secondaryApproverInLdap.EmailAddress,
                            IsActive  = true
                        };

                        _userRepository.EnsurePersistent(secondaryApproverInDb, forceSave: true);
                    }
                }
            }

            conditionalApproval.PrimaryApprover   = primaryApproverInDb;
            conditionalApproval.SecondaryApprover = secondaryApproverInDb;
            conditionalApproval.Workgroup         = workgroup;
            ModelState.Clear();
            conditionalApproval.TransferValidationMessagesTo(ModelState);

            if (ModelState.IsValid)
            {
                var newConditionalApproval = new ConditionalApproval
                {
                    Question          = conditionalApproval.Question,
                    Organization      = conditionalApproval.Organization,
                    Workgroup         = workgroup,
                    PrimaryApprover   = primaryApproverInDb,
                    SecondaryApprover = secondaryApproverInDb
                };
                Repository.OfType <ConditionalApproval>().EnsurePersistent(newConditionalApproval);
                return(this.RedirectToAction(a => a.ConditionalApprovals(id)));
            }
            conditionalApproval.Workgroup = workgroup;
            return(View(conditionalApproval));
        }