public ActionResult UpLoad() { List <ImportModel.rawImport> recordsIn = new List <ImportModel.rawImport>(); List <ImportModel.Pannebakker> existingRecords = new List <ImportModel.Pannebakker>(); List <ImportModel.rawImport> newRecords = new List <ImportModel.rawImport>(); try { recordsIn = ReadInputFile(); // existingRecords = db.GetPannebakkers().ToList(); // newRecords = recordsIn.Union(existingRecords).ToList(); // newRecords = existingRecords.Union(recordsIn, new DTO.PbComparer()).ToList(); } catch (Exception ex) { ViewBag.Error = ex.InnerException.Message; return(View("version")); } try { #region import ///// empty the import tables // db.Database.ExecuteSqlCommand("TRUNCATE TABLE [Pannebakker]"); db.EmptyImport(); /// insert into raw import and remove any duplicates just in case // db.BulkInsert<Pannebakker>(newRecords); db.BulkInsertIntoImport(recordsIn); db.RemoveDuplicateImport(); #endregion import // merge import into PB and clean form sizes //AddBatch(records); db.MergeImportToPB(); db.cleanPBForms(); db.cleanForms(); db.RemoveDuplicatePB(); // so PB table sould now be solid and ready // remove any duplicates from PB and Batch // may not be needed but just in case // db.RemoveDuplicateBatch(); // clean all old PB's from batch as we are going to provide a new lot. // worried about this moving frowards if quotes use batch ids from PB's i am removing //db.RemovePBFromBatch(); var allPB = db.GetPannebakkers().ToList(); // db.Database.ExecuteSqlCommand("TRUNCATE TABLE [Pannebakker]"); List <ImportModel.Pannebakker> newBatches = new List <ImportModel.Pannebakker>(); foreach (var b in allPB) { ImportModel.Pannebakker newB = new ImportModel.Pannebakker(); decimal price = CalCapPrice(b); if (price != 0) { newB.WholesalePrice = Convert.ToInt32(price); } else { newB.WholesalePrice = Convert.ToInt32(b.Price); } newB.Price = b.Price; newB.FormSize = b.FormSize; newB.Location = "PB"; newB.Name = b.Name; newB.Sku = b.Sku; newB.WholesalePrice = Convert.ToInt32(price); newB.FormSizeCode = b.FormSizeCode; if (price != b.Price) { newB.Comment = "Price Modified from " + b.Price + " to " + newB.WholesalePrice; } if (price == b.Price) { newB.Comment = "Price Not Modified"; } if (price == 0) { newB.Comment = null; } newBatches.Add(newB); } //IEnumerable<ImportModel.Batch> newBatches = allPB.Select(batch => new ImportModel.Batch //{ // Active = true, // AllocatedQuantity = 0, // BuyPrice = CalCapPrice(batch), // Comment = "", // FormSize = batch.FormSize, // ImageExists = false, // GrowingQuantity = 0, // Location = "PB", // Name = batch.Name, // Sku = batch.Sku, // Quantity = 5000, // WholesalePrice = 0, // DateStamp = DateTime.Now, //}); db.EmptyPB(); db.BulkInsertIntoPB(newBatches); db.MergePbToBatch(); ViewBag.Title = "done"; Response.Write("<script>console.log('Data has been saved to db');</script>"); return(View("uploadDone")); //return RedirectToAction("Index"); } catch (Exception ex) { ViewBag.Error = ex.InnerException.Message; return(View("shit")); } }
public ActionResult CalculateBasePrice(decimal margin, decimal import) { decimal test = 0; test = margin; try { var allPB = db.GetPannebakkers().ToList(); // db.Database.ExecuteSqlCommand("TRUNCATE TABLE [Pannebakker]"); #region update import value var pbSupplier = db.GetSupplierByAccount("PO21"); pbSupplier.ImportOffSet = Convert.ToDouble(import); db.UpdateSupplier(pbSupplier); #endregion List <ImportModel.Pannebakker> newBatches = new List <ImportModel.Pannebakker>(); foreach (var b in allPB) { if (b.BatchId == 5313) { var fred = 1; } ImportModel.Pannebakker newB = new ImportModel.Pannebakker(); CalcData.Result result = CalcData.CalMarginPrice(b, margin); decimal price = result.price; if (price != 0) { newB.WholesalePrice = Convert.ToInt32(price); } else { newB.WholesalePrice = Convert.ToInt32(b.Price); } newB.Price = b.Price; newB.FormSize = b.FormSize; newB.Location = "PB"; newB.Name = b.Name; newB.Sku = b.Sku; newB.WholesalePrice = Convert.ToInt32(price); newB.FormSizeCode = b.FormSizeCode; newB.FromDate = b.FromDate; if (price != b.Price) { newB.Comment = "Using Rule " + result.rule + "Price Modified from " + b.Price + " to " + newB.WholesalePrice; } if (price == b.Price) { newB.Comment = "Using Rule " + result.rule + " Price Not Modified"; } if (price == 0) { newB.Comment = null; } newBatches.Add(newB); } db.EmptyPB(); db.BulkInsertIntoPB(newBatches); return(View()); //return RedirectToAction("Index"); } catch (Exception ex) { ViewBag.Error = ex.InnerException.Message; return(View("shit")); } }