// GET: GrowMaster/Details/5 public ActionResult GMUpLoad() { List <Models.GMItem> recordsIn = new List <Models.GMItem>(); 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()); } try { #region import IEnumerable <ImportModel.Batch> GMImport = recordsIn.Select(b => new ImportModel.Batch { Location = b.Location, Name = b.Name, BuyPrice = 0, WholesalePrice = (int)b.WholeSalePrice, Sku = b.Sku, FormSize = b.Size + " " + b.Form, FormSizeCode = b.PBFSCode, Active = true, AllocatedQuantity = b.AllocatedQuantity, Comment = "", GrowingQuantity = b.GrowingQuantity, ImageExists = false, Quantity = b.StockQuantity, DateStamp = DateTime.Now }).AsEnumerable(); var result = GMImport.ToList(); db.BulkInsertGMBatch(GMImport); #endregion import // db.MergePbToBatch(); ViewBag.Title = "done"; Response.Write("<script>console.log('Data has been saved to db');</script>"); return(RedirectToAction("index", "readBatch")); //return RedirectToAction("Index"); } catch (Exception ex) { ViewBag.Error = ex.InnerException.Message; return(View("shit")); } }
public ActionResult UpLoad() { ImportSet importSet = new ImportSet(); List <ImportModel.rawImport> recordsIn = new List <ImportModel.rawImport>(); List <ImportModel.Batch> batchIn = new List <ImportModel.Batch>(); //List<ImportModel.Pannebakker> existingRecords = new List<ImportModel.Pannebakker>(); //List<ImportModel.rawImport> newRecords = new List<ImportModel.rawImport>(); try { importSet = ReadInputFile(); recordsIn = importSet.rawImport; batchIn = importSet.batchImport; // 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 { // "TRUNCATE TABLE [rawImport]"]"); RepDb.EmptyImport(); // db.BulkInsert<Pannebakker>(newRecords); RepDb.BulkInsertIntoImport(recordsIn); RepDb.BulkInsertGMBatch(batchIn); // RepDb.RemoveDuplicateNames(); //AddBatch(records); RepDb.MergeBatchToNames(); RepDb.RemoveDuplicateNames(); ViewBag.Title = "done"; Response.Write("<script>console.log('Data has been saved to db');</script>"); //return View("Index"); return(RedirectToAction("Index")); } catch (Exception ex) { ViewBag.Error = ex.InnerException.Message; return(View("shit")); } }