public JsonResult ChangeStatus(int id) { var purchaseOrder = db.PurchaseOrders.Find(id); try { purchaseOrder.PurchaseOrderStatusId = db.PurchaseOrderStatus.FirstOrDefault(p => p.Name.ToUpper().Equals("ACCEPTED")).Id; db.Entry(purchaseOrder).State = EntityState.Modified; var stockService = new StockService(db); stockService.ReceiveOrder(id); return(Json(new { Result = true, Message = "Product Stock updated successful" })); } catch (Exception ex) { var message = new StringBuilder(); message.AppendLine(ex.Message); Exception innerException = ex.InnerException; while (innerException != null) { message.AppendLine(string.IsNullOrWhiteSpace(innerException.Message) ? string.Empty : innerException.Message); innerException = innerException.InnerException; } return(Json(new { Result = false, Message = message.ToString() })); } }
public JsonResult Update(string data) { try { var model = JsonConvert.DeserializeObject <SalesDetailViewModel>(data); var invoice = db.Invoices.Find(model.Invoice.Id); invoice.InvoiceStatusId = (int)InvoiceStatus.InProgress; invoice.IsDelivery = model.Invoice.IsDelivery; invoice.DeliveryFee = model.Invoice.DeliveryFee; invoice.SNAP = model.Invoice.SNAP; invoice.Date = model.Invoice.Date; invoice.Address = model.Invoice.Address; invoice.InstalationFee = model.Invoice.InstalationFee; invoice.Subtotal = model.Invoice.Subtotal; invoice.Total = model.Invoice.Total; if (model.Invoice.Created > DateTime.MinValue) { invoice.Created = model.Invoice.Created; } db.Entry(invoice).State = EntityState.Modified; db.SaveChanges(); // foreach (var detail in model.Invoice.InvoiceDetails) { db.Entry(detail).State = EntityState.Modified; } var currentPayments = db.Payments.Where(p => p.InvoiceId == model.Invoice.Id); foreach (Payment payment in model.Invoice.Payments.Where(p => p.UserId == null)) { payment.UserId = this.User.Identity.GetUserId(); } db.Payments.RemoveRange(currentPayments); db.Payments.AddRange(model.Invoice.Payments); db.SaveChanges(); return(Json(new { Result = true, Message = string.Format(" Invoice ({0}) updated successful", model.Invoice.Id), Data = new { InvoiceId = model.Invoice.Id } })); } catch (Exception ex) { var message = new StringBuilder(); message.AppendLine(ex.Message); Exception innerException = ex.InnerException; while (innerException != null) { message.AppendLine(string.IsNullOrWhiteSpace(innerException.Message) ? string.Empty : innerException.Message); innerException = innerException.InnerException; } return(Json(new { Result = false, Message = message.ToString() })); } }
public JsonResult ConvertToInvoice(int id) { try { var invoice = db.Invoices.Find(id); invoice.InvoiceStatusId = 2; db.Entry(invoice).State = EntityState.Modified; db.SaveChanges(); return(Json(new { Result = true, Message = "Convert Estimate to Invoice success", InvoiceId = id })); } catch (Exception ex) { return(Json(new { Result = false, Message = ex.Message })); } }
public void ReceiveOrder(int orderId) { var order = db.PurchaseOrders .Include(po => po.PurchaseOrderDetails) .FirstOrDefault(po => po.Id == orderId); foreach (var detail in order.PurchaseOrderDetails) { var stockProduct = db.Stocks.FirstOrDefault(s => s.ProductId == detail.ProductId); if (stockProduct == null) { stockProduct = new Stock() { ProductId = detail.ProductId, LocationId = 1,//TODO: StockQuantity = detail.Quantity }; db.Stocks.Add(stockProduct); } else { stockProduct.StockQuantity += detail.Quantity; db.Entry(stockProduct).State = EntityState.Modified; } } db.SaveChanges(); }
public ActionResult Edit([Bind(Include = "Id,FirstName,MiddleName,LastName,Email,Phone,Address")] Client client) { if (ModelState.IsValid) { db.Entry(client).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(client)); }
public ActionResult Edit([Bind(Include = "Id,Name")] InvoiceStatu invoiceStatu) { if (ModelState.IsValid) { db.Entry(invoiceStatu).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(invoiceStatu)); }
public ActionResult Edit([Bind(Include = "Key,Value")] Config config) { if (ModelState.IsValid) { db.Entry(config).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(config)); }
public ActionResult Edit([Bind(Include = "Id,BusinessName,ContactName,Email,Phone,Address,WorkingHours,IsActive")] Provider provider) { if (ModelState.IsValid) { db.Entry(provider).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(provider)); }
public ActionResult Edit([Bind(Include = "Id,Name")] PaymentType paymentType) { if (ModelState.IsValid) { db.Entry(paymentType).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(paymentType)); }
public ActionResult Edit([Bind(Include = "Id,Code,Name,Display,SellPrice,PurchasePrice,Max,Min,ProviderId,CategoryId")] Product product) { if (ModelState.IsValid) { db.Entry(product).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ProviderId = new SelectList(db.Providers .ToList() .Select(p => new { Id = p.Id, Name = p.BusinessName }), "Id", "Name", product.ProviderId); ViewBag.CategoryId = new SelectList(db.Categories, "Id", "Name", product.CategoryId) .ToList(); return(View(product)); }
public ActionResult Edit([Bind(Include = "Id,Name,StorageId")] Location location) { if (ModelState.IsValid) { db.Entry(location).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.StorageId = new SelectList(db.Storages, "Id", "Name", location.StorageId); return(View(location)); }
public ActionResult Edit([Bind(Include = "Id,Name,BranchId")] Storage storage) { if (ModelState.IsValid) { db.Entry(storage).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.BranchId = new SelectList(db.Branches, "Id", "Name", storage.BranchId); return(View(storage)); }
public ActionResult Edit([Bind(Include = "Id,Text,UserId,ClientId,Active")] ClientNote clientNote) { if (ModelState.IsValid) { db.Entry(clientNote).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.UserId = new SelectList(db.AspNetUsers, "Id", "FullName", clientNote.UserId); ViewBag.ClientId = new SelectList(db.Clients, "Id", "FullName", clientNote.ClientId); return(View(clientNote)); }
public void ExtractFromStock(IEnumerable <InvoiceDetail> details) { if (details == null) { throw new ArgumentNullException("The list of products can't be empty"); } foreach (var detail in details) { if (db.Stocks.Any(s => s.ProductId == detail.ProductId)) { var stockProduct = db.Stocks.FirstOrDefault(s => s.ProductId == detail.ProductId); if ((stockProduct.StockQuantity - detail.Quantity) < 0) { throw new Exception(string.Format("There is not enough product for attend to this order(Product Quantity{0}", stockProduct.StockQuantity)); } stockProduct.StockQuantity -= detail.Quantity - detail.InOrder; db.Entry(stockProduct).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } } }
public JsonResult Edit([Bind(Include = "Id,Type,Date,Number,Name,Amount,ProviderId")] Supply supply) { try { db.Entry(supply).State = EntityState.Modified; db.SaveChanges(); return(Json(new { Result = true, Data = supply }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new { Result = false, Message = ex.Message }, JsonRequestBehavior.AllowGet)); } }
public JsonResult Edit([Bind(Include = "Id,Type,Date,Number,Name,Split,OriginalAmount,PaidAmount,Description")] Utility utility) { try { db.Entry(utility).State = EntityState.Modified; db.SaveChanges(); return(Json(new { Result = true, Data = utility }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new { Result = false, Message = ex.Message }, JsonRequestBehavior.AllowGet)); } }