public IHttpActionResult Put(ProductModel product) { Product productTemp = AdminDomain.GetBy(product.ProductId); productTemp.ProductName = product.ProductName; productTemp.ProductDescription = product.ProductDescription; productTemp.Quantity = product.Quantity; productTemp.Cost = product.Cost; productTemp.Comment = product.Comment; var newSubCategoryId = Uow.Repository <SubCategory>().FirstOrDefault(c => c.SubCategoryName == product.SubCategory); productTemp.SubCategoryId = newSubCategoryId.SubCategoryId; var newDiscountId = Uow.Repository <Discount>().FirstOrDefault(c => c.Percentage == product.Discount); productTemp.DiscountId = newDiscountId.DiscountId; var newBrandId = Uow.Repository <Brand>().FirstOrDefault(c => c.BrandName == product.Brand); productTemp.BrandId = newBrandId.BrandId; var newProduct = Uow.Repository <Product>().FirstOrDefault(c => c.ProductId == product.ProductId); var fil = new FileCollection() { url = (newProduct.ProductImage).BaseStringJpeg() }; if (product.ProductImageBaseString == fil.url) { productTemp.ProductImage = newProduct.ProductImage; } else { productTemp.ProductImage = product.ProductImage; } return(Ok(AdminDomain.PutProduct(productTemp))); }
public IHttpActionResult Get(int id) { var product = AdminDomain.GetBy(id); ProductModel productTemp = new ProductModel(); productTemp.ProductId = product.ProductId; productTemp.ProductName = product.ProductName; productTemp.ProductDescription = product.ProductDescription; productTemp.Quantity = product.Quantity; var date = product.ProductDate.ToString("d"); productTemp.ProductDateBaseString = date; var newSubCategory = Uow.Repository <SubCategory>().FirstOrDefault(c => c.SubCategoryId == product.SubCategoryId); productTemp.SubCategory = newSubCategory.SubCategoryName; var newDiscount = Uow.Repository <Discount>().FirstOrDefault(c => c.DiscountId == product.DiscountId); productTemp.Discount = newDiscount.Percentage; var newBrand = Uow.Repository <Brand>().FirstOrDefault(c => c.BrandId == product.BrandId); productTemp.Brand = newBrand.BrandName; productTemp.Cost = product.Cost; productTemp.Comment = product.Comment; var fil = new FileCollection() { url = (product.ProductImage).BaseStringJpeg() }; productTemp.ProductImageBaseString = fil.url; return(Ok(productTemp)); }