예제 #1
0
        public Error InsertOrUpdateBrandCategory(BrandCategoryModel category,
                                                 List <int> selectedBrandIds,
                                                 UserModel user, string lockGuid)
        {
            var error = validateModel(category);

            if (!error.IsError)
            {
                // Check that the lock is still current
                if (!db.IsLockStillValid(typeof(BrandCategory).ToString(), category.Id, lockGuid))
                {
                    error.SetError(EvolutionResources.errRecordChangedByAnotherUser, "CategoryName");
                }
                else
                {
                    BrandCategory temp = null;
                    if (category.Id != 0)
                    {
                        temp = db.FindBrandCategory(category.Id);
                    }
                    if (temp == null)
                    {
                        temp = new BrandCategory();
                    }

                    Mapper.Map <BrandCategoryModel, BrandCategory>(category, temp);

                    db.InsertOrUpdateBrandCategory(temp, selectedBrandIds);
                    category.Id = temp.Id;
                }
            }
            return(error);
        }
예제 #2
0
        public void DeleteBrandCategoryTest()
        {
            // Get a test user
            var user        = GetTestUser();
            var testCompany = GetTestCompany(user);

            // Create a price level
            BrandCategoryModel model = createBrandCategory(testCompany);

            var error = ProductService.InsertOrUpdateBrandCategory(model, null, user, "");

            Assert.IsTrue(!error.IsError, error.Message);

            // Check that it was written
            var result = db.FindBrandCategory(model.Id);
            BrandCategoryModel test = ProductService.MapToModel(result);

            AreEqual(model, test);

            // Now delete it
            ProductService.DeleteBrandCategory(model.Id);

            // And check that is was deleted
            result = db.FindBrandCategory(model.Id);
            Assert.IsTrue(result == null, "Error: A non-NULL value was returned when a NULL value was expected - record delete failed");
        }
예제 #3
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);
        }
예제 #4
0
 public List <ListItemModel> FindBrandBrandCategoriesListItemModel(BrandCategoryModel brandCategory) //int brandCategoryId) {
 {
     return(db.FindBrandBrandCategories(brandCategory.Id)
            .Select(bc => new ListItemModel {
         Id = bc.Brand.Id.ToString(),
         Text = bc.Brand.BrandName,
         ImageURL = ""
     })
            .ToList());
 }
        public void FindBrandCategorySalesPersonsModelTest()
        {
            var testUser     = GetTestUser();
            var testCompany  = GetTestCompany(testUser);
            var testCustomer = GetTestCustomer(testCompany, testUser);

            // Create a brand
            var brand = new BrandModel {
                BrandName = RandomString(),
                Enabled   = true
            };
            var error = ProductService.InsertOrUpdateBrand(brand, testUser, "");

            Assert.IsTrue(!error.IsError, error.Message);

            var brandIds = new List <int>();

            brandIds.Add(brand.Id);

            // Add the brand to a brand category
            var brandCategory = new BrandCategoryModel {
                CompanyId    = testCompany.Id,
                CategoryName = RandomString(),
                Enabled      = true
            };

            error = ProductService.InsertOrUpdateBrandCategory(brandCategory, brandIds, testUser, "");
            Assert.IsTrue(!error.IsError, error.Message);

            // Add some users as the sales persons
            var salesPerson1 = GetTestUser();
            var model1       = createBrandCategorySalesPerson(testCompany, brandCategory, testCustomer, salesPerson1, getSalesPersonType());

            error = CustomerService.InsertOrUpdateBrandCategorySalesPerson(model1, testUser, "");
            Assert.IsTrue(!error.IsError, $"Error: {error.Message}");

            var salesPerson2 = GetTestUser();
            var model2       = createBrandCategorySalesPerson(testCompany, brandCategory, testCustomer, salesPerson2, getSalesPersonType());

            error = CustomerService.InsertOrUpdateBrandCategorySalesPerson(model2, testUser, "");
            Assert.IsTrue(!error.IsError, $"Error: {error.Message}");

            var salesPerson3 = GetTestUser();
            var model3       = createBrandCategorySalesPerson(testCompany, brandCategory, testCustomer, salesPerson2, getAdminPersonType());

            error = CustomerService.InsertOrUpdateBrandCategorySalesPerson(model3, testUser, "");
            Assert.IsTrue(!error.IsError, $"Error: {error.Message}");

            // Find the Brand category sales persons
            var salesPersons = CustomerService.FindBrandCategorySalesPersonsListModel(testCustomer.Id, 0, 1, Int32.MaxValue, "");
            int expected     = 3,
                actual       = salesPersons.Items.Count();

            Assert.IsTrue(actual == expected, $"Error: {actual} items were returned when {expected} were expected");
        }
예제 #6
0
 public JsonResult GetBrandCategoryDetails(int id)
 {
     using (var db = new PolishWarehouseEntities())
     {
         try
         {
             var m = new BrandCategoryModel(id);
             return(Json(m));
         }
         catch (Exception ex)
         {
             return(Json(ex.Message));
         }
     }
 }
예제 #7
0
        private Error validateModel(BrandCategoryModel model)
        {
            var error = isValidRequiredString(getFieldValue(model.CategoryName), 64, "CategoryName", EvolutionResources.errTextDataRequiredInField);

            if (!error.IsError)
            {
                // Check if a record with the same name already exists
                var category = db.FindBrandCategory(model.CompanyId, model.CategoryName);
                if (category != null &&                 // Record was found
                    ((category.Id == 0 ||               // when creating new or
                      category.Id != model.Id)))        // when updating existing
                {
                    error.SetError(EvolutionResources.errBrandCategoryAlreadyExists, "CategoryName");
                }
            }

            return(error);
        }
예제 #8
0
        protected BrandCategoryModel SearchBrandCategory(IList <BrandCategoryModel> list, string urlKey)
        {
            BrandCategoryModel category = null;
            bool found = false;

            foreach (var item1 in list)
            {
                foreach (var item2 in item1.Children)
                {
                    foreach (var item3 in item2.Children)
                    {
                        if (urlKey.ToLower() == item3.UrlKey.ToLower())
                        {
                            category = item3;
                            found    = true;
                            break;
                        }
                    }

                    if (found)
                    {
                        break;
                    }
                    if (urlKey.ToLower() == item2.UrlKey.ToLower())
                    {
                        category = item2;
                        found    = true;
                        break;
                    }
                }
                if (found)
                {
                    break;
                }
                if (urlKey.ToLower() == item1.UrlKey.ToLower())
                {
                    category = item1;
                    found    = true;
                    break;
                }
            }

            return(category);
        }
예제 #9
0
        public ActionResult DeleteBrandCategory(BrandCategoryModel model)
        {
            try
            {
                var resp = model.Delete();
                if (resp.WasSuccessful)
                {
                    TempData["Messages"] = "Category Deleted!";
                }
                else
                {
                    TempData["Errors"] = resp.Message;
                }
            }
            catch (Exception ex)
            {
                TempData["Errors"] = ex.Message;
            }

            return(RedirectToAction("BrandCategories"));
        }
예제 #10
0
        private BrandCategoryModel createBrandCategoryWithBrands(CompanyModel testCompany, UserModel testUser, int numBrandsToAdd)
        {
            // Create a brand category
            BrandCategoryModel brandCategory = createBrandCategory(testCompany);

            ProductService.InsertOrUpdateBrandCategory(brandCategory, null, testUser, "");

            // Now attach random brands
            var brandList = ProductService.FindBrandListModel(0, 1, PageSize, "").Items;
            int actual    = brandList.Count();

            Assert.IsTrue(actual > 0, $"Error: {actual} Brands were found when 1 or more were expected");

            for (int i = 0; i < numBrandsToAdd; i++)
            {
                int rand = RandomInt(0, brandList.Count() - 1);
                ProductService.AddBrandToBrandCategory(testCompany, brandList[rand], brandCategory);
                brandList.RemoveAt(rand);       // So we don't try to add the same item again
            }

            return(brandCategory);
        }
        private BrandCategorySalesPersonModel createBrandCategorySalesPerson(CompanyModel testCompany,
                                                                             BrandCategoryModel brandCategory,
                                                                             CustomerModel customer, UserModel user,
                                                                             LOVItemModel salesPersonType)
        {
            var tempUser = db.FindUser(user.Id) ?? new User {
                Id = 0, FirstName = "", LastName = ""
            };

            BrandCategorySalesPersonModel model = new BrandCategorySalesPersonModel {
                CompanyId           = testCompany.Id,
                BrandCategoryId     = brandCategory.Id,
                BrandCategoryName   = db.FindBrandCategory(brandCategory.Id).CategoryName,
                CustomerId          = customer.Id,
                UserId              = user.Id,
                UserName            = (tempUser.FirstName + " " + tempUser.LastName).Trim().WordCapitalise(),
                SalesPersonTypeId   = salesPersonType.Id,
                SalesPersonTypeName = db.FindLOVItem(salesPersonType.Id).ItemText
            };

            return(model);
        }
예제 #12
0
        public BrandCategoryModel FindBrandCategoryModel(int id, CompanyModel company, bool bCreateEmptyIfNotfound = true)
        {
            BrandCategoryModel model = null;

            var bc = db.FindBrandCategory(id);

            if (bc == null)
            {
                if (bCreateEmptyIfNotfound)
                {
                    model = new BrandCategoryModel {
                        CompanyId = company.Id
                    }
                }
                ;
            }
            else
            {
                model = MapToModel(bc);
            }

            return(model);
        }
예제 #13
0
        public BrandCategoryModel MapToModel(BrandCategoryModel item)
        {
            var newItem = Mapper.Map <BrandCategoryModel, BrandCategoryModel>(item);

            return(newItem);
        }
예제 #14
0
 public void DeleteBrandFromBrandCategory(BrandModel brand, BrandCategoryModel brandCategory)
 {
     db.DeleteBrandFromBrandCategory(brandCategory.CompanyId, brandCategory.Id, brand.Id);
 }
예제 #15
0
        public BrandBrandCategoryModel AddBrandToBrandCategory(CompanyModel company, BrandModel brand, BrandCategoryModel brandCategory)
        {
            BrandBrandCategoryModel result = new BrandBrandCategoryModel();

            BrandBrandCategory bbc = db.FindBrandBrandCategories(brandCategory.Id)
                                     .Where(bbci => bbci.BrandId == brand.Id)
                                     .FirstOrDefault();

            if (bbc == null)
            {
                bbc = new BrandBrandCategory {
                    Company       = db.FindCompany(company.Id),
                    BrandCategory = db.FindBrandCategory(brandCategory.Id),
                    Brand         = db.FindBrand(brand.Id)
                };
                db.InsertOrUpdateBrandBrandCategory(bbc);
            }
            Mapper.Map(bbc, result);

            return(result);
        }
예제 #16
0
 public string LockBrandCategory(BrandCategoryModel model)
 {
     return(db.LockRecord(typeof(BrandCategory).ToString(), model.Id));
 }