public static bool UpdateProduct(COM.Product mProduct) { try { using (var ent = DB.Entity) { ent.Products.Attach(mProduct); var Entry = ent.Entry(mProduct); Entry.Property(ex => ex.Description).IsModified = true; Entry.Property(ex => ex.Price).IsModified = true; Entry.Property(ex => ex.PriceOff).IsModified = true; Entry.Property(ex => ex.StockCount).IsModified = true; Entry.Property(ex => ex.specification).IsModified = true; Entry.Property(ex => ex.Name).IsModified = true; Entry.Property(ex => ex.CatID).IsModified = true; Entry.Property(ex => ex.SubCatID).IsModified = true; ent.SaveChanges(); return(true); } } catch (Exception e) { Log.DoLog(COM.Action.UpdateProduct, mProduct.PID.ToString(), -100, e.Message); return(false); } }
public async Task <IHttpActionResult> PostUpdateProduct() { try { if (!Request.Content.IsMimeMultipartContent()) { return(Json(JsonConvert.SerializeObject("Exception dade: UnsupportedMediaType"))); } var filesReadToProvider = await Request.Content.ReadAsMultipartAsync(); ProductMorphy mProductMorphy = new ProductMorphy(); foreach (var itemContent in filesReadToProvider.Contents) { if (itemContent.Headers.ContentDisposition.Name == "Object" || itemContent.Headers.ContentDisposition.Name == "\"Object\"") { var jsonString = await itemContent.ReadAsStringAsync(); var serializer = new JavaScriptSerializer(); mProductMorphy = serializer.Deserialize <ProductMorphy>(jsonString); COM.Product mProduct = new COM.Product() { PID = mProductMorphy.PID, Brand = mProductMorphy.Brand, CatID = mProductMorphy.CatID, Description = mProductMorphy.Description, Name = mProductMorphy.Name, Price = mProductMorphy.Price, PriceOff = mProductMorphy.PriceOff, StockCount = mProductMorphy.StockCount, SubCatID = mProductMorphy.SubCatID, }; mProduct.specification = JsonConvert.SerializeObject(mProductMorphy.specification); bool ResAdd = BLL.Product.UpdateProduct(mProduct); if (!ResAdd) { return(Json(JsonConvert.SerializeObject("natoooneste to DB save beshe "))); } else { return(Json(JsonConvert.SerializeObject(ResAdd.ToString()))); } } } return(Json(JsonConvert.SerializeObject("az halghe biroon oomad toosh hich chizi naboode"))); } catch (Exception ee) { Log.DoLog(COM.Action.PostUpdateProduct, "UpdatePro", -100, ee.Message); return(Json(JsonConvert.SerializeObject("Exception dade: " + ee.Message))); } }
public static int AddProduct(COM.Product mProduct) { try { using (var ent = DB.Entity) { ent.Products.Add(mProduct); ent.SaveChanges(); return(mProduct.PID); } } catch (Exception e) { Log.DoLog(COM.Action.AddProduct, "NoName", -100, e.Message); return(-100); } }
public int AddProduct([FromBody] ProductMorphy NewProduct) { COM.Product product = new COM.Product() { Brand = NewProduct.Brand, CatID = NewProduct.CatID, Description = NewProduct.Description, Name = NewProduct.Name, Price = NewProduct.Price, PriceOff = NewProduct.PriceOff, StockCount = NewProduct.StockCount, SubCatID = NewProduct.SubCatID, }; product.specification = JsonConvert.SerializeObject(NewProduct.specification); return(BLL.Product.AddProduct(product)); }
public static bool RemoveProductByID(int PID) { try { using (var ent = DB.Entity) { COM.Product mProduct = new COM.Product() { PID = PID }; ent.Products.Count(); ent.Products.Attach(mProduct); ent.Products.Remove(mProduct); ent.SaveChanges(); } return(true); } catch { return(false); } }