public static void UpdateItem(int Id, inventryItem itm) { ServicesPortalApiEntities db = new ServicesPortalApiEntities(); var data = db.inventryItems.Where(m => m.id == Id).FirstOrDefault(); if (data != null) { data.AvgSalePrice = itm.AvgSalePrice; data.AvgPurchasePrice = itm.AvgPurchasePrice; data.BottemPrice = itm.BottemPrice; data.InternalPrice = itm.InternalPrice; data.TradesPrice = itm.TradesPrice; data.QoutedPrice = itm.QoutedPrice; data.SalesDescription = itm.SalesDescription; data.PurchaseDescription = itm.PurchaseDescription; } db.SaveChanges(); }
public ActionResult Save(inventryItem I) { if (I.id > 0) { InventoryHandler.UpdateItem(I.id, I); db.SaveChanges(); return(RedirectToAction("List")); } else { int itemID; var listt = db.inventryItems.ToList(); if (listt.Count != 0) { var lastrecord = listt.Last(); itemID = lastrecord.id + 1; } else { itemID = 1; } var catid = db.SubCategories.Where(m => m.id == I.CatID).FirstOrDefault(); int CateGoryID = catid.CatId; var TempItemAttributes = db.TempItermAttributes.Where(m => m.CatID == CateGoryID & m.SubCatID == I.CatID & m.ModelID == I.ModelID).ToList(); var ItemAttributes = db.ItemAttributes.Where(m => m.CatID == CateGoryID & m.SubCatID == I.CatID & m.ModelID == I.ModelID).ToList(); foreach (var data in TempItemAttributes) { status = ItemAttributes.Any(m => m.AttributeValue == data.AttributeValue); if (status == false) { status = false; break; } } if (status != true) { Session["itmfid"] = itemID; string path = null; if (Request.Files != null && Request.Files.Count > 0) { foreach (string f in Request.Files) { HttpPostedFileBase file = Request.Files[f]; if (file.FileName == "") { path = "/Files/user.jpg"; } else { string webpath = "/Files/" + DateTime.Now.Ticks + file.FileName.Substring(file.FileName.LastIndexOf(".")); file.SaveAs(Request.MapPath(webpath)); //physical path is required to save a file path = webpath; } } } I.Image = path; I.id = itemID; I.CompanyId = Convert.ToInt32(Session["Cid"]); I.CreatedBy = Session["HAname"].ToString(); I.CreatedOn = DateTime.Now; db.inventryItems.Add(I); db.SaveChanges(); return(RedirectToAction("TemDataMove")); } else { TempData["itemalready"] = "Item Is already exist"; return(RedirectToAction("NewInv")); } } }