public async Task <IActionResult> Edit(int id, [Bind("DeliveryId,Date,Status")] Delivery delivery) { if (id != delivery.DeliveryId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(delivery); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DeliveryExists(delivery.DeliveryId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(delivery)); }
public async Task <IActionResult> Edit(int id, [Bind("InvoiceId,CustomerId,Ref,CreationDate,StartPeriod,EndPeriod,Status")] Invoice invoice) { if (id != invoice.InvoiceId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(invoice); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!InvoiceExists(invoice.InvoiceId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["CustomerId"] = new SelectList(_context.Set <Customer>(), "CustomerId", "Name", invoice.CustomerId); return(View(invoice)); }
public async Task <IActionResult> Edit(int id, [Bind("Id, FirstName, LastName, DepartmentId")] Employee employee) { if (id != employee.Id) { return(NotFound()); } if (ModelState.IsValid) { try { employee.Department = _context.Departments.Find(employee.DepartmentId); _context.Update(employee); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EmployeeExists(employee.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewBag.DepartmentId = new SelectList(_context.Departments, nameof(Department.Id), nameof(Department.Name), employee.DepartmentId); return(View(employee)); }
public async Task <IActionResult> Edit(int id, [Bind("InvoiceLineId,InvoiceId,ProductId,CreationDate,Description,Quantity,Price")] InvoiceLine invoiceLine) { if (id != invoiceLine.InvoiceLineId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(invoiceLine); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!InvoiceLineExists(invoiceLine.InvoiceLineId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["InvoiceId"] = new SelectList(_context.Set <Invoice>(), "InvoiceId", "InvoiceId", invoiceLine.InvoiceId); ViewData["ProductId"] = new SelectList(_context.Set <Product>(), "ProductId", "ProductId", invoiceLine.ProductId); return(View(invoiceLine)); }
public async Task <IActionResult> Edit(int id, [Bind("BarcodeId,CustomerId,ProductId")] Barcode barcode) { if (id != barcode.BarcodeId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(barcode); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BarcodeExists(barcode.BarcodeId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["CustomerId"] = new SelectList(_context.Set <Customer>(), "CustomerId", "Name", barcode.CustomerId); ViewData["ProductId"] = new SelectList(_context.Set <Product>(), "ProductId", "Description", barcode.ProductId); return(View(barcode)); }
public async Task <IActionResult> Edit(int id, [Bind("ID,Title,Artist,Album,ReleaseYear,Genre,Filename,Folder")] Music music) { if (id != music.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(music); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MusicExists(music.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(music)); }
public async Task <IActionResult> Edit(int id, [Bind("PersonId,Name,Mail,Age")] Person person) { if (id != person.PersonId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(person); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PersonExists(person.PersonId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(person)); }
public async Task <IActionResult> Edit(int id, [Bind("CustomerId,Name,address,address2,address3,zipcode,city")] Customer customer) { if (id != customer.CustomerId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(customer); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CustomerExists(customer.CustomerId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(customer)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Title,ReleaseDate,Genre,Price,Rating")] Movie movie) { if (id != movie.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(movie); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MovieExists(movie.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(movie)); }
public async Task <IActionResult> Edit(int id, [Bind("ProductId,Description,Price")] Product product) { if (id != product.ProductId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(product); await _context.SaveChangesAsync(); var currentInvoiceIds = _context.Invoice.Where(i => i.Status == FacturationWebSite.Models.Enum.InvoiceStatus.Active).Select(i => i.InvoiceId); var invoiceLines = _context.InvoiceLine.Where(il => currentInvoiceIds.Contains(il.InvoiceId) && il.ProductId == product.ProductId).ToList(); foreach (var line in invoiceLines) { if (line.Price != product.Price) { line.Price = product.Price; _context.Update(line); await _context.SaveChangesAsync(); } } } catch (DbUpdateConcurrencyException) { if (!ProductExists(product.ProductId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(product)); }
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)); }