Exemple #1
0
        public bool CheckAndValidateFileToBeUpload(ExportToExcelUploadGrossPriceListDto inputs)
        {
            var dataToExport = (
                from mu in _contextProp.MS_Unit
                join X in inputs.priceList.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();


            if (!dataToExport.Any())
            {
                throw new UserFriendlyException("Data is Required !");
            }
            if (string.IsNullOrEmpty(dataToExport[0].termName))
            {
                throw new UserFriendlyException("Term Name is Required !");
            }
            int row = 1;

            foreach (var input in inputs.unitItemPrice.inputUnitItemPrice)
            {
                if (string.IsNullOrWhiteSpace(input.unitCode))
                {
                    throw new UserFriendlyException("Unit Code in " + AddOrdinal(row) + " data cannot be blank!");
                }

                if (string.IsNullOrWhiteSpace(input.unitNo))
                {
                    throw new UserFriendlyException("Unit No in " + AddOrdinal(row) + " data cannot be blank!");
                }

                if (string.IsNullOrWhiteSpace(input.renovCode))
                {
                    throw new UserFriendlyException("Renovation Code in " + AddOrdinal(row) + " data cannot be blank!");
                }

                var getUnitCodeID = (from A in _contextProp.MS_UnitCode
                                     where A.entityID == 1 &&
                                     A.unitCode == input.unitCode
                                     select A.Id);

                if (!getUnitCodeID.Any())
                {
                    throw new UserFriendlyException("Unit Code ID with EntityId: " + 1 + " and UnitCode: " + input.unitCode + " not found!");
                }

                var getUnitID = (from A in _contextProp.MS_Unit
                                 where A.entityID == 1 &&
                                 A.unitCodeID == getUnitCodeID.FirstOrDefault() &&
                                 A.unitNo == input.unitNo &&
                                 A.projectID == inputs.unitItemPrice.projectId &&
                                 A.clusterID == inputs.unitItemPrice.clusterId
                                 select A.Id);

                if (!getUnitID.Any())
                {
                    throw new UserFriendlyException("Unit ID with EntityId: " + 1 + ", UnitCodeID: "
                                                    + getUnitCodeID.FirstOrDefault() + ", UnitNo: "
                                                    + input.unitNo + ", Project ID "
                                                    + inputs.unitItemPrice.projectId + " and Cluster ID "
                                                    + inputs.unitItemPrice.clusterId + " not found!");
                }

                var getRenovId = (from A in _contextProp.MS_Renovation
                                  where A.renovationCode == input.renovCode &&
                                  A.projectID == inputs.unitItemPrice.projectId
                                  select A.Id);

                if (!getRenovId.Any())
                {
                    throw new UserFriendlyException("Renovation ID with RenovationCode: "
                                                    + input.renovCode + " and Project ID "
                                                    + inputs.unitItemPrice.projectId + " not found!");
                }

                var getItemId = (from A in _contextProp.LK_Item
                                 where A.itemCode == input.itemCode
                                 select A.Id);

                if (!getItemId.Any())
                {
                    throw new UserFriendlyException("Item ID with ItemCode: "
                                                    + input.itemCode + " not found!");
                }
                row++;
            }
            return(true);
        }
Exemple #2
0
        public FileDto ExportToExcelUploadGrossPrice(ExportToExcelUploadGrossPriceListDto 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.priceList)
                 * {
                 *  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.priceList.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 == mu.termMainID && mu.productID == X.productID &&
                    mu.clusterID == X.clusterID && mu.categoryID == X.categoryID &&
                    mu.projectID == X.projectID
                    orderby mp.productName
                    select new ExportToExcelUploadPriceListDto
                {
                    productName = mp.productName,
                    unitCode = X.unitCode,
                    unitNo = X.unitNo,
                    renovCode = X.renovCode,
                    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.ExportToExcelUploadGrossPrice(result);
            }
            catch (Exception e)
            {
                SendConsole("" + e.Message + " " + e.StackTrace);
                throw new UserFriendlyException(e.Message);
            }

            CreateUnitItemPrice(input.unitItemPrice);

            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\GrossPriceFile\";
                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, "grossPrice");
                    var dtoPriceTaskList = new CreatePriceTaskListInputDto
                    {
                        projectID     = input.priceList.FirstOrDefault().projectID,
                        priceListFile = priceListFile
                    };

                    var checkAvailibilityProject = (from x in _contextProp.MS_Project
                                                    where x.Id == input.priceList.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 !");
                }
            }

            return(fileExcel);
        }