public IActionResult OnPost() { PackageItem p = new PackageItem(); p.PackageItemId = Guid.NewGuid(); p.ProductId = Guid.Parse(producto); p.PackageId = pac.PackageId; p.Qty = cantidad; p.Description = desc; _context.PackageItem.Add(p); _context.SaveChanges(); return(RedirectToPage("./IndexPackageItem", contact)); }
public IActionResult OnPost() { if (!ModelState.IsValid) { return(Page()); } Order.OrderId = Guid.NewGuid(); Order.Agency = _context.Agency.First(); Order.AgencyId = Order.Agency.AgencyId; Order.Office = _context.Office.First(); Order.OfficeId = Order.Office.OfficeId; Order.User = _context.User.First(); Order.UserId = _context.User.First().UserId; Order.Date = DateTime.Now.Date; Order.TipoPago = _context.TipoPago.First(); Order.TipoPagoId = Order.TipoPago.TipoPagoId; if (Order.Type == "Mixto") { Order.Number = "MX"; } else if (Order.Type == "Paquete") { Order.Number = "PA"; } else if (Order.Type == "Alimentos") { Order.Number = "AL"; } else if (Order.Type == "Medicina") { Order.Number = "ME"; } else { Order.Number = "RE"; } Order.Number += DateTime.Now.ToString("MMddyyyyHHmm"); if (listVA.Count() > 0) { for (int i = 0; i < listVA.Count(); i++) { ValorAduanalItem value = new ValorAduanalItem(); value.ValorAduanalItemId = Guid.NewGuid(); value.OrderId = Order.OrderId; value.Order = Order; value.ValorAduanal = _context.ValorAduanal.Where(x => x.ValorAduanalId == Guid.Parse(listVA[i])).First(); value.ValorAduanalId = Guid.Parse(listVA[i]); Order.ValorAduanal += value.ValorAduanal.Value; Order.ValorAduanalItem.Add(value); _context.Add(value); } } Order.Amount = Order.ValorAduanal + (Order.CantLb * Order.PriceLb) + Order.OtrosCostos; Order.Balance = Order.Amount - Order.ValorPagado; if (Order.Balance != 0)//si el balance no es 0 el status es pendiente si el valanece es 0 iniciado, { Order.Status = "Pendiente"; } else { Order.Status = "Iniciada"; } Order.ContactId = contactId; Order.ClientId = _context.Contact.Find(Order.ContactId).ClientId; _context.Add(Order); //Crear un Pacquete Package package = new Package(); package.PackageId = Guid.NewGuid(); package.PackageNavigation = Order; _context.Add(package); if (PackageItem.Count > 0) { for (int i = 0; i < listProduct.Count; i++) { PackageItem packageItem = new PackageItem(); packageItem.PackageItemId = Guid.NewGuid(); packageItem.PackageId = pac.PackageId; packageItem.Package = pac; packageItem.Product = _context.Product.Where(x => x.ProductId == Guid.Parse(listProduct[i])).First(); packageItem.ProductId = packageItem.Product.ProductId; _context.PackageItem.Add(packageItem); } } Order.Package = package; _context.SaveChanges(); return(RedirectToPage("/Index")); }
public ActionResult OnPostImport() { IFormFile file = Request.Form.Files[0]; string folderName = "Upload"; string webRootPath = _env.WebRootPath; string newPath = Path.Combine(webRootPath, folderName); StringBuilder sb = new StringBuilder(); if (!Directory.Exists(newPath)) { Directory.CreateDirectory(newPath); } if (file.Length > 0) { string sFileExtension = Path.GetExtension(file.FileName).ToLower(); ISheet sheet; string fullPath = Path.Combine(newPath, file.FileName); using (var stream = new FileStream(fullPath, FileMode.Create)) { file.CopyTo(stream); stream.Position = 0; if (sFileExtension == ".xls") { HSSFWorkbook hssfwb = new HSSFWorkbook(stream); //This will read the Excel 97-2000 formats sheet = hssfwb.GetSheetAt(0); //get first sheet from workbook } else { XSSFWorkbook hssfwb = new XSSFWorkbook(stream); //This will read 2007 Excel format sheet = hssfwb.GetSheetAt(0); //get first sheet from workbook } IRow headerRow = sheet.GetRow(0); //Get Header Row int cellCount = headerRow.LastCellNum; sb.Append("<table class='table'><tr>"); for (int j = 0; j < cellCount; j++) { NPOI.SS.UserModel.ICell cell = headerRow.GetCell(j); if (cell == null || string.IsNullOrWhiteSpace(cell.ToString())) { continue; } sb.Append("<th>" + cell.ToString() + "</th>"); } sb.Append("</tr>"); sb.AppendLine("<tr>"); for (int i = (sheet.FirstRowNum + 1); i <= sheet.LastRowNum; i++) //Read Excel File { IRow row = sheet.GetRow(i); if (row == null) { continue; } if (row.Cells.All(d => d.CellType == CellType.Blank)) { continue; } for (int j = row.FirstCellNum; j < cellCount; j++) { if (row.GetCell(j) != null) { sb.Append("<td>" + row.GetCell(j).ToString() + "</td>"); } } sb.AppendLine("</tr>"); } sb.Append("</table>"); var clientList = new List <Client>(); var phoneList = new List <Phone>(); var addressList = new List <Address>(); for (int i = (sheet.FirstRowNum + 1); i <= sheet.LastRowNum; i++) //Read Excel File { IRow row = sheet.GetRow(i); if (row == null) { continue; } Client c; if (!_context.Client.Where(x => x.Name == row.GetCell(0).ToString() && x.LastName == row.GetCell(1).ToString()).Any()) { c = new Client(); c.ClientId = Guid.NewGuid(); c.Name = row.GetCell(0).ToString(); c.LastName = row.GetCell(1).ToString(); c.Email = row.GetCell(2).ToString(); c.CreatedAt = DateTime.Now; c.Agency = _context.Agency.First();//Ver aki va la agencia registrada _context.Client.Add(c); } else { c = _context.Client.Where(x => x.Name == row.GetCell(0).ToString() && x.LastName == row.GetCell(1).ToString()).FirstOrDefault(); } if (!_context.Phone.Where(x => x.ReferenceId == c.ClientId && x.Number == row.GetCell(4).ToString()).Any()) { Phone phone; phone = new Phone(); phone.PhoneId = Guid.NewGuid(); phone.Type = row.GetCell(3).ToString(); phone.Number = row.GetCell(4).ToString(); phone.Current = true; phone.ReferenceId = c.ClientId; _context.Phone.Add(phone); } if (!_context.Address.Where(x => x.ReferenceId == c.ClientId && x.Type == row.GetCell(6).ToString()).Any()) { Address add = new Address(); add.AddressId = Guid.NewGuid(); add.Type = row.GetCell(5).ToString(); add.AddressLine1 = row.GetCell(6).ToString(); add.City = row.GetCell(7).ToString(); add.State = row.GetCell(8).ToString(); add.Country = row.GetCell(9).ToString(); add.ReferenceId = c.ClientId; add.CreatedAt = DateTime.Now; add.CreatedBy = _context.User.FirstOrDefault().UserId; //Ver Aqui va el usuario registrado add.UpdatedAt = DateTime.Now; add.UpdatedBy = _context.User.FirstOrDefault().UserId; //Ver Aqui va el usuario registrado _context.Address.Add(add); } } _context.SaveChanges(); ViewData["Message"] = "Los datos han sido importados satisfactoriamente"; } } return(this.Content(sb.ToString())); }
public void CrearOrden() { order = new Order(); order.OrderId = Guid.NewGuid(); order.Agency = _context.Agency.First(); order.AgencyId = order.Agency.AgencyId; order.Office = _context.Office.First(); order.OfficeId = order.Office.OfficeId; order.User = _context.User.First(); order.UserId = _context.User.First().UserId; order.Date = DateTime.Now.Date; //order.TipoPago = _context.TipoPago.First(); //order.TipoPagoId = order.TipoPago.TipoPagoId; order.Type = type; if (type == "Mixto") { order.Number = "MX"; } else if (type == "Paquete") { order.Number = "PA"; } else if (type == "Alimentos") { order.Number = "AL"; } else if (type == "Medicina") { order.Number = "ME"; } else { order.Number = "RE"; } order.Number += DateTime.Now.ToString("MMddyyyyHHmm"); if (listVA.Count() > 0) { for (int i = 0; i < listVA.Count(); i++) { ValorAduanalItem value = new ValorAduanalItem(); value.ValorAduanalItemId = Guid.NewGuid(); value.OrderId = order.OrderId; value.Order = order; value.ValorAduanal = _context.ValorAduanal.Where(x => x.ValorAduanalId == Guid.Parse(listVA[i])).First(); value.ValorAduanalId = Guid.Parse(listVA[i]); order.ValorAduanal += value.ValorAduanal.Value; order.ValorAduanalItem.Add(value); _context.Add(value); } } order.CantLb = cantlb; order.PriceLb = preciolb; order.OtrosCostos = otrosgastos; order.ValorAduanal = valor; order.Amount = order.ValorAduanal + (order.CantLb * order.PriceLb) + order.OtrosCostos; order.Balance = order.Amount - order.ValorPagado; if (order.Balance != 0)//si el balance no es 0 el status es pendiente si el valanece es 0 iniciado, { order.Status = "Pendiente"; } else { order.Status = "Iniciada"; } order.ContactId = contactId; order.ClientId = _context.Contact.Find(order.ContactId).ClientId; _context.Add(order); _context.SaveChanges(); //Crear un Pacquete Package package = new Package(); package.PackageId = Guid.NewGuid(); package.PackageNavigation = order; _context.Add(package); for (int i = 0; i < listProduct.Count; i++) { PackageItem packageItem = new PackageItem(); packageItem.PackageItemId = Guid.NewGuid(); packageItem.PackageId = pac.PackageId; packageItem.Package = pac; packageItem.Product = _context.Product.Where(x => x.ProductId == Guid.Parse(listProduct[i])).First(); packageItem.ProductId = packageItem.Product.ProductId; _context.Add(packageItem); } order.Package = package; _context.SaveChanges(); }