public ActionResult Edit(SupplierPriceLineItem lineItem) { try { var offer = _context.OfferMasters.FirstOrDefault(o => o.Id == lineItem.OfferMasterId); var EditedItem = _context.SupplierPriceLineItems.Include("LineItem").First(x => x.Id == lineItem.Id); if (ModelState.IsValid) { EditedItem.SupplierPrice = lineItem.SupplierPrice; EditedItem.Vat = lineItem.Vat; EditedItem.Currency = lineItem.Currency; EditedItem.Comment = lineItem.Comment; EditedItem.IsOldPrice = false; EditedItem.UpdateDate = DateTime.Now; EditedItem.TurkishDescription = lineItem.TurkishDescription; _context.SaveChanges(); return(RedirectToAction("Offer", new { id = offer.OfferId })); } ViewBag.OfferId = offer.OfferId; return(View(EditedItem)); } catch (Exception e) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, e.Message)); } }
private async Task Createsupplierlineitems(LineItemSupplier lineItemSupplier, int masterid) { var suplineitem = await _context.SupplierPriceLineItems.Include("OfferMaster").Include("LineItem").FirstOrDefaultAsync(x => x.LineItemId == lineItemSupplier.LineItemId && x.OfferMasterId == masterid).ConfigureAwait(true); if (suplineitem == null) { //will be added if supplier has price var lastpricelist = await _context.SupplierPriceLineItems.Include("OfferMaster").Include("LineItem").Where(l => l.OfferMaster.SupplierId == lineItemSupplier.SupplierId && l.LineItem.Impa == lineItemSupplier.LineItem.Impa && l.SupplierPrice != 0).OrderBy(l => l.CreatedDate).Distinct().ToListAsync().ConfigureAwait(true); var supplierLineItem = new SupplierPriceLineItem { OfferMasterId = masterid, LineItemId = lineItemSupplier.LineItemId, CreatedDate = DateTime.Now.Date }; if (lastpricelist.Count > 0) { var lastoffer = lastpricelist[0]; supplierLineItem.Currency = lastoffer.Currency; supplierLineItem.Vat = lastoffer.Vat; supplierLineItem.Comment = lastoffer.Comment; supplierLineItem.SupplierPrice = lastoffer.SupplierPrice; supplierLineItem.OldPriceDate = lastoffer.CreatedDate; supplierLineItem.IsOldPrice = true; supplierLineItem.TurkishDescription = lastoffer.TurkishDescription; } _context.SupplierPriceLineItems.Add(supplierLineItem); await _context.SaveChangesAsync(); } }
public ActionResult AddNewSupplier(int fileid, int lineitemid, string lineitemimpa, string supplierid, string price, int vat, string currency, string remark) { try { var lineitem = _context.LineItems.FirstOrDefault(l => l.Id == lineitemid); int referanceno = lineitem.ReferanceNumberId; var sup = _context.Suppliers.FirstOrDefault(s => s.Id == supplierid); //check master and add supplier var supplier = new LineItemSupplier { LineItemId = lineitemid, SupplierId = sup.Id, SupplierName = sup.SupplierName }; _context.LineItemSuppliers.Add(supplier); _context.SaveChanges(); int masterid = 0; var offerid = GetStringSha256Hash(fileid + "/-/" + sup.Id); var offer = _context.OfferMasters.FirstOrDefault(x => x.OfferId == offerid); //offer master save if (offer == null) { var offermaster = new OfferMaster { OfferId = offerid, FileId = fileid, SupplierId = sup.Id }; _context.OfferMasters.Add(offermaster); _context.SaveChanges(); masterid = offermaster.Id; } else { masterid = offer.Id; } // suplineitem var supplierLineItem = new SupplierPriceLineItem { OfferMasterId = masterid, LineItemId = supplier.LineItemId, CreatedDate = DateTime.Now.Date, Vat = vat, Comment = remark, SupplierPrice = Convert.ToDecimal(price), Currency = currency }; _context.SupplierPriceLineItems.Add(supplierLineItem); _context.SaveChanges(); // supplier select var lineitemsupplier = _context.ViewSupplierPriceLineItems.Include("OfferMaster").FirstOrDefault(s => s.Id == supplierLineItem.Id); if (lineitemsupplier != null) { lineitem.SelectedSupplierName = lineitemsupplier.SupplierName; lineitem.SelectedSupplierCurrency = lineitemsupplier.Currency; lineitem.SelectedSupplierId = lineitemsupplier.OfferMaster.SupplierId; lineitem.SelectedSupplierPrice = lineitemsupplier.SupplierPrice; lineitem.SelectedSupplierRemark = lineitemsupplier.Comment; lineitem.SelectedSupplierCalculatedPrice = lineitemsupplier.RealPrice; lineitem.IsWareHouseSelected = false; _context.SaveChanges(); } return(Json(true)); } catch (Exception e) { return(Json(false)); } }
public async Task AddDefinedSuppliers(string impa, int itemid, int fileid) { try { var suppliers = _context.LineItemSuppliers.Where(x => x.LineItem.Impa == impa).GroupBy(x => x.SupplierId) .Select(g => new { g.FirstOrDefault().SupplierId, g.FirstOrDefault().SupplierName }) .ToListAsync(); foreach (var sup in await suppliers) { var supplier = new LineItemSupplier { LineItemId = itemid, SupplierId = sup.SupplierId, SupplierName = sup.SupplierName }; _context.LineItemSuppliers.Add(supplier); _context.SaveChanges(); int masterid = 0; var offerid = GetStringSha256Hash(fileid + "/-/" + sup.SupplierId); var offer = _context.OfferMasters.FirstOrDefault(x => x.OfferId == offerid); //offer master save if (offer == null) { var offermaster = new OfferMaster { OfferId = offerid, FileId = fileid, SupplierId = sup.SupplierId }; masterid = offermaster.Id; _context.OfferMasters.Add(offermaster); _context.SaveChanges(); } else { masterid = offer.Id; } // suplineitem var lastpricelist = await _context.SupplierPriceLineItems.Include("OfferMaster").Include("LineItem").Where(l => l.OfferMaster.SupplierId == supplier.SupplierId && l.LineItem.Impa == supplier.LineItem.Impa && l.SupplierPrice != 0).OrderBy(l => l.CreatedDate).Distinct().ToListAsync().ConfigureAwait(true); var supplierLineItem = new SupplierPriceLineItem { OfferMasterId = masterid, LineItemId = supplier.LineItemId, CreatedDate = DateTime.Now.Date }; if (lastpricelist.Count > 0) { var lastoffer = lastpricelist[0]; supplierLineItem.Currency = lastoffer.Currency; supplierLineItem.Vat = lastoffer.Vat; supplierLineItem.Comment = lastoffer.Comment; supplierLineItem.SupplierPrice = lastoffer.SupplierPrice; supplierLineItem.OldPriceDate = lastoffer.CreatedDate; supplierLineItem.IsOldPrice = true; } _context.SupplierPriceLineItems.Add(supplierLineItem); await _context.SaveChangesAsync(); } } catch (Exception) { throw; } }