Exemplo n.º 1
0
        public Error InsertOrUpdateBrandCategorySalesPerson(BrandCategorySalesPersonModel acctMgr, UserModel user, string lockGuid)
        {
            var error = validateAddressModel(acctMgr);

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

                    var before = MapToEntity(temp);

                    MapToEntity(acctMgr, temp);

                    db.InsertOrUpdateBrandCategorySalesPerson(temp);
                    acctMgr.Id = temp.Id;

                    logChanges(before, temp, user);
                }
            }
            return(error);
        }
        public void DeleteBrandCategorySalesPersonTest()
        {
            // Get a test user
            var user          = GetTestUser();
            var testCompany   = GetTestCompany(user);
            var testCustomer  = GetTestCustomer(testCompany, user);
            var brandCategory = ProductService.FindBrandCategoriesModel(testCompany).First();

            // Create a price level
            BrandCategorySalesPersonModel model = createBrandCategorySalesPerson(testCompany, brandCategory, testCustomer, user, getSalesPersonType());

            var error = CustomerService.InsertOrUpdateBrandCategorySalesPerson(model, user, "");

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

            // Check that it was written
            var result = db.FindBrandCategorySalesPerson(model.Id);

            AreEqual(model, result);

            // Now delete it
            CustomerService.DeleteBrandCategorySalesPerson(model.Id);

            // And check that is was deleted
            result = db.FindBrandCategorySalesPerson(model.Id);
            Assert.IsTrue(result == null, "Error: A non-NULL value was returned when a NULL value was expected - record delete failed");
        }
        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);
        }
Exemplo n.º 4
0
        public BrandCategorySalesPersonModel FindBrandCategorySalesPersonModel(int id, CompanyModel company, int customerId, bool bCreateEmptyIfNotfound = true)
        {
            BrandCategorySalesPersonModel model = null;

            var sp = db.FindBrandCategorySalesPerson(id);

            if (sp == null)
            {
                if (bCreateEmptyIfNotfound)
                {
                    model = new BrandCategorySalesPersonModel {
                        CompanyId  = company.Id,
                        CustomerId = customerId
                    }
                }
                ;
            }
            else
            {
                model = MapToModel(sp);
            }

            return(model);
        }
Exemplo n.º 5
0
 public void MapToEntity(BrandCategorySalesPersonModel model, BrandCategorySalesPerson entity)
 {
     Mapper.Map <BrandCategorySalesPersonModel, BrandCategorySalesPerson>(model, entity);
 }
Exemplo n.º 6
0
        private Error validateAddressModel(BrandCategorySalesPersonModel model)
        {
            var error = new Error();

            return(error);
        }
Exemplo n.º 7
0
 public string LockBrandCategorySalesPerson(BrandCategorySalesPersonModel model)
 {
     return(db.LockRecord(typeof(BrandCategorySalesPerson).ToString(), model.Id));
 }