Exemple #1
0
        public List <UserModel> FindOrderPurchasers(PurchaseOrderHeaderModel poh,
                                                    CompanyModel company,
                                                    decimal poNumber,
                                                    ref string errorMsg)
        {
            // Given a PurchaseOrderHeader model, finds the sales person (purchaser)
            // for the order and returns a list of all the users in the same user
            // group as the sales person, including the sales person.
            List <UserModel> users = null;

            UserModel salesPerson = null;

            if (poh.SalespersonId != null)
            {
                salesPerson = MembershipManagementService.FindUserModel(poh.SalespersonId.Value);
            }
            if (salesPerson != null)
            {
                // Found the sales person
                BrandCategoryModel brandCat = null;
                if (poh.BrandCategoryId != null)
                {
                    brandCat = ProductService.FindBrandCategoryModel(poh.BrandCategoryId.Value, company, false);
                }
                if (brandCat != null)
                {
                    string groupName = brandCat.CategoryName.ToLower() + " purchasing";
                    var    userGroup = MembershipManagementService.FindGroupsForUser(salesPerson)
                                       .Where(ug => ug.GroupName.ToLower().Contains(groupName))
                                       .FirstOrDefault();
                    if (userGroup != null)
                    {
                        // Found the group, so get all the users in the group, including the sales person
                        users = MembershipManagementService.FindUsersInGroup(userGroup);
                        if (users.Count() == 0)
                        {
                            errorMsg = $"Error: Active Directory User Group '{groupName}' has no members!";
                            users    = null;;
                        }
                    }
                    else
                    {
                        errorMsg = $"Error: Failed to find Active Directory Group '{groupName}' !";
                    }
                }
                else
                {
                    errorMsg = $"Error: Failed to find a Brand Catgeory for Purchase Order Number {poNumber} !";
                }
            }
            else
            {
                errorMsg = $"Error: Failed to find a Sales Person for Purchase Order Number {poNumber} !";
            }

            return(users);
        }