public ActionResult Create(Employee employee) { if (ModelState.IsValid) { db.Employees.Add(employee); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(employee)); }
public IActionResult NewLine(int DeliveryId, string Description, double Price, int Quantity, int InvoiceId) { InvoiceLine returnVal = new InvoiceLine(); returnVal.InvoiceId = InvoiceId; returnVal.DeliveryId = DeliveryId; returnVal.CreationDate = DateTime.Now; returnVal.Description = Description; returnVal.Quantity = Quantity; returnVal.Price = Price; _context.InvoiceLine.Add(returnVal); _context.SaveChanges(); return(Json(returnVal)); }
public static void Initialize(MvcAppContext context) { context.Database.EnsureCreated(); // Look for any students. if (context.Deliveries.Any()) { return; // DB has been seeded } var deliveries = new List <Delivery>(); var tuesdays = GetDatesByDayOfWeek(2018, DayOfWeek.Tuesday); var thursdays = GetDatesByDayOfWeek(2018, DayOfWeek.Thursday); foreach (var day in tuesdays) { deliveries.Add(new Delivery { Date = day, Status = FacturationWebSite.Models.Enum.DeliveryStatus.Pending }); } foreach (var day in thursdays) { deliveries.Add(new Delivery { Date = day, Status = FacturationWebSite.Models.Enum.DeliveryStatus.Pending }); } foreach (Delivery d in deliveries) { context.Deliveries.Add(d); } context.SaveChanges(); }
public IActionResult NewLine(string Barcode, int DeliveryId) { ReturnObject returnVal = new ReturnObject(); int barcodeValue = Int32.Parse(Barcode); var barcode = _context.Barcode.SingleOrDefault(b => b.BarcodeId == barcodeValue); if (barcode != null) { var startMonth = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1); var endMonth = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1).AddMonths(1).AddDays(-1); var invoice = _context.Invoice.SingleOrDefault(i => i.CustomerId == barcode.CustomerId && i.StartPeriod == startMonth.ToString("dd/MM/yyyy") && i.EndPeriod == endMonth.ToString("dd/MM/yyyy")); var product = _context.Product.SingleOrDefault(p => p.ProductId == barcode.ProductId); double?price; var customer_price = _context.CustomerPrice.SingleOrDefault(cp => cp.CustomerId == barcode.CustomerId && cp.ProductId == barcode.ProductId); if (customer_price == null) { price = product.Price; } else { price = customer_price.Price; } if (invoice != null) { var invoiceLine = _context.InvoiceLine.SingleOrDefault(il => (il.DeliveryId == DeliveryId) && (barcode.ProductId == il.ProductId) && il.InvoiceId == invoice.InvoiceId); if (invoiceLine == null) { invoiceLine = new InvoiceLine(); invoiceLine.InvoiceId = invoice.InvoiceId; invoiceLine.Price = price.Value; invoiceLine.ProductId = barcode.ProductId; invoiceLine.Quantity = 1; invoiceLine.Description = product.Description; invoiceLine.DeliveryId = DeliveryId; invoiceLine.CreationDate = DateTime.Now; _context.InvoiceLine.Add(invoiceLine); _context.SaveChanges(); returnVal.successMessage = String.Format("Ligne ajoutée dans la facture ref {0} pour le produit {1} quantité : {2} ", invoice.Ref, product.Description, invoiceLine.Quantity); returnVal.errorCode = 0; returnVal.errorMessage = ""; } else { invoiceLine.Quantity = invoiceLine.Quantity + 1; _context.Update(invoiceLine); _context.SaveChanges(); returnVal.successMessage = String.Format("Ligne mise à jour dans la facture ref {0} pour le produit {1} - nouvelle quantité : {2} ", invoice.Ref, product.Description, invoiceLine.Quantity); returnVal.errorCode = 0; returnVal.errorMessage = ""; } } else { invoice = new Invoice(); invoice.Ref = GetInvoiceRef(); invoice.StartPeriod = startMonth.ToString("dd/MM/yyyy"); invoice.EndPeriod = endMonth.ToString("dd/MM/yyyy"); invoice.CustomerId = barcode.CustomerId; invoice.CreationDate = DateTime.Now; _context.Invoice.Add(invoice); _context.SaveChanges(); var invoiceLine = new InvoiceLine(); invoiceLine = new InvoiceLine(); invoiceLine.InvoiceId = invoice.InvoiceId; invoiceLine.Price = price.Value; invoiceLine.ProductId = barcode.ProductId; invoiceLine.Quantity = 1; invoiceLine.Description = product.Description; invoiceLine.DeliveryId = DeliveryId; invoiceLine.CreationDate = DateTime.Now; _context.InvoiceLine.Add(invoiceLine); _context.SaveChanges(); returnVal.successMessage = String.Format("Ligne ajoutée dans la facture créée ref {0} pour le produit {1} quantité : {2} ", invoice.Ref, product.Description, invoiceLine.Quantity); returnVal.errorCode = 0; returnVal.errorMessage = ""; } } else { returnVal.successMessage = ""; returnVal.errorCode = 1; returnVal.errorMessage = "Code barre non reconnu "; } return(Json(returnVal)); }