public void CreatePriceTaskList(CreatePriceTaskListInputDto input) { Logger.InfoFormat("CreatePriceTaskList() - Started."); var data = new MS_PriceTaskList { projectID = input.projectID, priceListFile = input.priceListFile }; Logger.DebugFormat("CreatePriceTaskList() - Start Insert MS_PriceTaskList. Parameters sent: {0} " + "projectID = {1}{0} " + "priceListFile = {2}{0}" , Environment.NewLine, input.projectID, input.priceListFile); _contextProp.MS_PriceTaskList.Add(data); _contextProp.SaveChanges(); Logger.InfoFormat("CreatePriceTaskList() - Finished."); }
public FileDto ExportToExcelUploadPriceList(List <ExportToExcelUploadPriceListDto> input)//passed { FileDto fileExcel = null; try { Debug.WriteLine("Trigger:" + _hostingEnvironment.ContentRootPath); Debug.WriteLine("Trigger:" + L("PriceList")); List <ExportToExcelUploadPriceListDto> result = new List <ExportToExcelUploadPriceListDto>(); #region versi old - hindari mengeksekusi query didalam foreach /* * foreach (var X in input) * { * var prepDP = (from A in _contextProp.MS_Unit * join B in _contextProp.MS_TermMain on X.termMainID equals B.Id * join C in _contextProp.MS_Product on A.productID equals C.Id * join D in _contextProp.MS_UnitCode on A.unitCodeID equals D.Id * where D.unitCode == X.unitCode && A.unitNo == X.unitNo * orderby C.productName * select new GetDpListDto * { * unitCode = D.unitCode, * unitNo = A.unitNo, * bfAmount = B.BFAmount, * productName = C.productName * }).FirstOrDefault(); * * decimal bookingFee = 0; * string productName = null; * * if (prepDP != null) * { * bookingFee = prepDP != null ? prepDP.bfAmount : 0; * productName = prepDP.productName != null ? prepDP.productName : null; * } * * var prepDatumExportData = new ExportToExcelUploadPriceListDto * { * productName = productName, * unitCode = X.unitCode, * unitNo = X.unitNo, * price = X.price, * termName = X.termName, * bookingFee = bookingFee * }; * result.Add(prepDatumExportData); * } */ #endregion var dataToExport = ( from mu in _contextProp.MS_Unit join X in input.ToList() on mu.unitNo equals X.unitNo join mtm in _contextProp.MS_TermMain on X.termMainID equals mtm.Id join mp in _contextProp.MS_Product on mu.productID equals mp.Id join muc in _contextProp.MS_UnitCode on mu.unitCodeID equals muc.Id where muc.unitCode == X.unitCode && mu.unitNo == X.unitNo && X.termMainID == mtm.Id orderby mp.productName select new ExportToExcelUploadPriceListDto { productName = mp.productName, unitCode = X.unitCode, unitNo = X.unitNo, price = X.price, termName = X.termName, bookingFee = mtm.BFAmount }).ToList(); result.AddRange(dataToExport); if (!result.Any()) { throw new UserFriendlyException("Data is Required !"); } if (string.IsNullOrEmpty(result[0].termName)) { throw new UserFriendlyException("Term Name is Required !"); } fileExcel = _generatePriceListExcelExporter.ExportToExcelUploadPriceList(result); //TODO ExportToExcelUploadPriceList var filePath = _hostingEnvironment.WebRootPath + @"\Temp\Downloads\" + fileExcel.FileToken; if (!File.Exists(filePath)) { throw new UserFriendlyException(L("RequestedFileDoesNotExists")); } else { var fileBytes = File.ReadAllBytes(filePath); string DestinationDir = _hostingEnvironment.WebRootPath + @"\Temp\Downloads\PriceListFile\"; string DestinationPath = DestinationDir + fileExcel.FileName; if (!Directory.Exists(DestinationDir)) { Directory.CreateDirectory(DestinationDir); } File.WriteAllBytes(DestinationPath, fileBytes); if (File.Exists(DestinationPath)) { var priceListFile = moveFile(fileExcel.FileName, "priceList"); var dtoPriceTaskList = new CreatePriceTaskListInputDto { projectID = input.FirstOrDefault().projectID, priceListFile = priceListFile }; var checkAvailibilityProject = (from x in _contextProp.MS_Project where x.Id == input.FirstOrDefault().projectID select x).Any(); if (!checkAvailibilityProject) { throw new UserFriendlyException("Master Project Code Unavailable !"); } CreatePriceTaskList(dtoPriceTaskList); } else { throw new UserFriendlyException("File is Required to be Uploaded !"); } } } catch (Exception e) { SendConsole("" + e.Message + " " + e.StackTrace); throw new UserFriendlyException(e.Message); } return(fileExcel); }