public ActionResult Detail(int id) { STOCK _stockDetail = db.STOCKS.Find(id); List <StockModifyModel> vm = new List <StockModifyModel>(); string _productname = ""; if (_stockDetail.TYPE == 1 || _stockDetail.TYPE == 2) { _productname = db.FERTILIZERs.Where(s => s.OBJECTID == _stockDetail.PRODUCT_ID).FirstOrDefault().NAME; } if (_stockDetail.TYPE == 3) { TechnicalSPEC techSpec = JsonConvert.DeserializeObject <TechnicalSPEC>(_stockDetail.SPEC); _productname = db.TECHNIQUES.Where(s => s.OBJECTID == _stockDetail.PRODUCT_ID).FirstOrDefault().NAME + " " + techSpec.licenseplate; } if (_stockDetail.TYPE == 4 || _stockDetail.TYPE == 5) { CropSPEC cropSpec = JsonConvert.DeserializeObject <CropSPEC>(_stockDetail.SPEC); string CropName = db.CROP_SORT.Where(w => w.OBJECTID == cropSpec.CropSortID).FirstOrDefault().NAME; string CropRepreduktion = db.CROP_REPRODUCTION.Where(s => s.OBJECTID == cropSpec.CropRepreducsiya).FirstOrDefault().NAME; _productname = db.CROPs.Where(s => s.OBJECTID == _stockDetail.PRODUCT_ID).FirstOrDefault().NAME + " - " + CropName + " (" + CropRepreduktion + ")"; } foreach (var item in db.STOCKMODIFies.Where(s => s.STOCKITEMID == _stockDetail.OBJECTID).ToList()) { vm.Add(new StockModifyModel() { OBJECTID = item.OBJECTID, PRODUCTNAME = _productname, DESTINATIONSTATUS = (item.STATUSID == 1) ? "Medaxil" : "Mexaric", MODIFYDATE = item.MODIFYDATE.Value.ToString("MM-dd-yyyy HH:mm"), QUANTITY = item.QUANTITY.ToString(), PLACENAME = item.STOCKPLACE.NAME, WORKERNAME = item.Worker.Name + " " + item.Worker.Surname }); } return(View(vm)); }
// GET: AgroPark/STOCK public ActionResult Index() { var Stock = db.STOCKS.ToList(); List <StockTotalView> stockView = new List <StockTotalView>(); foreach (var item in db.STOCKS.ToList()) { if (item.TYPE == 1) { stockView.Add(new StockTotalView() { OBJECTID = item.OBJECTID, CATEGORY = "Dərman", PRODUCTNAME = db.FERTILIZERs.Where(s => s.OBJECTID == item.PRODUCT_ID).FirstOrDefault().NAME + " (" + db.FERTILIZERs.Where(s => s.OBJECTID == item.PRODUCT_ID).FirstOrDefault().MAIN_COMPONENTS.NAME + ")", QUANTITY = (decimal)item.QUANTITY }); } if (item.TYPE == 2) { stockView.Add(new StockTotalView() { OBJECTID = item.OBJECTID, CATEGORY = "Gübrə", PRODUCTNAME = db.FERTILIZERs.Where(s => s.OBJECTID == item.PRODUCT_ID).FirstOrDefault().NAME + " (" + db.FERTILIZERs.Where(s => s.OBJECTID == item.PRODUCT_ID).FirstOrDefault().MAIN_COMPONENTS.NAME + ")", QUANTITY = (decimal)item.QUANTITY }); } if (item.TYPE == 3) { TechnicalSPEC techSpec = JsonConvert.DeserializeObject <TechnicalSPEC>(item.SPEC); stockView.Add(new StockTotalView() { OBJECTID = item.OBJECTID, CATEGORY = db.TECHNIQUES.Where(s => s.OBJECTID == item.PRODUCT_ID).FirstOrDefault().TECHNIQUE_TYPE.NAME, PRODUCTNAME = db.TECHNIQUES.Where(s => s.OBJECTID == item.PRODUCT_ID).FirstOrDefault().NAME + " " + techSpec.licenseplate, QUANTITY = (decimal)item.QUANTITY }); } if (item.TYPE == 4) { CropSPEC _cropspec = JsonConvert.DeserializeObject <CropSPEC>(item.SPEC); string CropName = db.CROP_SORT.Where(w => w.OBJECTID == _cropspec.CropSortID).FirstOrDefault().NAME; string CropRepreduktion = db.CROP_REPRODUCTION.Where(s => s.OBJECTID == _cropspec.CropRepreducsiya).FirstOrDefault().NAME; string _productname = db.CROPs.Where(s => s.OBJECTID == item.PRODUCT_ID).FirstOrDefault().NAME + " - " + CropName + " (" + CropRepreduktion + ")"; stockView.Add(new StockTotalView() { OBJECTID = item.OBJECTID, CATEGORY = "Dənli bitki", PRODUCTNAME = _productname, QUANTITY = (decimal)item.QUANTITY }); } if (item.TYPE == 5) { CropSPEC _cropspec = JsonConvert.DeserializeObject <CropSPEC>(item.SPEC); string CropName = db.CROP_SORT.Where(w => w.OBJECTID == _cropspec.CropSortID).FirstOrDefault().NAME; string CropRepreduktion = db.CROP_REPRODUCTION.Where(s => s.OBJECTID == _cropspec.CropRepreducsiya).FirstOrDefault().NAME; string _productname = db.CROPs.Where(s => s.OBJECTID == item.PRODUCT_ID).FirstOrDefault().NAME + " - " + CropName + " (" + CropRepreduktion + ")"; stockView.Add(new StockTotalView() { OBJECTID = item.OBJECTID, CATEGORY = "Meyvə", PRODUCTNAME = _productname, QUANTITY = (decimal)item.QUANTITY }); } } return(View(stockView)); }
public ActionResult Create(StockViewModel _stock, List <string> SPECS) { if (Session["HaveLogin"] == null) { return(RedirectToAction("Index", "Login")); } var logineduser = (User)Session["HaveLogin"]; if (true) { if (_stock.TYPE == 1 || _stock.TYPE == 2) { if (_stock.STATUSID == 1) { var exsistItem = db.STOCKS.Where(s => s.PRODUCT_ID == _stock.PRODUCT_ID).FirstOrDefault(); if (exsistItem == null) { STOCK _newStock = new STOCK(); _newStock.PRODUCT_ID = _stock.PRODUCT_ID; _newStock.TYPE = (short)_stock.TYPE; _newStock.QUANTITY = _stock.QUANTITY; _newStock.SPEC = ""; db.STOCKS.Add(_newStock); db.SaveChanges(); STOCKMODIFY _newmodify = new STOCKMODIFY(); _newmodify.STOCKITEMID = _newStock.OBJECTID; _newmodify.STATUSID = _stock.STATUSID; _newmodify.MODIFYDATE = DateTime.Now; _newmodify.QUANTITY = _stock.QUANTITY; _newmodify.PLACEID = _stock.PLACEID; _newmodify.WORKERID = logineduser.Worker.ID; db.STOCKMODIFies.Add(_newmodify); db.SaveChanges(); return(RedirectToAction("Index", "STOCK")); } else { exsistItem.QUANTITY += _stock.QUANTITY; db.Entry(exsistItem).State = EntityState.Modified; db.SaveChanges(); STOCKMODIFY _newmodify = new STOCKMODIFY(); _newmodify.STOCKITEMID = exsistItem.OBJECTID; _newmodify.STATUSID = _stock.STATUSID; _newmodify.MODIFYDATE = DateTime.Now; _newmodify.QUANTITY = _stock.QUANTITY; _newmodify.PLACEID = _stock.PLACEID; _newmodify.WORKERID = logineduser.Worker.ID; db.STOCKMODIFies.Add(_newmodify); db.SaveChanges(); return(RedirectToAction("Index", "STOCK")); } } if (_stock.STATUSID == 2) { var exsistItem = db.STOCKS.Where(s => s.OBJECTID == _stock.PRODUCT_ID).FirstOrDefault(); if (exsistItem.QUANTITY >= _stock.QUANTITY) { exsistItem.QUANTITY -= _stock.QUANTITY; db.Entry(exsistItem).State = EntityState.Modified; db.SaveChanges(); STOCKMODIFY _newmodify = new STOCKMODIFY(); _newmodify.STOCKITEMID = exsistItem.OBJECTID; _newmodify.STATUSID = _stock.STATUSID; _newmodify.MODIFYDATE = DateTime.Now; _newmodify.QUANTITY = _stock.QUANTITY; _newmodify.PLACEID = _stock.PLACEID; _newmodify.WORKERID = logineduser.Worker.ID; db.STOCKMODIFies.Add(_newmodify); db.SaveChanges(); return(RedirectToAction("Index", "STOCK")); } else { //anbarda kifayyet qeder ehtiyat yoxdu. //not enough product in stock ViewBag.Techicals = db.TECHNIQUE_TYPE.ToList(); ViewBag.STOCKPLACES = db.STOCKPLACES.ToList(); return(View()); } } } if (_stock.TYPE == 3) { if (_stock.STATUSID == 1) { STOCK _newStock = new STOCK(); _newStock.PRODUCT_ID = _stock.PRODUCT_ID; _newStock.TYPE = (short)_stock.TYPE; _newStock.QUANTITY = _stock.QUANTITY; TechnicalSPEC techspec = new TechnicalSPEC(); techspec.licenseplate = SPECS[0]; techspec.color = SPECS[1]; var ResuptSpec = JsonConvert.SerializeObject(techspec); _newStock.SPEC = ResuptSpec; db.STOCKS.Add(_newStock); db.SaveChanges(); STOCKMODIFY _newmodify = new STOCKMODIFY(); _newmodify.STOCKITEMID = _newStock.OBJECTID; _newmodify.STATUSID = _stock.STATUSID; _newmodify.MODIFYDATE = DateTime.Now; _newmodify.QUANTITY = _stock.QUANTITY; _newmodify.PLACEID = _stock.PLACEID; _newmodify.WORKERID = logineduser.Worker.ID; db.STOCKMODIFies.Add(_newmodify); db.SaveChanges(); return(RedirectToAction("Index", "STOCK")); } if (_stock.STATUSID == 2) { STOCK exsist = db.STOCKS.Find(_stock.PRODUCT_ID); exsist.QUANTITY -= 1; db.SaveChanges(); STOCKMODIFY _newmodify = new STOCKMODIFY(); _newmodify.STOCKITEMID = exsist.OBJECTID; _newmodify.STATUSID = _stock.STATUSID; _newmodify.MODIFYDATE = DateTime.Now; _newmodify.QUANTITY = _stock.QUANTITY; _newmodify.PLACEID = _stock.PLACEID; _newmodify.WORKERID = logineduser.Worker.ID; db.STOCKMODIFies.Add(_newmodify); db.SaveChanges(); return(RedirectToAction("Index", "STOCK")); } return(Content("test true")); } if (_stock.TYPE == 4 || _stock.TYPE == 5) { //medaxil olanda if (_stock.STATUSID == 1) { int cropID = Convert.ToInt32(SPECS[0]); int CropSortID = Convert.ToInt32(SPECS[1]); CropSPEC cropspec = new CropSPEC(); cropspec.CropSortID = _stock.PRODUCT_ID; cropspec.CropRepreducsiya = CropSortID; string CropSpecial = JsonConvert.SerializeObject(cropspec); var exsistItem = db.STOCKS.Where(s => s.PRODUCT_ID == cropID && s.SPEC == CropSpecial).FirstOrDefault(); //eger anbarda yolxdursa yenisin elave edir if (exsistItem == null) { STOCK newCropStok = new STOCK(); newCropStok.PRODUCT_ID = cropID; newCropStok.TYPE = (short)_stock.TYPE; newCropStok.QUANTITY = _stock.QUANTITY; newCropStok.SPEC = CropSpecial; db.STOCKS.Add(newCropStok); db.SaveChanges(); STOCKMODIFY _newmodify = new STOCKMODIFY(); _newmodify.STOCKITEMID = newCropStok.OBJECTID; _newmodify.STATUSID = _stock.STATUSID; _newmodify.MODIFYDATE = DateTime.Now; _newmodify.QUANTITY = _stock.QUANTITY; _newmodify.PLACEID = _stock.PLACEID; _newmodify.WORKERID = logineduser.Worker.ID; db.STOCKMODIFies.Add(_newmodify); db.SaveChanges(); return(RedirectToAction("Index", "STOCK")); } else// eger umumi anbarda bele bir mehsul varsa artiq onun uzerine elave edir. { exsistItem.QUANTITY += _stock.QUANTITY; db.Entry(exsistItem).State = EntityState.Modified; db.SaveChanges(); STOCKMODIFY _newmodify = new STOCKMODIFY(); _newmodify.STOCKITEMID = exsistItem.OBJECTID; _newmodify.STATUSID = _stock.STATUSID; _newmodify.MODIFYDATE = DateTime.Now; _newmodify.QUANTITY = _stock.QUANTITY; _newmodify.PLACEID = _stock.PLACEID; _newmodify.WORKERID = logineduser.Worker.ID; db.STOCKMODIFies.Add(_newmodify); db.SaveChanges(); return(RedirectToAction("Index", "STOCK")); } } if (_stock.STATUSID == 2) { var exsistItem = db.STOCKS.Where(s => s.OBJECTID == _stock.PRODUCT_ID).FirstOrDefault(); if (exsistItem.QUANTITY >= _stock.QUANTITY) { exsistItem.QUANTITY -= _stock.QUANTITY; db.Entry(exsistItem).State = EntityState.Modified; db.SaveChanges(); STOCKMODIFY _newmodify = new STOCKMODIFY(); _newmodify.STOCKITEMID = exsistItem.OBJECTID; _newmodify.STATUSID = _stock.STATUSID; _newmodify.MODIFYDATE = DateTime.Now; _newmodify.QUANTITY = _stock.QUANTITY; _newmodify.PLACEID = _stock.PLACEID; _newmodify.WORKERID = logineduser.Worker.ID; db.STOCKMODIFies.Add(_newmodify); db.SaveChanges(); return(RedirectToAction("Index", "STOCK")); } else { //anbarda kifayyet qeder ehtiyat yoxdu. //not enough product in stock ViewBag.Techicals = db.TECHNIQUE_TYPE.ToList(); ViewBag.STOCKPLACES = db.STOCKPLACES.ToList(); return(View()); } } } } ViewBag.Techicals = db.TECHNIQUE_TYPE.ToList(); ViewBag.STOCKPLACES = db.STOCKPLACES.ToList(); return(View()); }