Beispiel #1
0
        public bool CheckDataUploadGrossPrice(CheckDataUploadGrossPriceInputDto inputs)
        {
            bool NotFound = false;

            Logger.InfoFormat("CheckDataUploadGrossPrice() - Started.");
            var countLoop = inputs.DataUnit.ToList().Count;
            int inc       = 1;
            List <MS_UnitItemPrice> ListUnitItemPrice = new List <MS_UnitItemPrice>();

            foreach (var input in inputs.DataUnit)
            {
                Logger.InfoFormat("CheckDataUploadGrossPrice() - Started : " + inc + " of " + countLoop);
                var getUnitCodeID = (from A in _contextProp.MS_UnitCode
                                     where A.entityID == 1 &&
                                     A.unitCode == input.UnitCode
                                     select A.Id);

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

                var getUnitID = (from A in _msUnitRepo.GetAll()
                                 where A.entityID == 1 &&
                                 A.unitCodeID == getUnitCodeID.FirstOrDefault() &&
                                 A.unitNo == input.UnitNo &&
                                 A.projectID == inputs.ProjectId &&
                                 A.clusterID == inputs.ClusterId
                                 select A.Id);

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

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

                if (!getRenovId.Any())
                {
                    Logger.InfoFormat("Renovation ID with RenovationCode: "
                                      + input.RenovCode + " and Project ID "
                                      + inputs.ProjectId + " not found!");
                    throw new UserFriendlyException("Renovation ID with RenovationCode: "
                                                    + input.RenovCode + " and Project ID "
                                                    + inputs.ProjectId + " not found!");
                }

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

                if (!getItemId.Any())
                {
                    Logger.InfoFormat("Item ID with ItemCode: "
                                      + input.ItemCode + " not found!");
                    throw new UserFriendlyException("Item ID with ItemCode: "
                                                    + input.ItemCode + " not found!");
                }

                var msUnitItemPrice = new MS_UnitItemPrice
                {
                    entityID = 1,
                    itemID   = getItemId.FirstOrDefault(),
                    renovID  = getRenovId.FirstOrDefault(),
                    unitID   = getUnitID.FirstOrDefault()
                };

                Logger.DebugFormat("CheckDataUploadGrossPrice() - Start Add Into List UnitItemPrice. Parameters sent: {0} " +
                                   "entityID       = 1" +
                                   "itemID         = {1}{0}" +
                                   "renovID        = {2}{0}" +
                                   "unitID         = {3}{0}"
                                   , Environment.NewLine, getItemId.FirstOrDefault(), getRenovId.FirstOrDefault(), getUnitID.FirstOrDefault());

                ListUnitItemPrice.Add(msUnitItemPrice);
                Logger.InfoFormat("CheckDataUploadGrossPrice() - Finished : " + inc + " of " + countLoop);
                inc++;
            }

            if (ListUnitItemPrice.Any())
            {
                NotFound = true;
            }
            var founded = NotFound == false ? "not Found." : "Founded.";

            Logger.InfoFormat("CheckDataUploadGrossPrice() - Ended, Data " + founded);
            return(NotFound);
        }
Beispiel #2
0
        /*
         * public void CreateUnitItemPrice0(CreateUnitItemPriceInputDto inputs)
         * {
         *  foreach (var input in inputs.inputEtc)
         *  {
         *      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.projectId
         *                       && A.clusterID == inputs.clusterId
         *                       select A.Id);
         *
         *      if (!getUnitID.Any())
         *      {
         *          throw new UserFriendlyException("Unit ID with EntityId: " + 1 + ", UnitCodeID: "
         + getUnitCodeID.FirstOrDefault() + ", UnitNo: "
         + input.unitNo + ", Project ID "
         + inputs.projectId + " and Cluster ID "
         + inputs.clusterId + " not found!");
         +      }
         +
         +      var getRenovId = (from A in _contextProp.MS_Renovation
         +                        where A.renovationCode == input.renovCode
         +                        && A.projectID == inputs.projectId
         +                        select A.Id);
         +
         +      if (!getRenovId.Any())
         +      {
         +          throw new UserFriendlyException("Renovation ID with RenovationCode: "
         + input.renovCode + " and Project ID "
         + inputs.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!");
         +      }
         +
         +      var msUnitItemPrice = new MS_UnitItemPrice
         +      {
         +          entityID = 1,
         +          termID = inputs.termId,
         +          itemID = getItemId.FirstOrDefault(),
         +          renovID = getRenovId.FirstOrDefault(),
         +          unitID = getUnitID.FirstOrDefault(),
         +          grossPrice = input.grossPrice
         +      };
         +
         +      // _msUnitItemPriceRepository.Insert(msUnitItemPrice);
         +      _contextProp.MS_UnitItemPrice.Add(msUnitItemPrice);
         +      _contextProp.SaveChanges();
         +  }
         + }
         */

        public void CreateUnitItemPrice(CreateUnitItemPriceInputDto inputs)
        {
            Logger.InfoFormat("CreateUnitItemPrice() - Started.");
            var countLoop = inputs.inputUnitItemPrice.ToList().Count;
            int inc       = 1;

            foreach (var input in inputs.inputUnitItemPrice)
            {
                Logger.InfoFormat("CreateUnitItemPrice() - Started : " + inc + " of " + countLoop);
                var getUnitCodeID = (from A in _contextProp.MS_UnitCode
                                     where A.entityID == 1 &&
                                     A.unitCode == input.unitCode
                                     select A.Id);

                if (!getUnitCodeID.Any())
                {
                    Logger.InfoFormat("Unit Code ID with EntityId: " + 1 + " and UnitCode: " + input.unitCode + " not found!");
                    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.projectId &&
                                 A.clusterID == inputs.clusterId
                                 select A.Id);

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

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

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

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

                if (!getItemId.Any())
                {
                    Logger.InfoFormat("Item ID with ItemCode: "
                                      + input.itemCode + " not found!");
                    throw new UserFriendlyException("Item ID with ItemCode: "
                                                    + input.itemCode + " not found!");
                }

                var checkUnitItemPrice = (from A in _contextProp.MS_UnitItemPrice
                                          where A.entityID == 1 &&
                                          A.unitID == getUnitID.FirstOrDefault() &&
                                          A.termID == inputs.termId &&
                                          A.renovID == getRenovId.FirstOrDefault() &&
                                          A.itemID == getItemId.FirstOrDefault()
                                          select A).Any();
                if (!checkUnitItemPrice)
                {
                    var msUnitItemPrice = new MS_UnitItemPrice
                    {
                        entityID   = 1,
                        termID     = inputs.termId,
                        itemID     = getItemId.FirstOrDefault(),
                        renovID    = getRenovId.FirstOrDefault(),
                        unitID     = getUnitID.FirstOrDefault(),
                        grossPrice = input.grossPrice
                    };

                    Logger.DebugFormat("CreateUnitItemPrice() - Start Insert MS_UnitItemPrice. Parameters sent: {0} " +
                                       "entityID       = 1 " +
                                       "termID         = {1}{0} " +
                                       "itemID         = {2}{0} " +
                                       "renovID        = {3}{0} " +
                                       "unitID         = {4}{0} " +
                                       "grossPrice     = {5}{0}"
                                       , Environment.NewLine, inputs.termId, getItemId.FirstOrDefault(), getRenovId.FirstOrDefault(), getUnitID.FirstOrDefault(), input.grossPrice);

                    _contextProp.MS_UnitItemPrice.Add(msUnitItemPrice);
                    _contextProp.SaveChanges();
                    //_msUnitItemPriceRepository.Insert(msUnitItemPrice);
                    Logger.InfoFormat("CreateUnitItemPrice() - Finished : " + inc + " of " + countLoop);
                    inc++;
                }
                else
                {
                    Logger.DebugFormat("CheckUnitItemPrice() - Start Check MS_UnitItemPrice. Parameters sent: {0} " +
                                       "entityID       = 1 " +
                                       "termID         = {1}{0} " +
                                       "itemID         = {2}{0} " +
                                       "renovID        = {3}{0} " +
                                       "unitID         = {4}{0} " +
                                       "grossPrice     = {5}{0}"
                                       , Environment.NewLine, inputs.termId, getItemId.FirstOrDefault(), getRenovId.FirstOrDefault(), getUnitID.FirstOrDefault(), input.grossPrice);
                    throw new UserFriendlyException("Data already exist in MS_UnitItemPrice. EntityId: 1" +
                                                    " TermId: " + inputs.termId +
                                                    " ItemId: " + getItemId.FirstOrDefault() +
                                                    " RenovId: " + getRenovId.FirstOrDefault() +
                                                    " UnitId: " + getUnitID.FirstOrDefault());
                }
            }

            Logger.InfoFormat("CreateUnitItemPrice() - Finished.");
        }