// GET: Sale/Delete/5 public ActionResult Delete(tblSale saleToDelete) { var d = instance.tblSales.Where(x => x.id == saleToDelete.id).FirstOrDefault(); instance.tblSales.Remove(d); instance.SaveChanges(); return(View("ViewSale")); }
public ActionResult Create([Bind(Exclude = "Id")] tblSale addDetails) { if (!ModelState.IsValid) { return(View()); } instance.tblSales.Add(addDetails); instance.SaveChanges(); return(RedirectToAction("ViewSale")); }
public ActionResult Edit(tblSale saleToEdit) { var orignalRecord = (from m in instance.tblSales where m.id == saleToEdit.id select m).First(); if (!ModelState.IsValid) { return(View(orignalRecord)); } instance.Entry(orignalRecord).CurrentValues.SetValues(saleToEdit); instance.SaveChanges(); return(RedirectToAction("ViewSale")); }
private void BtnSave_Click(object sender, EventArgs e) { tblSalesInvoice tb = new tblSalesInvoice(); tb.InvoiceNo = txtInvoiceNo.Text; tb.InvoiceDate = Convert.ToDateTime(txtInvoiceDate.Text); tb.GrandTotal = Convert.ToDecimal(txtGrandTotal.Text); tb.CustomerId = customerid; db.tblSalesInvoices.Add(tb); db.SaveChanges(); tblCustomerPayment tbvenpay = new tblCustomerPayment(); tbvenpay.CustomerId = customerid; tbvenpay.PaymentDate = Convert.ToDateTime(txtInvoiceDate.Text); tbvenpay.TotalAmount = Convert.ToDecimal(txtGrandTotal.Text); tbvenpay.PaymentAmount = Convert.ToDecimal(txtPaidAmount.Text); tbvenpay.RemainingAmount = Convert.ToDecimal(txtRemainingAmount.Text); tbvenpay.PaymentMode = rbdCash.Checked ? "Cash" : "Cheque"; db.tblCustomerPayments.Add(tbvenpay); if (db.SaveChanges() > 0) { foreach (DataGridViewRow dr in dataGridView1.Rows) { tblSale pur = new tblSale(); pur.SalesInvoiceId = tb.SalesInvoiceId; pur.ProductId = Convert.ToInt32(dr.Cells["colProductId"].Value); pur.Quantity = Convert.ToInt32(dr.Cells["colQuantity"].Value); pur.UnitPrice = Convert.ToDecimal(dr.Cells["colUnitPrice"].Value); pur.Total = Convert.ToDecimal(dr.Cells["colTotal"].Value); pur.SalesDate = Convert.ToDateTime(txtInvoiceDate.Text); pur.Tax = Convert.ToDecimal(dr.Cells["colTax"].Value); db.tblSales.Add(pur); if (db.SaveChanges() > 0) { tblStock tbst = db.tblStocks.Where(p => p.ProductId == pur.ProductId).FirstOrDefault(); if (tbst != null) { int puranoquantity = Convert.ToInt32(tbst.Quantity); tbst.Quantity = puranoquantity - Convert.ToInt32(dr.Cells["colQuantity"].Value); db.SaveChanges(); } } } } MessageBox.Show("Sales Done"); }
public IHttpActionResult ApproveAuctionAdmin([FromUri] int id, int adminid) { tblBidding tblBidding = db.tblBiddings.Find(id); tblBidding.ApprovalAdminId = adminid; tblCropRequest tblCropRequest = db.tblCropRequests.Find(tblBidding.RequestId); tblFarmer tblFarmer = db.tblFarmers.Find(tblCropRequest.FarmerId); tblSale tblSale = new tblSale(); tblSale.FarmerId = tblFarmer.FarmerId; tblSale.BidderId = tblBidding.BidderId; tblSale.Quantity = (int?)tblCropRequest.Quantity; tblSale.CropName = tblCropRequest.CropName; tblSale.MinSalePrice = tblBidding.InitialPrice; tblSale.TotalPrice = tblBidding.CurrentBidPrice; tblSale.SaleDate = DateTime.Now.Date; tblSale.ApprovalAdminId = adminid; db.Entry(tblBidding).State = EntityState.Modified; db.tblSales.Add(tblSale); db.SaveChanges(); return(Ok("OK")); }