public async Task <JsonResult> Create([FromBody] ModelForProductDetail bike) { if (!ModelState.IsValid) { return(Json(false)); } bool result = await Task.Run(() => repository.AddProduct(bike)); return(Json(result)); }
public async Task <JsonResult> ViewProductDetail(int?id) { if (!id.HasValue) { return(Json(false)); } ModelForProductDetail product = await Task.Run(() => repository.GetProductDetail(id.Value)); if (product == null) { return(Json(false)); } return(Json(product)); }
public bool AddProduct(ModelForProductDetail product) { try { int modelId = AddModel(product.Model); int descId = AddDescription(product.Description); AddProductModelDescription(modelId, descId); Product addedProduct = new Product() { Name = product.Name, ProductNumber = product.ProductNumber, ProductSubcategoryId = product.CategoryId, MakeFlag = true, FinishedGoodsFlag = true, Color = product.Color, SafetyStockLevel = 10, ReorderPoint = 10, StandardCost = product.ListPrice, ListPrice = product.ListPrice, Size = product.Size, Weight = product.Weight, SellStartDate = DateTime.Now, Rowguid = Guid.NewGuid(), ModifiedDate = DateTime.Now, ProductModelId = modelId }; context.Entry(addedProduct).State = EntityState.Added; context.SaveChanges(); return(true); } catch (Exception) { return(false); } }