Exemple #1
0
        //Summary: get error tu model state tra về List<ErrorModel>
        public static List <ErrorModel> getErrorList(ModelStateDictionary model)
        {
            List <ErrorModel> lstErrors = new List <ErrorModel>();

            foreach (var state in model)
            {
                foreach (var error in state.Value.Errors)
                {
                    ErrorModel item = new ErrorModel();
                    //Check độ dài mess lỗi xem mess có chưa code lỗi không nếu có thì dùng trong chuỗi
                    if (error.ErrorMessage.Contains('@'))
                    {
                        String[] strtmp = error.ErrorMessage.Split('@');
                        item.code    = strtmp[0];
                        item.message = strtmp[1];
                    }
                    else if (!String.IsNullOrEmpty(error.ErrorMessage))
                    {
                        item.code    = error.ErrorMessage;
                        item.message = ConfigMultiLanguage.getMess(error.ErrorMessage);
                    }
                    else
                    {
                        item.code    = "Exception";
                        item.message = error.Exception.Message + " " + error.Exception.StackTrace;
                    }
                    lstErrors.Add(item);
                }
            }
            return(lstErrors);
        }
Exemple #2
0
 /// <summary>
 /// Return a list of entities by filter and paging (T parameter is a type of the entity).
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="predicate"></param>
 /// <param name="pageNumber"></param>
 /// <param name="pageSize"></param>
 /// <returns></returns>
 public List <T> Filter <T>(Expression <Func <T, bool> > predicate, int pageNumber, int pageSize, String namePropertyOrder)
     where T : class
 {
     if (pageNumber < 1)
     {
         throw new Exception(ConfigMultiLanguage.getMess(ConstantsMultiLanguageKey.SO_TRANG_KHONG_HOP_LE));
     }
     return(db.Set <T>().Where(predicate).OrderBy <T>(namePropertyOrder).Skip((pageNumber - 1) * pageSize).Take(pageSize).ToList());
 }
Exemple #3
0
        /// <summary>
        /// get Error theo key multilanguage
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static String getError(String key)
        {
            List <ErrorModel> lstErrors = new List <ErrorModel>();
            ErrorModel        item      = new ErrorModel();

            item.code    = key;
            item.message = ConfigMultiLanguage.getMess(key);
            lstErrors.Add(item);
            return(JsonConvert.SerializeObject(lstErrors));
        }
Exemple #4
0
        /// <summary>
        /// check required cho list model
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="lstObject">list object cần check required</param>
        /// <param name="arr">mảng chuỗi tên thuộc tính cần check required</param>
        /// <returns>Chuỗi nội dung lỗi</returns>
        public static List <String> validateRequiredList <T>(List <T> lstObject, params string[] arr)
        {
            List <String> lstError = new List <String>();

            for (int i = 0; i < lstObject.Count; i++)
            {
                foreach (String propertyName in arr)
                {
                    PropertyInfo pro = lstObject[i].GetType().GetProperty(propertyName);
                    if (pro.PropertyType == typeof(String))
                    {
                        object obj = pro.GetValue(lstObject[i], null);
                        if (obj == null || String.IsNullOrEmpty(obj.ToString()))
                        {
                            lstError.Add(ConfigMultiLanguage.getMessWithKey(String.Format(ConstantsMultiLanguageKey.E_REQUIRED_002, i + 1, propertyName)));
                        }
                    }
                    if (pro.PropertyType == typeof(DateTime))
                    {
                        DateTime obj = (DateTime)pro.GetValue(lstObject[i], null);
                        if (obj == null || obj == DateTime.MinValue)
                        {
                            lstError.Add(ConfigMultiLanguage.getMessWithKey(String.Format(ConstantsMultiLanguageKey.E_REQUIRED_002, i + 1, propertyName)));
                        }
                    }
                    else if (pro.PropertyType == typeof(int?))
                    {
                        int?objTmp = (int?)pro.GetValue(lstObject[i], null);
                        if (objTmp == null)
                        {
                            lstError.Add(String.Format(ConfigMultiLanguage.getMessWithKey(ConstantsMultiLanguageKey.E_REQUIRED_002), i + 1, propertyName));
                        }
                    }
                    else if (pro.PropertyType == typeof(decimal?))
                    {
                        decimal?objTmp = (decimal?)pro.GetValue(lstObject[i], null);
                        if (objTmp == null)
                        {
                            lstError.Add(String.Format(ConfigMultiLanguage.getMessWithKey(ConstantsMultiLanguageKey.E_REQUIRED_002), i + 1, propertyName));
                        }
                    }
                    else if (pro.PropertyType == typeof(double?))
                    {
                        double?objTmp = (double?)pro.GetValue(lstObject[i], null);
                        if (objTmp == null)
                        {
                            lstError.Add(String.Format(ConfigMultiLanguage.getMessWithKey(ConstantsMultiLanguageKey.E_REQUIRED_002), i + 1, propertyName));
                        }
                    }
                }
            }

            return(lstError);
        }
Exemple #5
0
        public static List <String> validateRequiredObject(string[] name, params object[] arr)
        {
            List <String> lstError = new List <String>();

            for (int i = 0; i < arr.Length; i++)
            {
                if (arr[i] == null)
                {
                    lstError.Add(String.Format(ConfigMultiLanguage.getMessWithKey(ConstantsMultiLanguageKey.E_REQUIRED_001), name[i]));
                }
                else if (arr[i].GetType() == typeof(String))
                {
                    String objTmp = (String)arr[i];
                    if (objTmp == null || String.IsNullOrEmpty(objTmp))
                    {
                        lstError.Add(String.Format(ConfigMultiLanguage.getMessWithKey(ConstantsMultiLanguageKey.E_REQUIRED_001), name[i]));
                    }
                }
                else if (arr[i].GetType() == typeof(DateTime))
                {
                    DateTime objTmp = (DateTime)arr[i];
                    if (arr[i] == null || objTmp == DateTime.MinValue)
                    {
                        lstError.Add(String.Format(ConfigMultiLanguage.getMessWithKey(ConstantsMultiLanguageKey.E_REQUIRED_001), name[i]));
                    }
                }
                else if (arr[i].GetType() == typeof(int?))
                {
                    int?objTmp = (int?)arr[i];
                    if (objTmp == null)
                    {
                        lstError.Add(String.Format(ConfigMultiLanguage.getMessWithKey(ConstantsMultiLanguageKey.E_REQUIRED_001), name[i]));
                    }
                }
                else if (arr[i].GetType() == typeof(decimal?))
                {
                    decimal?objTmp = (decimal?)arr[i];
                    if (objTmp == null)
                    {
                        lstError.Add(String.Format(ConfigMultiLanguage.getMessWithKey(ConstantsMultiLanguageKey.E_REQUIRED_001), name[i]));
                    }
                }
                else if (arr[i].GetType() == typeof(double?))
                {
                    double?objTmp = (double?)arr[i];
                    if (objTmp == null)
                    {
                        lstError.Add(String.Format(ConfigMultiLanguage.getMessWithKey(ConstantsMultiLanguageKey.E_REQUIRED_001), name[i]));
                    }
                }
            }
            return(lstError);
        }
Exemple #6
0
        public static ValidationResult checkExistInvoice(String fkey)
        {
            PVOILInvoiceDA pvOil  = new PVOILInvoiceDA();
            PVOILInvoice   objInv = pvOil.checkExistInvoice(fkey);

            if (objInv != null)
            {
                return(new ValidationResult(String.Format(ConfigMultiLanguage.getMessWithKey(ConstantsMultiLanguageKey.E_Invoice_Exist), fkey)));
            }
            else
            {
                return(null);
            }
        }
Exemple #7
0
        public static ValidationResult checkFormatDate(String dateT, String inputFormat, String nameCheck, String errorCode)
        {
            DateTime    d;
            CultureInfo provider = CultureInfo.InvariantCulture;

            if (DateTime.TryParseExact(dateT, inputFormat, provider, DateTimeStyles.None, out d))
            {
                return(null);
            }
            else
            {
                return(new ValidationResult(String.Format(ConfigMultiLanguage.getMessWithKey(errorCode), nameCheck)));
            }
        }
Exemple #8
0
        public static ValidationResult checkExistCustaxcode(String custaxcode, out Customer objOut)
        {
            CustomerDA ctlCustomer = new CustomerDA();

            objOut = ctlCustomer.checkExistCustaxcode(custaxcode);
            if (objOut == null)
            {
                return(new ValidationResult(String.Format(ConfigMultiLanguage.getMessWithKey(ConstantsMultiLanguageKey.E_CustomerTaxCode_Exist), custaxcode)));
            }
            else
            {
                return(null);
            }
        }
Exemple #9
0
        public static ValidationResult checkSoAm(object objCheck, String nameCheck, String errorCode)
        {
            if (objCheck == null)
            {
                return(new ValidationResult(String.Format(ConfigMultiLanguage.getMessWithKey(errorCode), nameCheck)));
            }
            else if (objCheck.GetType() == typeof(String))
            {
                String objCheckStr = (String)objCheck;
                if (String.IsNullOrEmpty(objCheckStr))
                {
                    return(new ValidationResult(String.Format(ConfigMultiLanguage.getMessWithKey(errorCode), nameCheck)));
                }
                if (Convert.ToDecimal(objCheckStr) < 0)
                {
                    return(new ValidationResult(String.Format(ConfigMultiLanguage.getMessWithKey(errorCode), nameCheck)));
                }
                else
                {
                    return(null);
                }
            }
            else if (objCheck.GetType() == typeof(int))
            {
                int objCheckInt = (int)objCheck;
                if (objCheckInt < 0)
                {
                    return(new ValidationResult(String.Format(ConfigMultiLanguage.getMessWithKey(errorCode), nameCheck)));
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                decimal objCheckDecimal = (decimal)objCheck;

                if (objCheckDecimal < 0)
                {
                    return(new ValidationResult(String.Format(ConfigMultiLanguage.getMessWithKey(errorCode), nameCheck)));
                }
                else
                {
                    return(null);
                }
            }
        }
Exemple #10
0
        public static ValidationResult checkExistNoInvoice(String fkey, out PVOILInvoice objOut)
        {
            PVOILInvoiceDA pvOil  = new PVOILInvoiceDA();
            PVOILInvoice   objInv = pvOil.checkExistInvoice(fkey);

            if (objInv == null)
            {
                objOut = null;
                return(new ValidationResult(ConfigMultiLanguage.getMess(ConstantsMultiLanguageKey.E_InvoiceDelete_NotExist)));
            }
            else
            {
                objOut = objInv;
                return(null);
            }
        }
Exemple #11
0
        public static ValidationResult checkDoDaiSo(String objCheck, int length, String nameCheck, String errorCode)
        {
            if (String.IsNullOrEmpty(objCheck))
            {
                return(new ValidationResult(String.Format(ConfigMultiLanguage.getMessWithKey(errorCode), nameCheck, length)));
            }

            if (objCheck.Length > length)
            {
                return(new ValidationResult(String.Format(ConfigMultiLanguage.getMessWithKey(errorCode), nameCheck, length)));
            }
            else
            {
                return(null);
            }
        }
Exemple #12
0
        /// <summary>
        /// Update an entity by expression (T parameter is a type of the entity).
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="entity"></param>
        /// <param name="predicate"></param>
        public void Update <T>(T entity, Expression <Func <T, bool> > predicate) where T : class
        {
            var t = db.Set <T>().Where(predicate).SingleOrDefault();

            if (t == null)
            {
                throw new NullReferenceException(ConfigMultiLanguage.getMess(ConstantsMultiLanguageKey.DOI_TUONG_KHONG_TON_TAI));
            }
            if (!t.Equals(entity))
            {
                foreach (var p in t.GetType().GetProperties())
                {
                    p.SetValue(t, p.GetValue(entity, null), null);
                }
            }
            db.SaveChanges();
        }
Exemple #13
0
        /// <summary>
        /// Check gia tri ton tai trong 1 struc hay khong
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="objCheck">đối tượng cần check tồn tại</param>
        /// <param name="nameCheck">tên đối tượng cần check tồn tại để trả về</param>
        /// <param name="errorCode">tên mã lỗi</param>
        /// <returns></returns>
        public static ValidationResult checkValueInArrayValue <T>(object objCheck, String nameCheck, String errorCode)
        {
            try
            {
                if (objCheck == null)
                {
                    return(new ValidationResult(String.Format(ConfigMultiLanguage.getMessWithKey(errorCode), nameCheck)));
                }
                else if (objCheck.GetType() == typeof(int))
                {
                    int invoiceTypeInt = (int)objCheck;
                    if (!Untility.checkExistStrucString <T>(invoiceTypeInt.ToString()))
                    {
                        return(new ValidationResult(String.Format(ConfigMultiLanguage.getMessWithKey(errorCode), nameCheck)));
                    }
                    else
                    {
                        return(null);
                    }
                }
                else if (objCheck.GetType() == typeof(String))
                {
                    String objCheckStr = (String)objCheck;

                    if (!Untility.checkExistStrucString <T>(objCheckStr))
                    {
                        return(new ValidationResult(String.Format(ConfigMultiLanguage.getMessWithKey(errorCode), nameCheck)));
                    }
                    else
                    {
                        return(null);
                    }
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemple #14
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            //Cầu hình cho log4net
            log4net.Config.XmlConfigurator.Configure();

            //Cấu hình Automapper
            AutoMapperConfiguration.Configure();

            //Cấu hình đa ngôn ngữ
            String culture       = ConfigurationManager.AppSettings["culture"];
            String ForderCulture = ConfigurationManager.AppSettings["ForderCulture"];

            ConfigMultiLanguage.Configure(culture, ForderCulture);

            //Cấu hình dependence injection
            // Create the container as usual.
            var container = new Container();

            container.Options.DefaultScopedLifestyle = new AsyncScopedLifestyle();

            // Register your types, for instance using the scoped lifestyle:
            //Lifestyle:
            //Singleton trong suốt vòng đời ứng dụng chỉ có 1 instance duy nhất
            //Scoped: Chỉ tồn tại 1 instance trong 1 lần request (mỗi request là 1 scope).
            //Transient: Một instance mới luôn được tạo, mỗi khi được yêu cầu.
            container.Register <IInvoiceCategorys, InvoiceCategorysService>(Lifestyle.Scoped);
            container.Register <IInvoice, InvoiceService>(Lifestyle.Scoped);
            container.Register <IAuthentication, AuthenticationService>(Lifestyle.Scoped);

            // This is an extension method from the integration package.
            container.RegisterWebApiControllers(GlobalConfiguration.Configuration);

            container.Verify();

            GlobalConfiguration.Configuration.DependencyResolver =
                new SimpleInjectorWebApiDependencyResolver(container);
        }
Exemple #15
0
 /// <summary>
 /// check required cho model
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="objectVal">object can check required</param>
 /// <param name="arr">mảng chuỗi tên thuộc tính càn check required</param>
 /// <returns>Chuỗi nội dung lỗi</returns>
 public static String validateRequiredObject <T>(T objectVal, params string[] arr)
 {
     foreach (String propertyName in arr)
     {
         PropertyInfo pro = objectVal.GetType().GetProperty(propertyName);
         if (pro.PropertyType == typeof(String))
         {
             object obj = pro.GetValue(objectVal, null);
             if (obj == null || String.IsNullOrEmpty(obj.ToString()))
             {
                 return(String.Format(ConfigMultiLanguage.getMess(ConstantsMultiLanguageKey.E_REQUIRED_001), propertyName));
             }
         }
         if (pro.PropertyType == typeof(DateTime))
         {
             DateTime obj = (DateTime)pro.GetValue(objectVal, null);
             if (obj == null || obj == DateTime.MinValue)
             {
                 return(String.Format(ConfigMultiLanguage.getMess(ConstantsMultiLanguageKey.E_REQUIRED_002), propertyName));
             }
         }
     }
     return(null);
 }
Exemple #16
0
        /// <summary>
        /// ham validate model
        /// </summary>
        /// <param name="validationContext"></param>
        /// <returns></returns>
        public IEnumerable <ValidationResult> Validate(System.ComponentModel.DataAnnotations.ValidationContext validationContext)
        {
            AdjustInvDH ctlAdj      = new AdjustInvDH();
            Boolean     draftCancel = invoice.DraftCancel ?? false;

            //check hoa đơn hủy
            if ((invoice.Type == InvoiceType.Nomal || invoice.Type == InvoiceType.ForReplace || invoice.Type == InvoiceType.ForAdjustAccrete ||
                 invoice.Type == InvoiceType.ForAdjustReduce ||
                 invoice.Type == InvoiceType.ForAdjustInfo) && draftCancel)
            {
                List <String> validateRequestHuy = ModelBase.validateRequiredObject(new string[] { "key"
                                                                                                   , "invoice.Type", "invoice.Status", "invoice.DraftCancel", "invoice.ComtaxCode" }, new object[] { key, invoice.Type, invoice.Status, invoice.DraftCancel, invoice.ComTaxCode });
                foreach (String item in validateRequestHuy)
                {
                    yield return(new ValidationResult(item));
                }
                //check invoice co ton tai hay ko
                PVOILInvoice objOut;
                yield return(ModelValidate.checkExistNoInvoice(key, out objOut));

                //type=0,1,2,3,4 and status=0 and draftcancel=1 check key họ truyền lên với fkey trong bảng pvoilinvie là status=3 hoặc 5 thì k nhận báo lỗi
                if (objOut != null)
                {
                    if (objOut.Status == Untilities.Common.Constants.InvoiceStatus.Bi_Thay_The ||
                        objOut.Status == Untilities.Common.Constants.InvoiceStatus.Xoa_Bo)
                    {
                        yield return(new ValidationResult(ConstantsMultiLanguageKey.E_Invoice_Status_3_5));
                    }
                    // Check trong bảng [AdjustInv] nếu đã tồn tại invid của key truyền lên thì báo lỗi
                    AdjustInv objAdj = ctlAdj.CheckExists(objOut.id);
                    if (objAdj != null)
                    {
                        yield return(new ValidationResult(String.Format(ConfigMultiLanguage.getMessWithKey(ConstantsMultiLanguageKey.E_AdjustInv_Exist), key)));
                    }
                }

                //if (invoice.Status != 1)
                //{
                //    yield return new ValidationResult(ConstantsMultiLanguageKey.E_Invoice_Status_Delete);
                //}
            }
            else
            {
                List <String> validateRequest = ModelBase.validateRequiredObject(new string[] { "key"
                                                                                                , "invoice.ComtaxCode", "invoice.BusinessDepartmentID", "invoice.Type", "invoice.Status"
                                                                                                , "invoice.PaymentMethod", "invoice.PaymentStatus", "invoice.CreateDate", "invoice.CreateBy"
                                                                                                , "invoice.Total"
                                                                                                , "invoice.VATRate", "invoice.VATAmount", "invoice.Amount"
                                                                                                , "invoice.AmountInWords"
                                                                                                , "invoice.Otherfees"
                                                                                                , "invoice.Currency"
                                                                                                , "invoice.ExchangeRate" }, new object[] { key
                                                                                                                                           , invoice.ComTaxCode, invoice.BusinessDepartmentID, invoice.Type, invoice.Status
                                                                                                                                           , invoice.PaymentMethod, invoice.PaymentStatus, invoice.CreateDate, invoice.CreateBy
                                                                                                                                           , invoice.Total
                                                                                                                                           , invoice.VATRate, invoice.VATAmount, invoice.Amount
                                                                                                                                           , invoice.AmountInWords
                                                                                                                                           , invoice.OtherFees
                                                                                                                                           , invoice.Currency
                                                                                                                                           , invoice.ExchangeRate });
                foreach (String item in validateRequest)
                {
                    yield return(new ValidationResult(item));
                }

                //ton tai du lieu 1 trong 3 column sau CusTaxCode,CusName,CusAddress thì ca 3 column này phải có data
                if (String.IsNullOrEmpty(invoice.Buyer))
                {
                    List <String> validateRequestCus = ModelBase.validateRequiredObject(new string[] { "invoice.CusTaxCode",
                                                                                                       "invoice.CusName",
                                                                                                       "invoice.CusAddress" }, new object[] { invoice.CusTaxCode, invoice.CusName, invoice.CusAddress });
                    foreach (String item in validateRequestCus)
                    {
                        yield return(new ValidationResult(item));
                    }
                }


                if (invoice.Status != 0)
                {
                    new ValidationResult(ConstantsMultiLanguageKey.E_Invoice_Status_Create);
                }
                else
                {
                    if ((invoice.Type == InvoiceType.Nomal ||
                         invoice.Type == InvoiceType.ForReplace || invoice.Type == InvoiceType.ForAdjustAccrete ||
                         invoice.Type == InvoiceType.ForAdjustReduce ||
                         invoice.Type == InvoiceType.ForAdjustInfo) && invoice.DraftCancel != null)
                    {
                        if (!(invoice.Type == InvoiceType.Nomal && !draftCancel))
                        {
                            String noCheckOk = HttpContext.Current.Request.QueryString["NoCheckOK"];
                            if ((!((invoice.Type == InvoiceType.ForAdjustReduce || invoice.Type == InvoiceType.ForAdjustAccrete) && !draftCancel)) || noCheckOk == null)
                            {
                                List <String> validateRequestCus = ModelBase.validateRequiredObject(new string[] { "invoice.originalKey" },
                                                                                                    new object[] { invoice.originalKey });
                                foreach (String item in validateRequestCus)
                                {
                                    yield return(new ValidationResult(item));
                                }
                            }
                        }
                        //hoa don ko phai huy
                        if (!draftCancel)
                        {
                            //check invoice co ton tai hay ko
                            yield return(ModelValidate.checkExistInvoice(key));

                            if (invoice.Status != 0)
                            {
                                new ValidationResult(ConstantsMultiLanguageKey.E_Invoice_Status_Create);
                            }
                            PVOILInvoiceDA pvOil = new PVOILInvoiceDA();
                            //originalKey trong bảng pvoilinvie là status=3 hoặc 5 thì k nhận báo lỗi
                            PVOILInvoice objInvoice = pvOil.checkExistInvoice(invoice.originalKey);
                            if (objInvoice != null)
                            {
                                if (objInvoice.Status == Untilities.Common.Constants.InvoiceStatus.Bi_Thay_The ||
                                    objInvoice.Status == Untilities.Common.Constants.InvoiceStatus.Xoa_Bo)
                                {
                                    yield return(new ValidationResult(ConstantsMultiLanguageKey.E_Invoice_Status_3_5));
                                }
                            }
                            // type=1,2,3,4 check id của originalKey có trong bảng [AdjustInv] chưa?. nếu có status khác 0,1,2 báo lỗi
                            if ((invoice.Type == InvoiceType.ForReplace || invoice.Type == InvoiceType.ForAdjustAccrete ||
                                 invoice.Type == InvoiceType.ForAdjustReduce ||
                                 invoice.Type == InvoiceType.ForAdjustInfo) && objInvoice != null)
                            {
                                AdjustInv objAdj = ctlAdj.CheckExistsAdj(Convert.ToInt64(objInvoice.id));
                                if (objAdj != null && (objAdj.Status != Untilities.Common.Constants.StatusAdj.Adj_0 &&
                                                       objAdj.Status != Untilities.Common.Constants.StatusAdj.Adj_1 &&
                                                       objAdj.Status != Untilities.Common.Constants.StatusAdj.Adj_2))
                                {
                                    yield return(new ValidationResult(String.Format(ConfigMultiLanguage.getMessWithKey(ConstantsMultiLanguageKey.E_AdjustInv_ThayThe), invoice.originalKey)));
                                }
                            }
                            // type=1,2,3,4 thì bắt truyền trường ProcessInvNote => "bắt buộc nhập ProcessInvNote"
                            if (invoice.Type == InvoiceType.ForReplace || invoice.Type == InvoiceType.ForAdjustAccrete ||
                                invoice.Type == InvoiceType.ForAdjustReduce || invoice.Type == InvoiceType.ForAdjustInfo)
                            {
                                List <String> validateRequestProcessInvNote = ModelBase.validateRequiredObject(new string[] { "invoice.ProcessInvNote" },
                                                                                                               new object[] { invoice.ProcessInvNote });
                                foreach (String item in validateRequestProcessInvNote)
                                {
                                    yield return(new ValidationResult(item));
                                }
                            }
                            //  type=4 : check originalKey nếu tồn tại type=4 thì sẽ chỉ nhận type=4 k nhận type=1,2,3 của fkey mới
                            if (invoice.Type == InvoiceType.ForAdjustInfo)
                            {
                                if (objInvoice.Type == InvoiceType.ForAdjustInfo)
                                {
                                    yield return(new ValidationResult(String.Format(ConfigMultiLanguage.getMessWithKey(ConstantsMultiLanguageKey.E_Invoice_DaDieuChinhThongTin), invoice.originalKey)));
                                }
                            }
                        }
                        //else if (draftCancel)
                        //{
                        //    if (invoice.Status != 1)
                        //    {
                        //        new ValidationResult(ConstantsMultiLanguageKey.E_Invoice_Status_Delete);
                        //    }
                        //}
                        //check mau hoa don khong được điều chỉnh thay thế
                        if ((invoice.Type == InvoiceType.ForReplace || invoice.Type == InvoiceType.ForAdjustAccrete ||
                             invoice.Type == InvoiceType.ForAdjustReduce ||
                             invoice.Type == InvoiceType.ForAdjustInfo) && invoice.DraftCancel != null)
                        {
                            yield return(ModelValidate.checkExistInvoiceTemplateTypeView(invoice.Type ?? 8));
                        }
                    }
                    else
                    {
                        //check invoice co ton tai hay ko
                        yield return(ModelValidate.checkExistInvoice(key));
                    }
                }



                CustomerDA ctlCustomer = new CustomerDA();
                Customer   objCus      = ctlCustomer.checkExistCustaxcode(invoice.CusTaxCode);
                if (objCus != null)
                {
                    invoice.CusAddress = objCus.Address;
                    invoice.CusName    = objCus.Name;
                }

                WareHouseDA ctlWareHouse = new WareHouseDA();
                Warehouse   objWareHouse = ctlWareHouse.checkExistWarehouse(invoice.COutputWarehouseID ?? 0);
                if (objWareHouse != null)
                {
                    invoice.COutputWarehouseCode = objWareHouse.Code;
                    invoice.COutputWarehouse     = objWareHouse.Name;
                }
                //check hàng hóa
                List <String> validateRequestProduct = ModelBase.validateRequiredList <ProductModel>(invoice.products,
                                                                                                     new string[] { "VATRate", "VATAmount" });
                foreach (String item in validateRequestProduct)
                {
                    yield return(new ValidationResult(item));
                }

                int ComID = invoice.ComID ?? default(int);

                //Check company
                //yield return ModelValidate.checkComID(ComID);
                //Check buyer
                //yield return ModelValidate.checkExistBuyer(invoice.Buyer);

                yield return(ModelValidate.checkValueInArrayValue <InvoiceType>(invoice.Type, "Type", ConstantsMultiLanguageKey.E_InValid_Value));

                yield return(ModelValidate.checkValueInArrayValue <PaymentMethod>(invoice.PaymentMethod, "PaymentMethod", ConstantsMultiLanguageKey.E_InValid_Value));

                yield return(ModelValidate.checkValueInArrayValue <InvoiceStatus>(invoice.Status, "Status", ConstantsMultiLanguageKey.E_InValid_Value));

                yield return(ModelValidate.checkValueInArrayValue <PaymentStatus>(invoice.PaymentStatus, "PaymentStatus", ConstantsMultiLanguageKey.E_InValid_Value));

                yield return(ModelValidate.checkValueInArrayValue <VATRate>(invoice.VATRate, "VATRate", ConstantsMultiLanguageKey.E_InValid_Value));

                yield return(ModelValidate.checkDoDaiSo(invoice.Total.ToString(), LengthNumber.DO_DAI_19, "Total", ConstantsMultiLanguageKey.E_String_Length));

                yield return(ModelValidate.checkSoAm(invoice.Total, "Total", ConstantsMultiLanguageKey.E_Number_Value));

                yield return(ModelValidate.checkDoDaiSo(invoice.VATAmount.ToString(), LengthNumber.DO_DAI_19, "VATAmount", ConstantsMultiLanguageKey.E_String_Length));

                yield return(ModelValidate.checkSoAm(invoice.VATAmount, "VATAmount", ConstantsMultiLanguageKey.E_Number_Value));

                yield return(ModelValidate.checkDoDaiSo(invoice.Amount.ToString(), LengthNumber.DO_DAI_19, "Amount", ConstantsMultiLanguageKey.E_String_Length));

                yield return(ModelValidate.checkSoAm(invoice.Amount, "Amount", ConstantsMultiLanguageKey.E_Number_Value));

                yield return(ModelValidate.checkDoDaiSo(invoice.AmountInWords, LengthNumber.DO_DAI_255, "AmountInWords", ConstantsMultiLanguageKey.E_String_Length));

                yield return(ModelValidate.checkDoDaiSo(invoice.OtherFees.ToString(), LengthNumber.DO_DAI_19, "Otherfees", ConstantsMultiLanguageKey.E_String_Length));

                yield return(ModelValidate.checkSoAm(invoice.OtherFees, "Otherfees", ConstantsMultiLanguageKey.E_Number_Value));

                yield return(ModelValidate.checkDoDaiSo(invoice.ExchangeRate.ToString(), LengthNumber.DO_DAI_19, "ExchangeRate", ConstantsMultiLanguageKey.E_String_Length));

                yield return(ModelValidate.checkSoAm(invoice.ExchangeRate, "ExchangeRate", ConstantsMultiLanguageKey.E_Number_Value));

                yield return(ModelValidate.checkDoDaiSo(invoice.Currency, LengthNumber.DO_DAI_3, "Currency", ConstantsMultiLanguageKey.E_String_Length));



                //yield return ModelValidate.checkCurrency(invoice.Currency);

                ///Check BusinessDepartment ID
                BusinessDepartment objBD         = null;
                Business           objB          = null;
                PublishInvoice     objPInvoice   = null;
                Department         objDepartment = null;
                userdata           objuser       = null;
                //Lấy BusinessID
                yield return(ModelValidate.checkExistBussinessDepartment(invoice.BusinessDepartmentID, out objBD));

                if (objBD != null)
                {
                    //Lấy thông tin Business
                    yield return(ModelValidate.checkExistBussiness(objBD.BusinessID, out objB));

                    if (invoice.ModifiedDate == null)
                    {
                        invoice.ModifiedDate = DateTime.Now;
                    }
                    if (invoice.PublishDate == null)
                    {
                        invoice.PublishDate = DateTime.Now;
                    }
                    //check khac nhau giua tax code dang nhap va bussinessDepartment
                    if (!invoice.ComTaxCode.Equals(objB.TaxCode))
                    {
                        yield return(new ValidationResult(ConstantsMultiLanguageKey.E_TAXCODEDANGNHAP_TAXCODEBUSINESSDEPARTMENT));
                    }
                    //lay tax code
                    invoice.ComTaxCode = objB.TaxCode;
                    if (objB != null)
                    {
                        invoice.Serial     = objB.InvSerial;
                        invoice.Pattern    = objB.InvPattern;
                        invoice.BusinessID = objBD.BusinessID;
                        //lấy thông tin company
                        CompanyDA ctlCompany = new CompanyDA();
                        Company   company    = ctlCompany.checkExistByID(objB.ComID);
                        if (company != null)
                        {
                            invoice.ComName    = company.Name;
                            invoice.ComAddress = company.Address;
                        }
                        //Lấy thông tin Publish Invoice
                        yield return(ModelValidate.checkExistPublishInvoice(objB.InvSerial, objB.InvPattern, objB.ComID, out objPInvoice));

                        if (objPInvoice != null)
                        {
                            invoice.Name = objPInvoice.InvCateName;
                        }
                        //Lấy thông tin Publish Invoice
                        yield return(ModelValidate.checkExistDepartment(objBD.DepartmentID, out objDepartment));

                        if (objDepartment != null)
                        {
                            invoice.DepartmentID  = objBD.DepartmentID;
                            invoice.BranchCode    = objDepartment.Code;
                            invoice.BranchName    = objDepartment.Name;
                            invoice.BranchAddress = objDepartment.Address;
                            invoice.BranchPhone   = objDepartment.Phone;
                            invoice.ComID         = objDepartment.ComID;
                        }
                        //Lấy thông tin User
                        yield return(ModelValidate.checkUsersByID(objBD.UserID, out objuser));

                        if (objuser != null)
                        {
                            if (HttpContext.Current.Request.Headers["Authentication"] != null)
                            {
                                String[] authentication = Untility.decodeBase64(HttpContext.Current.Request.Headers["Authentication"]).Split(':');
                                String   userNameLogin  = authentication[0];
                                //check khac nhau giua username dang nhap va bussinessDepartment
                                if (!objuser.username.Equals(userNameLogin))
                                {
                                    yield return(new ValidationResult(ConstantsMultiLanguageKey.E_USERNAMEDANGNHAP_USERNAMEBUSINESSDEPARTMENT));
                                }
                            }

                            if (!objuser.IsApproved ?? !eInvoice.Untilities.Common.Constants.ActiveUser.INACTIVE)
                            {
                                yield return(new ValidationResult(String.Format(ConfigMultiLanguage.getMessWithKey(ConstantsMultiLanguageKey.E_User_Active), objuser.username)));
                            }
                        }
                    }
                }
            }
        }