public bool ExcelUpload(StockTapeModel stockTape) { var body = JsonConvert.SerializeObject(stockTape); bool StockTapeCreate = ServerResponse.Invoke <bool>("api/stockTape/stockTapeExcelData", body, "Post"); return(StockTapeCreate); }
public bool Create(StockTapeModel stock) { bool CreateStokeTape = ServerResponse.Invoke <bool>("api/stockTape/create", JsonConvert.SerializeObject(stock), "POST"); return(CreateStokeTape); }
public ActionResult ExcelUpload(StockTapeModel stock1, FormDataModel model) { // var BranchId1 = ConvertToInt(file["BranchId"]); var file = model.file; var BranchId = model.BranchId; string filePath = string.Empty; var StockBranchModel = Services.StockBranchInventoryService.GetAll(); if ((file != null) && (file.ContentLength > 0) && !string.IsNullOrEmpty(file.FileName)) { string path = Server.MapPath("~/File/"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } filePath = path + Path.GetFileName(file.FileName); string extension = Path.GetExtension(file.FileName); file.SaveAs(filePath); string csvData = System.IO.File.ReadAllText(filePath); var stockTapeList = new List <StockTapeModel>(); Dictionary <string, StockTapeModel> dict = new Dictionary <string, StockTapeModel>(); foreach (string row in csvData.Split('\n')) { if (!string.IsNullOrEmpty(row)) { var barcodeString = row.Split(',')[0].Replace("\r", ""); var productBarcode = barcodeString.Substring(0, 10); //stock.Barcode = productBarcode; var size = barcodeString.Substring((barcodeString.Length - 2), 2); var listBarcode = stockTapeList.Any(x => x.Barcode == productBarcode); StockTapeModel temp; dict.TryGetValue(productBarcode, out temp); if (temp != null) { if (size == "01") { temp.Quantity01 += 1; } if (size == "02") { temp.Quantity02 += 1; } if (size == "03") { temp.Quantity03 += 1; } if (size == "04") { temp.Quantity04 += 1; } if (size == "05") { temp.Quantity05 += 1; } if (size == "06") { temp.Quantity06 += 1; } if (size == "07") { temp.Quantity07 += 1; } if (size == "08") { temp.Quantity08 += 1; } if (size == "09") { temp.Quantity09 += 1; } if (size == "10") { temp.Quantity10 += 1; } if (size == "11") { temp.Quantity11 += 1; } if (size == "12") { temp.Quantity12 += 1; } if (size == "13") { temp.Quantity13 += 1; } if (size == "14") { temp.Quantity14 += 1; } if (size == "15") { temp.Quantity15 += 1; } if (size == "16") { temp.Quantity16 += 1; } if (size == "17") { temp.Quantity17 += 1; } if (size == "18") { temp.Quantity18 += 1; } if (size == "19") { temp.Quantity19 += 1; } if (size == "20") { temp.Quantity20 += 1; } if (size == "21") { temp.Quantity21 += 1; } if (size == "22") { temp.Quantity22 += 1; } if (size == "23") { temp.Quantity23 += 1; } if (size == "24") { temp.Quantity24 += 1; } if (size == "25") { temp.Quantity25 += 1; } if (size == "26") { temp.Quantity26 += 1; } if (size == "27") { temp.Quantity27 += 1; } if (size == "28") { temp.Quantity28 += 1; } if (size == "29") { temp.Quantity29 += 1; } if (size == "30") { temp.Quantity30 += 1; } } else { temp = new StockTapeModel(); temp.Quantity01 = 0; temp.Quantity02 = 0; temp.Quantity03 = 0; temp.Quantity04 = 0; temp.Quantity05 = 0; temp.Quantity06 = 0; temp.Quantity07 = 0; temp.Quantity08 = 0; temp.Quantity09 = 0; temp.Quantity10 = 0; temp.Quantity11 = 0; temp.Quantity12 = 0; temp.Quantity13 = 0; temp.Quantity14 = 0; temp.Quantity15 = 0; temp.Quantity16 = 0; temp.Quantity17 = 0; temp.Quantity18 = 0; temp.Quantity19 = 0; temp.Quantity20 = 0; temp.Quantity21 = 0; temp.Quantity22 = 0; temp.Quantity23 = 0; temp.Quantity24 = 0; temp.Quantity25 = 0; temp.Quantity26 = 0; temp.Quantity27 = 0; temp.Quantity28 = 0; temp.Quantity29 = 0; temp.Quantity30 = 0; temp.Barcode = productBarcode; temp.BranchId = BranchId; temp.Date = DateTime.Now; temp.LogId = 2; temp.IsActive = true; temp.ProductId = StockBranchModel.Where(x => x.Barcode == temp.Barcode).Select(x => x.ProductId).FirstOrDefault(); if (size == "01") { temp.Quantity01 += 1; } if (size == "02") { temp.Quantity02 += 1; } if (size == "03") { temp.Quantity03 += 1; } if (size == "04") { temp.Quantity04 += 1; } if (size == "05") { temp.Quantity05 += 1; } if (size == "06") { temp.Quantity06 += 1; } if (size == "07") { temp.Quantity07 += 1; } if (size == "08") { temp.Quantity08 += 1; } if (size == "09") { temp.Quantity09 += 1; } if (size == "10") { temp.Quantity10 += 1; } if (size == "11") { temp.Quantity11 += 1; } if (size == "12") { temp.Quantity12 += 1; } if (size == "13") { temp.Quantity13 += 1; } if (size == "14") { temp.Quantity14 += 1; } if (size == "15") { temp.Quantity15 += 1; } if (size == "16") { temp.Quantity16 += 1; } if (size == "17") { temp.Quantity17 += 1; } if (size == "18") { temp.Quantity18 += 1; } if (size == "19") { temp.Quantity19 += 1; } if (size == "20") { temp.Quantity20 += 1; } if (size == "21") { temp.Quantity21 += 1; } if (size == "22") { temp.Quantity22 += 1; } if (size == "23") { temp.Quantity23 += 1; } if (size == "24") { temp.Quantity24 += 1; } if (size == "25") { temp.Quantity25 += 1; } if (size == "26") { temp.Quantity26 += 1; } if (size == "27") { temp.Quantity27 += 1; } if (size == "28") { temp.Quantity28 += 1; } if (size == "29") { temp.Quantity29 += 1; } if (size == "30") { temp.Quantity30 += 1; } dict.Add(productBarcode, temp); } } } var stockList = dict.Select(x => x.Value).ToList(); foreach (var l in stockList) { bool stockTape = Services.StockTapeService.Create(l); } TempData["Success"] = "File Uploaded Successfully!"; return(RedirectToAction("Index", "StockTape")); } return(View(stock1)); }