public static Product ProductBTOToProduct(this ProductBTO bto) { //return new Product //{ // name = bto.name, // description = bto.description, // price = bto.price, // publicationDate = bto.publicationDate, // categoryId = (Category)bto.categoryId // //public int id { get; set; } //}; Product product = new Product(); product.name = bto.name; product.description = bto.description; product.price = bto.price; product.publicationDate = bto.publicationDate; product.categoryId = bto.categoryId; //product.category = bto.category.CategoryBTOToCategory(); return(product); //public int id { get; set; } }
//Update public void Update(ProductBTO existingCateg) { UnitOfWork unitOfWork = new UnitOfWork(context); unitOfWork.ProductRepo.Update(existingCateg.ProductBTOToProduct()); unitOfWork.Save(); }
public IHttpActionResult Post(ProductBTO productBto) { if (!ModelState.IsValid) { return(BadRequest("Not a valid model")); } ProductLogic categ = new ProductLogic(); var model = categ.Create(productBto); return(CreatedAtRoute("DefaultApi", new { id = model.id }, model)); }
//Create public ProductBTO Create(ProductBTO bto) { UnitOfWork unitOfWork = new UnitOfWork(context); var response = unitOfWork.ProductRepo.Create(bto.ProductBTOToProduct()); unitOfWork.Save(); return(response.ProductToProductBTO()); //using (ProductRepo repo = new ProductRepo(context)) //{ // //De la Logique... // repo.Create(bto.ProductBTOToProduct()); //} //return bto; }
public IHttpActionResult Put(ProductBTO productBto) { if (!ModelState.IsValid) { return(BadRequest("Not a valid model")); } ProductLogic categ = new ProductLogic(); var existingCateg = categ.Retrieve(productBto.id); if (existingCateg != null) { categ.Update(productBto); } else { return(NotFound()); } return(Ok()); }
//ReadAll public List <ProductBTO> RetrieveAll() { UnitOfWork unitOfWork = new UnitOfWork(context); List <ProductBTO> Listbto = new List <ProductBTO>(); foreach (var item in unitOfWork.ProductRepo.RetrieveAll()) { ProductBTO btoToAdd = this.Retrieve(item.id); Listbto.Add(btoToAdd); } return(Listbto); //using (ProductRepo repo = new ProductRepo(context)) //{ // //De la Logique... // return RetrieveAll(); //} }