public void AddProduct(Product product) { using (var context = new AuctionModelContainer()) { context.setLazyFalse(); if (product.Categories.Count() == 0) { throw new ValidationException("The product must have at least one category setted!"); } ICollection<Product> products = this.GetProdctByNameAndDescription(product.Name, product.Description); foreach (Category category in product.Categories) { foreach (Product p in products) { Product productAux = this.GetProdctById(p.IdProduct); context.Products.Attach(productAux); context.Entry(productAux).Collection(pAux => pAux.Categories).Load(); foreach (Category pcateg in productAux.Categories) { if (category.Name.Equals(pcateg.Name)) throw new DuplicateException("The same product already exists - same name, description and category"); } } } foreach (Category categ in product.Categories) context.Categories.Attach(categ); context.Products.Add(product); context.SaveChanges(); } }
public Domain.Product ToDomainProduct() { Domain.Product p = new Domain.Product(); p.Name = this.Name; p.UnitPrice = this.UnitPrice; return(p); }
public void TestProductDiscountWithNullDiscount() { ProductId prodOneId = new ProductId("1"); Product prodOne = new Product(prodOneId, 10m); decimal discountedPrice = prodOne.DiscountPrice(null); Assert.IsTrue(discountedPrice == 10m); }
public void TestProductEqualsIdenticalProduct() { ProductId prodOneId = new ProductId("1"); Product prodOne = new Product(prodOneId, 10m); Product prodOneClone = new Product(prodOneId, 10m); Assert.IsTrue(prodOne.Equals(prodOneClone)); }
public void TestAddNegativeNote() { User user1 = new User(); user1.FirstName = "AAA2"; user1.LastName = "AAA2"; user1.Email = "[email protected]"; User user2 = userService.GetUserByEmail("*****@*****.**"); Category category = categoryService.GetCategoryByName("category"); Product product = new Product(); product.Name = "BBBB2"; product.Description = "BBBB2"; product.Categories.Add(category); userService.AddUser(user1); productService.AddProduct(product); //currencyService.AddCurrency("RON"); Currency currency = currencyService.getCurrencyById(1); Role role = roleService.GetRoleByName(Constants.ACTIONEER); userService.AddRoleToUser("[email protected]", role); auctionService.AddNewAuction(user2, product, currency, 100, DateTime.Now, new DateTime(2015, 10, 18)); productAuctionService.AddProductAuction(user1, product, 101, currency); bool ok = userService.AddNoteToUser(user1, user2, -1); }
public void TestProductNotEqualsDifferentProductById() { ProductId prodOneId = new ProductId("1"); ProductId prodTwoId = new ProductId("2"); Product prodOne = new Product(prodOneId, 10m); Product prodTwo = new Product(prodTwoId, 10m); Assert.IsFalse(prodOne.Equals(prodTwo)); }
public void TestProductDiscountWithValidDiscountByDate() { ProductId prodOneId = new ProductId("1"); Product prodOne = new Product(prodOneId, 10m); DiscountByDate discount = new DiscountByDate(.1m, DateTime.Now.AddDays(1)); decimal discountedPrice = prodOne.DiscountPrice(discount); Assert.IsTrue(discountedPrice == 9m); }
public void TestProductDiscountWithInvalidDiscount() { ProductId prodOneId = new ProductId("1"); Product prodOne = new Product(prodOneId, 10m); string notADiscount = "bad discount"; decimal discountedPrice = prodOne.DiscountPrice(notADiscount); Assert.IsTrue(discountedPrice == 10m); }
public OrderedProduct(Product product) { ProductId = product.ProductId; Name = product.Name; Price = product.Price; RecurringPossible = product.RecurringPossible; SplitPaymentPossible = product.SplitPaymentPossible; }
public bool AddProduct(Product product) { logger.logInfo("Try to add a new product in db."); if (product == null) { ValidationException e = new ValidationException("Product is null"); logger.logError(e); throw e; } if (product.Categories == null) { ValidationException e = new ValidationException("Product's categories are null"); logger.logError(e); throw e; } CategoryService categoryService = new CategoryService(); foreach (Category categ in product.Categories) { if (categoryService.GetCategoryById(categ.IdCategory) == null) { EntityDoesNotExistException e = new EntityDoesNotExistException("One or more categories of the product do not exist"); logger.logError(e); throw e; } } var validationResults = Validation.Validate<Product>(product); if (product.Name != null) { if (!validationResults.IsValid) { ValidationException e = new ValidationException("Invalid product's name/description."); logger.logError(e); throw e; } else { try { DataMapperFactoryMethod.GetCurrentFactory().ProductFactory.AddProduct(product); } catch (DuplicateException duplicateException) { logger.logError(duplicateException); throw duplicateException; } } } else { ValidationException e = new ValidationException("Invalid product's name - null."); logger.logError(e); throw e; } logger.logInfo("Product added successfully!"); return true; }
public ICollection<Category> GetAllCategoryForAProduct(Product product) { using(var context = new AuctionModelContainer()) { context.Products.Attach(product); context.Entry(product).Collection(prod => prod.Categories).Load(); return product.Categories; } }
public static void AddAuction() { Auction auction = new Auction(); User user = new User(); Product product = new Product(); auction.Product = product; IAuctionService auctionService = new AuctionService(); auctionService.AddNewAuction(auction, user); }
internal static void Validate(Product product, ValidationResults results) { if (product.Name.Length < 3 || product.Name.Length > 30 || product.Description.Length > 200)//some business-logic derived condition { results.AddResult ( new ValidationResult("Invalid product's name/description.", product, "ValidateMethod", "error", null) ); } }
public void TestAddAuctionWithNegativeStartPrice() { User user = userService.GetUserById(1); Currency currency = currencyService.GetCurrencyByName("RON"); Category category = categoryService.GetCategoryById(1); Product product = new Product(); product.Name = "AAA7"; product.Description = "AAAAAAAA4"; product.Categories.Add(category); productService.AddProduct(product); auctionService.AddNewAuction(user, product, currency, -1.0, DateTime.Now, DateTime.Now); }
public void TestAddAuctionWithInvalidDates() { User user = userService.GetUserById(1); Currency currency = currencyService.GetCurrencyByName("RON"); Category category = categoryService.GetCategoryById(1); Product product = new Product(); product.Name = "AAA12"; product.Description = "AAAAAAAA12"; product.Categories.Add(category); productService.AddProduct(product); auctionService.AddNewAuction(user, product, currency, 1000, new DateTime(2015,01,10), new DateTime(2014,10,10)); }
public void AddProductNullName() { Product product = new Product(); product.Name = null; ProductService productService = new ProductService(); Boolean result = false; try { result = productService.AddProduct(product); } catch (ValidationException exc) { Assert.AreEqual("Invalid product's name - null.", exc.Message); } Assert.AreEqual(result, false); }
public bool AddProductAuction(User user, Product product, double price, Currency currency) { logger.logInfo("Try to add a new ProductAuction"); try { DataMapperFactoryMethod.GetCurrentFactory().ProductAuctionFactory.AddProductAuction(user, product, price, currency); return true; } catch (ValidationException validationException) { logger.logError(validationException); throw validationException; } catch (EntityDoesNotExistException entity) { logger.logError(entity); throw entity; } }
public bool closeAuction(User user, Product product) { logger.logInfo("Try to close a auction"); try { DataMapperFactoryMethod.GetCurrentFactory().ProductAuctionFactory.closeAuction(user, product); } catch (EntityDoesNotExistException exc) { logger.logError(exc); throw exc; } catch (AuctionException exc) { logger.logError(exc); throw exc; } return true; }
public void AddProductExistent() { Product product = new Product(); product.Name = "thr"; product.Description = ""; CategoryService categoryService = new CategoryService(); Category category = categoryService.GetCategoryById(2); product.Categories.Add(category); ProductService productService = new ProductService(); Boolean result = false; try { result = productService.AddProduct(product); } catch (DuplicateException exc) { Assert.AreEqual("The same product already exists - same name, description and category", exc.Message); } Assert.AreEqual(result, false); }
public void AddNewAuction(User user,Product product,Currency currency,double startPrice,DateTime startDate,DateTime endDate) { try { logger.logInfo("User "+user.Email+" try to add a new auction."); CheckUser(user); CheckProduct(product,user); Auction auction = new Auction(); auction.User = user; auction.Product = product; auction.Currency = currency; auction.StartPrice = startPrice; auction.BeginDate = startDate; auction.EndDate = endDate; var validationResults = Validation.Validate<Auction>(auction); if (!validationResults.IsValid) { throw new ValidationException("Invalid auction"); } DataMapperFactoryMethod.GetCurrentFactory().AuctionFactory.AddNewAuction(auction); } catch (EntityDoesNotExistException exc) { logger.logError(exc); throw exc; } catch (ValidationException validationException) { logger.logError(validationException); throw validationException; } catch (AuctionException auctioException) { logger.logError(auctioException); throw auctioException; } }
private void CheckProduct(Product product,User user) { ICategoryService categoryService = new CategoryService(); IProductService productService = new ProductService(); IConfiguration configuration = ConfigurationService.GetInstance(); ICollection<Category> categorys = categoryService.GetCategorysForAProduct(product); int nrOfAuctions = 0; foreach(Category category in categorys) { ICollection<Category> parentCAtegorys = categoryService.getParents(category.IdCategory); ICollection<Product> products; foreach(Category parentCategory in parentCAtegorys) { products = productService.GetAllProductsOfACategory(category); foreach(Product productCat in products) { Auction auction = productService.GetAuctionOfAProduct(productCat); if (auction != null && auction.User.Equals(user)) nrOfAuctions++; } } } if(nrOfAuctions >= configuration.GetValue(Constants.MAX_NR_OF_AUCTION_ASSOCIATE_WITH_CATEGORY)) throw new AuctionException("The auction can not be added because the number of auctions per category was exceeded"); }
public void AddProduct(Product product) { product.Order = this; products.Add(product); }
public void TestProductReturnsListPrice() { ProductId prodOneId = new ProductId("1"); decimal ListPrice = 10m; Product prodOne = new Product(prodOneId, ListPrice); Assert.IsTrue(prodOne.ListPrice == ListPrice); }
public void TestProductNotEqualsNull() { ProductId prodOneId = new ProductId("1"); Product prodOne = new Product(prodOneId, 10m); Assert.IsFalse(prodOne.Equals(null)); }
public ICollection<Category> GetCategorysForAProduct(Product product) { logger.logInfo("Get all category for product " + product.Name); return DataMapperFactoryMethod.GetCurrentFactory().CategoryFactory.GetAllCategoryForAProduct(product); }
public Auction GetAuctionOfAProduct(Product product) { return DataMapperFactoryMethod.GetCurrentFactory().ProductFactory.GetAuctionOfAProduct(product); }
public void TestAddNewAuctionByAUserWithGoodRating() { User user = userService.GetUserById(1); Currency currency = currencyService.GetCurrencyByName("RON"); Category category = categoryService.GetCategoryById(1); Product product = new Product(); product.Name = "AAA2"; product.Description = "AAAAAAAA2"; product.Categories.Add(category); productService.AddProduct(product); auctionService.AddNewAuction(user, product, currency, 100, DateTime.Now, DateTime.Now); }
public void TestAddNewAuctionByAUserWithBadRating() { User user1 = userService.GetUserById(1); User user2 = new User(); user2.FirstName = "CCC"; user2.LastName = "CCC"; user2.Email = "[email protected]"; userService.AddUser(user2); userService.AddRoleToUser("[email protected]", roleService.GetRoleByName(Constants.ACTIONEER)); Category category = categoryService.GetCategoryById(1); Product product = new Product(); product.Name = "AAA3"; product.Description = "AAAAAAAA3"; product.Categories.Add(category); productService.AddProduct(product); Currency currency = currencyService.GetCurrencyByName("RON"); auctionService.AddNewAuction(user1, product, currency, 100, DateTime.Now, DateTime.Now); productAuctionService.AddProductAuction(user2, product, 500, currency); userService.AddNoteToUser(user2, user1, 1); product = new Product(); product.Name = "AAA4"; product.Description = "AAAAAAAA4"; product.Categories.Add(category); productService.AddProduct(product); auctionService.AddNewAuction(user1, product, currency, 100, DateTime.Now, DateTime.Now); }
public void TestAddLicitation() { User user1 = new User(); user1.FirstName = "AAA"; user1.LastName = "AAA"; user1.Email = "[email protected]"; User user2 = new User(); user2.FirstName = "BBB"; user2.LastName = "BBB"; user2.Email = "[email protected]"; Role role1 = new Role(); role1.Name = Constants.OWNER; Role role2 = new Role(); role2.Name = Constants.ACTIONEER; Category category = new Category(); category.Name = "category"; category.Description = "AAAAA"; categoryService.AddCategory(category); Product product = new Product(); product.Name = "AAA"; product.Description = "AAAAAAAA"; product.Categories.Add(category); userService.AddUser(user1); userService.AddUser(user2); productService.AddProduct(product); currencyService.AddCurrency("RON"); Currency currency = currencyService.GetCurrencyByName("RON"); roleService.AddRole(role1); roleService.AddRole(role2); userService.AddRoleToUser("[email protected]", role1); userService.AddRoleToUser("[email protected]", role2); auctionService.AddNewAuction(user1, product, currency, 100, DateTime.Now, DateTime.Now); productAuctionService.AddProductAuction(user2, product, 200, currency); userService.AddNoteToUser(user2, user1, 7); }
public Auction GetAuctionOfAProduct(Product product) { using (var context = new AuctionModelContainer()) { var auctionVar = (from auction in context.Auctions join productSel in context.Products on auction.Product.IdProduct equals product.IdProduct where productSel.IdProduct == product.IdProduct select auction).FirstOrDefault(); if (auctionVar != null) { context.Auctions.Attach(auctionVar); context.Entry(auctionVar).Reference(auc => auc.User).Load(); } return auctionVar; } }
public void UpdateProductDescription(Product product, String description) { using (var context = new AuctionModelContainer()) { ICollection<Product> products = this.GetProdctByNameAndDescription(product.Name, description); foreach (Category category in product.Categories) { foreach (Product p in products) { Product productAux = this.GetProdctById(p.IdProduct); context.Products.Attach(productAux); context.Entry(productAux).Collection(pAux => pAux.Categories).Load(); foreach (Category pcateg in productAux.Categories) { if (category.Name.Equals(pcateg.Name)) throw new DuplicateException("The same product already exists - same name, description and category"); } } } product.Description = description; context.Products.Attach(product); var entry = context.Entry(product); entry.Property(r => r.Description).IsModified = true; context.SaveChanges(); } }