Example #1
0
 public override IEnumerable <string[]> Validate()
 {
     if (string.IsNullOrWhiteSpace(Descricao))
     {
         yield return(Validation.Add <Tenant>(c => c.Descricao, ValidationMessages.Required()));
     }
 }
Example #2
0
        public Dictionary <string, string> ValidateSale(SaleTransaction model)
        {
            var modelStateDict = new Dictionary <string, string>();

            #region VALIDATE CUSTOMER / HAULER
            if (model.CustomerId.IsNullOrZero() && model.HaulerId.IsNullOrZero())
            {
                modelStateDict.Add(nameof(model.CustomerId), ValidationMessages.Required("Customer/Hauler"));
            }
            if (model.CustomerId.IsNullOrZero() == false)
            {
                if (CustomerExists(model.CustomerId) == false)
                {
                    modelStateDict.Add(nameof(model.CustomerId), ValidationMessages.CustomerNotExists);
                }
            }
            if (model.HaulerId.IsNullOrZero() == false)
            {
                if (HaulerExists(model.HaulerId) == false)
                {
                    modelStateDict.Add(nameof(model.HaulerId), ValidationMessages.HaulerNotExists);
                }
            }
            #endregion

            #region VALIDATE PRODUCT
            if (model.ProductId.IsNullOrZero())
            {
                modelStateDict.Add(nameof(model.ProductId), ValidationMessages.Required("Product"));
            }
            else if (ProductExists(model.ProductId) == false)
            {
                modelStateDict.Add(nameof(model.ProductId), ValidationMessages.ProductNotExists);
            }

            #endregion

            #region VALIDATE BALES

            if (model.SaleBales?.Count() > 0)
            {
                var unRelatedBalesCount = model.SaleBales.Select(a => a.Bale).Count(a => a.ProductId != model.ProductId);
                if (unRelatedBalesCount > 0)
                {
                    modelStateDict.Add(nameof(model.ProductId), "Selected bales must match the product type.");
                }
                ;
            }

            #endregion

            #region VALIDATE PAPER MILL
            if (model.PaperMillId.IsNullOrZero())
            {
                modelStateDict.Add(nameof(model.PaperMillId), ValidationMessages.Required("Paper Mill"));
            }
            else if (PaperMillExists(model.PaperMillId ?? 0) == false)
            {
                modelStateDict.Add(nameof(model.PaperMillId), ValidationMessages.ProductNotExists);
            }
            #endregion

            #region VALIDATE MOISTURE READER
            if (model.MoistureReaderId.IsNullOrZero())
            {
                modelStateDict.Add(nameof(model.MoistureReaderId), ValidationMessages.Required("Moisture Reader"));
            }
            else if (MoistureReaderExists(model.MoistureReaderId ?? 0) == false)
            {
                modelStateDict.Add(nameof(model.MoistureReaderId), ValidationMessages.MoistureReaderNotExists);
            }
            #endregion

            #region VALIDATE INSPECTOR/WEIGHER
            if (model.WeigherOutId.IsNull())
            {
                modelStateDict.Add(nameof(model.WeigherOutId), ValidationMessages.Required("Inspector is required."));
            }
            else if (UserAccountExists(model.WeigherOutId) == false)
            {
                modelStateDict.Add(nameof(model.WeigherOutId), ValidationMessages.UserNotExists);
            }
            #endregion

            return(modelStateDict);
        }
Example #3
0
        public Dictionary <string, string> ValidatePurchase(PurchaseTransaction model)
        {
            var modelStateDict = new Dictionary <string, string>();

            #region VALIDATE VEHICLE NUM
            if (model.VehicleNum.IsNull())
            {
                modelStateDict.Add(nameof(model.VehicleNum), ValidationMessages.Required("Vehicle Number"));
            }
            #endregion

            #region VALIDATE BALE TYPE
            if (model.BaleTypeId.IsNullOrZero())
            {
                modelStateDict.Add(nameof(model.BaleTypeId), ValidationMessages.Required("Bale Type"));
            }
            else if (BaleTypeExists(model.BaleTypeId) == false)
            {
                modelStateDict.Add(nameof(model.BaleTypeId), ValidationMessages.BaleTypeNotExists);
            }
            #endregion

            #region VALIDATE SUPPLIER
            if (model.SupplierId.IsNullOrZero())
            {
                modelStateDict.Add(nameof(model.SupplierId), ValidationMessages.Required("Supplier"));
            }
            else if (SupplierExists(model.SupplierId) == false)
            {
                modelStateDict.Add(nameof(model.SupplierId), ValidationMessages.SupplierNotExists);
            }
            #endregion

            #region VALIDATE MATERIAL
            if (model.RawMaterialId.IsNullOrZero())
            {
                modelStateDict.Add(nameof(model.RawMaterialId), ValidationMessages.Required("Material"));
            }
            else if (RawMaterialExists(model.RawMaterialId) == false)
            {
                modelStateDict.Add(nameof(model.RawMaterialId), ValidationMessages.RawMaterialNotExists);
            }
            #endregion

            #region VALIDATE SOURCE
            if (model.SourceId.IsNullOrZero())
            {
                modelStateDict.Add(nameof(model.SourceId), ValidationMessages.Required("Source"));
            }
            else if (SourceExists(model.SourceId) == false)
            {
                modelStateDict.Add(nameof(model.SourceId), ValidationMessages.SourceNotExists);
            }
            #endregion

            #region VALIDATE PO
            var poModified = dbContext.PurchaseTransactions.AsNoTracking().Where(a => a.PurchaseId == model.PurchaseId).Select(a => a.PurchaseOrderId != model.PurchaseOrderId).FirstOrDefault();

            if (poModified)
            {
                var po = purchaseOrderRepository.ValidatePO(new PurchaseOrder()
                {
                    PurchaseOrderId = model.PurchaseOrderId ?? 0
                });
                if (po == null)
                {
                    modelStateDict.Add(nameof(model.PurchaseOrderId), ValidationMessages.POInvalid);
                }
                else if (po.BalanceRemainingKg < -5000)
                {
                    modelStateDict.Add(nameof(model.PurchaseOrderId), ValidationMessages.PORemainingBalanceInvalid);
                }
            }
            #endregion

            #region VALIDATE MOISTURE READER
            if (model.MoistureReaderId.IsNullOrZero())
            {
                modelStateDict.Add(nameof(model.MoistureReaderId), ValidationMessages.Required("Moisture Reader"));
            }
            else if (MoistureReaderExists(model.MoistureReaderId ?? 0) == false)
            {
                modelStateDict.Add(nameof(model.MoistureReaderId), ValidationMessages.MoistureReaderNotExists);
            }
            #endregion

            #region VALIDATE INSPECTOR/WEIGHER
            if (model.WeigherOutId.IsNull())
            {
                modelStateDict.Add(nameof(model.WeigherOutId), ValidationMessages.Required("Inspector is required."));
            }
            else if (UserAccountExists(model.WeigherOutId) == false)
            {
                modelStateDict.Add(nameof(model.WeigherOutId), ValidationMessages.UserNotExists);
            }
            #endregion

            return(modelStateDict);
        }
Example #4
0
        public Dictionary <string, string> ValidateInyardWeighing(Inyard model)
        {
            var modelStateDict = new Dictionary <string, string>();

            if (model.TransactionProcess == SysUtility.Enums.TransactionProcess.WEIGH_IN ||
                model.TransactionProcess == SysUtility.Enums.TransactionProcess.UPDATE_WEIGH_IN)
            {
                if (model.IsOfflineIn == false)
                {
                    if (model.VehicleNum != model.VehicleNumOld || model.VehicleNumOld == null)
                    {
                        var vehicleDeliverRestriction = new VehicleDeliveryRestriction(model.VehicleNum, model.CommodityId)
                        {
                            DateTimeIn = model.DateTimeIn
                        };
                        var vehicleDeliveryRestrictionResult = vehicleDeliveryRestrictionRepository.CheckRestriction(vehicleDeliverRestriction);
                        if (vehicleDeliveryRestrictionResult != null)
                        {
                            modelStateDict.Add(nameof(Inyard.VehicleNum), ValidationMessages.VehicleDeliveryInvalid(vehicleDeliveryRestrictionResult.DTRestriction));
                        }

                        var purchaseGrossRestrictionresult = new PurchaseGrossWtRestriction(model.VehicleNum, model.CommodityId)
                        {
                            DateTimeIn = model.DateTimeIn
                        };
                        var purchaseGrossRestrictionResult = purchaseGrossWtRestrictionRepository.CheckRestriction(purchaseGrossRestrictionresult);
                        if (purchaseGrossRestrictionResult != null)
                        {
                            modelStateDict.Add(nameof(Inyard.GrossWt), ValidationMessages.PurchaseGrossInvalid(purchaseGrossRestrictionResult.DTRestriction));
                        }
                    }
                }

                #region VALIDATE INSPECTOR/WEIGHER
                if (model.WeigherInId.IsNull())
                {
                    modelStateDict.Add(nameof(model.WeigherInId), ValidationMessages.Required("Inspector is required."));
                }
                else if (UserAccountExists(model.WeigherInId) == false)
                {
                    modelStateDict.Add(nameof(model.BaleTypeId), ValidationMessages.UserNotExists);
                }
                #endregion

                if (modelStateDict.Count > 0)
                {
                    return(modelStateDict);
                }
            }
            else
            {
                #region VALIDATE INSPECTOR/WEIGHER
                if (model.WeigherOutId.IsNull())
                {
                    modelStateDict.Add(nameof(model.WeigherOutId), ValidationMessages.Required("Inspector is required."));
                }
                else if (UserAccountExists(model.WeigherOutId) == false)
                {
                    modelStateDict.Add(nameof(model.WeigherOutId), ValidationMessages.UserNotExists);
                }
                #endregion
            }

            #region VALIDATE VEHICLE NUM
            if (model.VehicleNum.IsNull())
            {
                modelStateDict.Add(nameof(model.VehicleNum), ValidationMessages.Required("Vehicle Number"));
            }
            #endregion

            #region VALIDATE BALE TYPE
            if (model.BaleTypeId.IsNullOrZero())
            {
                modelStateDict.Add(nameof(model.BaleTypeId), ValidationMessages.Required("Bale Type"));
            }
            else if (BaleTypeExists(model.BaleTypeId) == false)
            {
                modelStateDict.Add(nameof(model.BaleTypeId), ValidationMessages.BaleTypeNotExists);
            }
            #endregion

            if (model.TransactionTypeCode == "I")
            {
                if (model.TransactionProcess == SysUtility.Enums.TransactionProcess.WEIGH_IN)
                {
                    if (model.GrossWt == 0)
                    {
                        modelStateDict.Add(nameof(model.GrossWt), ValidationMessages.InvalidWeight);
                    }
                }
                else if (model.TransactionProcess == SysUtility.Enums.TransactionProcess.WEIGH_OUT)
                {
                    if (model.MC == 0)
                    {
                        modelStateDict.Add(nameof(model.MC), ValidationMessages.Required("MC"));
                    }
                    if (model.TareWt == 0 || model.NetWt == 0)
                    {
                        modelStateDict.Add(nameof(model.TareWt), ValidationMessages.InvalidWeight);
                    }

                    var corrected10 = 0M;
                    if (model.MC != 0 & model.NetWt != 0)
                    {
                        var correctedMC = moistureSettingsRepository.GetCorrectedMC(model.MC, model.NetWt);
                        corrected10 = correctedMC.Corrected10;
                    }

                    #region VALIDATE RECEIPT NUM
                    //var receiptNum = refNumRepository.Get().FirstOrDefault().PurchaseReceiptNum;
                    if (dbContext.PurchaseTransactions.AsNoTracking().Count(a => a.ReceiptNum == model.InyardNum) > 0)
                    {
                        modelStateDict.Add(nameof(model.InyardNum), ValidationMessages.InvalidReceiptNum);
                    }
                    #endregion

                    #region VALIDATE MOISTURE READER
                    if (model.MoistureReaderId.IsNullOrZero())
                    {
                        modelStateDict.Add(nameof(model.MoistureReaderId), ValidationMessages.Required("Moisture Reader"));
                    }
                    else if (MoistureReaderExists(model.MoistureReaderId ?? 0) == false)
                    {
                        modelStateDict.Add(nameof(model.MoistureReaderId), ValidationMessages.MoistureReaderNotExists);
                    }
                    #endregion

                    #region VALIDATE MC FILE
                    if (ValidateMCFile(model) == false)
                    {
                        modelStateDict.Add(nameof(model.MC), ValidationMessages.MCFileInvalid);
                    }
                    #endregion
                }

                #region VALIDATE DR
                if (model.DRNum.IsNull())
                {
                    modelStateDict.Add(nameof(model.DRNum), ValidationMessages.Required("DR Number"));
                }
                #endregion
                #region VALIDATE SUPPLIER
                if (model.ClientId.IsNullOrZero())
                {
                    modelStateDict.Add(nameof(model.ClientId), ValidationMessages.Required("Supplier"));
                }
                else if (SupplierExists(model.ClientId) == false)
                {
                    modelStateDict.Add(nameof(model.ClientName), ValidationMessages.SupplierNotExists);
                }
                #endregion

                #region VALIDATE MATERIAL
                if (model.CommodityId.IsNullOrZero())
                {
                    modelStateDict.Add(nameof(model.CommodityId), ValidationMessages.Required("Material"));
                }
                else if (RawMaterialExists(model.CommodityId) == false)
                {
                    modelStateDict.Add(nameof(model.CommodityId), ValidationMessages.RawMaterialNotExists);
                }
                #endregion

                #region VALIDATE SOURCE
                if (model.SourceId.IsNullOrZero())
                {
                    modelStateDict.Add(nameof(model.SourceId), ValidationMessages.Required("Source"));
                }
                else if (SourceExists(model.SourceId) == false)
                {
                    modelStateDict.Add(nameof(model.SourceId), ValidationMessages.SourceNotExists);
                }
                #endregion

                #region VALIDATE PO

                var po = purchaseOrderRepository.ValidatePO(new PurchaseOrder()
                {
                    PurchaseOrderId = model.PurchaseOrderId ?? 0
                });
                if (po == null)
                {
                    modelStateDict.Add(nameof(model.PurchaseOrderId), ValidationMessages.POInvalid);
                }
                else if (po.BalanceRemainingKg < -5000)
                {
                    modelStateDict.Add(nameof(model.PurchaseOrderId), ValidationMessages.PORemainingBalanceInvalid);
                }

                #endregion
            }

            if (model.TransactionTypeCode == "O")
            {
                if (model.TransactionProcess == SysUtility.Enums.TransactionProcess.WEIGH_IN)
                {
                    if (model.TareWt == 0)
                    {
                        modelStateDict.Add(nameof(model.TareWt), ValidationMessages.InvalidWeight);
                    }
                }
                else if (model.TransactionProcess == SysUtility.Enums.TransactionProcess.WEIGH_OUT)
                {
                    if (model.MC == 0)
                    {
                        modelStateDict.Add(nameof(model.MC), ValidationMessages.Required("MC"));
                    }
                    if (model.TareWt == 0 || model.NetWt == 0)
                    {
                        modelStateDict.Add(nameof(model.TareWt), ValidationMessages.InvalidWeight);
                    }

                    var receiptNum = refNumRepository.Get().FirstOrDefault().PurchaseReceiptNum;
                    if (dbContext.SaleTransactions.AsNoTracking().Count(a => a.ReceiptNum == receiptNum) > 0)
                    {
                        modelStateDict.Add(nameof(model.InyardNum), ValidationMessages.InvalidReceiptNum);
                    }
                    if (model.BaleCount == 0)
                    {
                        modelStateDict.Add(nameof(model.BaleCount), ValidationMessages.Required("Bale Count"));
                    }

                    #region VALIDATE MOISTURE READER
                    if (model.MoistureReaderId.IsNullOrZero())
                    {
                        modelStateDict.Add(nameof(model.MoistureReaderId), ValidationMessages.Required("Moisture Reader"));
                    }
                    else if (MoistureReaderExists(model.MoistureReaderId ?? 0) == false)
                    {
                        modelStateDict.Add(nameof(model.MoistureReaderId), ValidationMessages.MoistureReaderNotExists);
                    }
                    #endregion
                }

                #region VALIDATE CUSTOMER / HAULER
                if (model.ClientId.IsNullOrZero() && model.HaulerId.IsNullOrZero())
                {
                    modelStateDict.Add(nameof(model.ClientId), ValidationMessages.Required("Customer/Hauler"));
                }
                if (model.ClientId.IsNullOrZero() == false)
                {
                    if (CustomerExists(model.ClientId) == false)
                    {
                        modelStateDict.Add(nameof(model.ClientId), ValidationMessages.CustomerNotExists);
                    }
                }
                if (model.HaulerId.IsNullOrZero() == false)
                {
                    if (HaulerExists(model.HaulerId ?? 0) == false)
                    {
                        modelStateDict.Add(nameof(model.HaulerId), ValidationMessages.HaulerNotExists);
                    }
                }
                #endregion

                #region VALIDATE PRODUCT
                if (model.CommodityId.IsNullOrZero())
                {
                    modelStateDict.Add(nameof(model.CommodityId), ValidationMessages.Required("Product"));
                }
                else if (ProductExists(model.CommodityId) == false)
                {
                    modelStateDict.Add(nameof(model.CommodityId), ValidationMessages.ProductNotExists);
                }
                #endregion

                #region VALIDATE BALES
                if (model.TransactionProcess == SysUtility.Enums.TransactionProcess.WEIGH_OUT)
                {
                    if (model.Bales.Count() > 0)
                    {
                        var unRelatedBalesCount = model.Bales.Count(a => a.ProductId != model.CommodityId);
                        if (unRelatedBalesCount > 0)
                        {
                            modelStateDict.Add(nameof(model.CommodityId), "Selected bales must match the product type.");
                        }
                        ;
                    }
                }
                #endregion

                #region VALIDATE PAPER MILL
                if (model.PaperMillId.IsNullOrZero())
                {
                    modelStateDict.Add(nameof(model.PaperMillId), ValidationMessages.Required("Paper Mill"));
                }
                else if (PaperMillExists(model.PaperMillId ?? 0) == false)
                {
                    modelStateDict.Add(nameof(model.PaperMillId), ValidationMessages.ProductNotExists);
                }
                #endregion
            }

            return(modelStateDict);
        }