public ProductModel(Product product) { Id = product.Id; Category = product.Category.Name; Image = new Image(product.ImagePath); Parts = new List<PartModel>(); }
public IList<PartCategory> GetAllPartCategoriesByProduct(Product product) { if(product.Parts==null) { return new List<PartCategory>(); } return product.Parts.Select(p => p.Category).Distinct().ToList(); }
public void Update(Product product) { var prod = Get(product.Id); if (prod != null) { prod = product; _context.SaveChanges(); } }
public void Delete(Product product) { var prod = Get(product.Id); if (prod != null) { _context.Products.Remove(prod); _context.SaveChanges(); } }
public bool UpdateProduct(Product product) { var prod = _context.Products.FirstOrDefault(x => x.Id == product.Id); if(prod != null) { prod = product; _context.SaveChanges(); return true; } return false; }
public bool UpdateProduct(Product product, Part part) { var prod = _context.Products.FirstOrDefault(x => x.Id == product.Id); if (prod != null) { prod.Parts.SingleOrDefault(p => p.Id == part.Id).IncompatibleParts.Clear(); prod = product; _context.SaveChanges(); return true; } return false; }
public Product Add(Product product) { _context.Products.Add(product); _context.SaveChanges(); return product; }
public IList<Order> GetOrderByProduct(Product product) { throw new NotImplementedException(); }
public ActionResult CreateProduct(ProductViewModel model) { if (!ModelState.IsValid) { return View(model); } else if (_productService.GetAllProductCategories().Any(c => c.Name == model.Product.Category)) { ModelState.AddModelError("Product.Category", "Category already exists"); return View(); } var product = new Product() { Name = model.Product.Category, Category = new ProductCategory { Name = model.Product.Category }, ImagePath = SaveImage(model.Product.Image.ImageUpload) }; product = _productService.AddProduct(product); return RedirectToAction("ProductPartList", new { id = product.Id }); }
public void UpdateProduct(Product product) { _repository.Update(product); }
public IList<Part> DisplayPartsByCategory(Product product, PartCategory category) { return product.Parts.Where(p => p.Category.Id == category.Id).ToList(); }
public bool DeleteProduct(Product product) { return _repository.DeleteProduct(product); }
public Product AddProduct(Product product) { _repository.AddProduct(product); return product; }
public ActionResult CreateProduct(ProductViewModel model) { var path = ""; var fullPath = ""; var categories = _productService.GetAllProductCategories(); if(categories.Any(c => c.Name == model.Product.Category)) { return View("~/Views/Admin/CreateProduct.cshtml"); } if(model.Product.Image.ImageUpload.FileName!=null) { var fileName = Path.GetFileName(model.Product.Image.ImageUpload.FileName); path = Url.Content(Path.Combine(Server.MapPath("~/Content/Images"), fileName)); model.Product.Image.ImageUpload.SaveAs(path); fullPath = @"~/Content/Images/" + fileName; } var product = new Product() { Name = model.Product.Category, Category = new ProductCategory { Name = model.Product.Category }, ImagePath = fullPath }; product = _productService.AddProduct(product); return RedirectToAction("ProductPartList", new { id = product.Id }); }
public IEnumerable<Order> GetOrdersByProduct(Product product) { return _context.Orders.Where(x => x.Product.Id == product.Id); }
public void AssertThat_AddProduct_Returns_Same_Product() { var prod = new Product { Id = 5, Category = new ProductCategory { Id = 16, Name = "Bullar" }, Name = "Fiskbulle", ImagePath = "", ProductCode = "", Parts = new List<Part>() }; Assert.AreSame(prod, _service.AddProduct(prod)); }
public bool UpdateProduct(Product product, Part part) { return _repository.UpdateProduct(product, part); }
public ProductViewModel(Product product) { Product = new ProductModel(product); }
public void DeleteProduct(Product product) { _repository.Delete(product); }