Esempio n. 1
0
        public static bool ValidateRemove(TR01AViewModel model, List <TR01BViewModel> updateDetail)
        {
            if (model.TR01A_ID > 0)
            {
                TR01Service _Service  = new TR01Service();
                var         hasMaster = _Service.GetA(model.TR01A_ID);
                if (hasMaster == null)
                {
                    return(false);
                }

                if (updateDetail != null && updateDetail.Count > 0)
                {
                    var            TR01B_IDList = updateDetail.Select(x => x.TR01B_ID).ToList();
                    PURSysEntities _Entity      = new PURSysEntities();
                    var            DBCount      = _Entity.TR01B.Where(x => TR01B_IDList.Contains(x.TR01B_ID)).Count();
                    if (DBCount != TR01B_IDList.Count())
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Esempio n. 2
0
        /// <summary>Entity to viewmodel Single</summary>
        /// <param name="entity">TR01A</param>
        public static TR01AViewModel FromEntity(TR01A entity)
        {
            var data = new TR01AViewModel();

            if (entity != null)
            {
                var objectHelper = new ActWeis.Utility.ObjectHelper();
                objectHelper.CopyValue(entity, data);

                #region [ 資料處理 ]
                var BA01A = CacheCommonDataModule.GetBA01A().FirstOrDefault(x => x.BA01A_ID == entity.BA01A_ID);
                if (BA01A != null)
                {
                    data.FAX_NO = BA01A.FAX_NO;
                    data.ADD_DR = BA01A.ADD_DR;
                }

                var BA01B = new Services.BA01.BA01Service().GetD(x => x.BA01B_ID == entity.BA01B_ID);
                if (BA01B != null)
                {
                    data.TEL_NO = BA01B.TEL_NO;
                    data.TEL_EX = BA01B.TEL_EX;
                }
                #endregion [ 資料處理 ]
            }
            return(data);
        }
Esempio n. 3
0
 public static bool Validation(TR01AViewModel model, ModelStateDictionary modelState)
 {
     //if (model.REM_MM != null && model.REM_MM.Length > 10)
     //{
     //    modelState.AddModelError("REM_MM", "REM_MM Too long From Business layer");
     //}
     if (model.TAX_RT < 0)
     {
         modelState.AddModelError("TAX_RT", "Error");
     }
     return(modelState.IsValid);
 }
Esempio n. 4
0
        public static bool Validation(TR01AViewModel model, MVCxGridViewBatchUpdateValues <TR01BViewModel, int> updateValues, ModelStateDictionary modelState)
        {
            if (model.TAX_RT < 0)
            {
                modelState.AddModelError("TAX_RT", "Error");
            }

            for (int i = 0; i < updateValues.Insert.Count; i++)
            {
                //if (updateValues.Insert[i].ITM_NO == null || updateValues.Insert[i].ITM_NO.Length < 1)
                //{
                //    modelState.AddModelError($"Insert[{i}].ITM_NO", "必填");
                //}
                if (updateValues.Insert[i].ITM_NM == null || updateValues.Insert[i].ITM_NM.Length < 1)
                {
                    modelState.AddModelError($"Insert[{i}].ITM_NM", "必填");
                }

                if (updateValues.Insert[i].PUR_QT < 0)
                {
                    modelState.AddModelError($"Insert[{i}].PUR_QT", "不可以小於零");
                }
                if (updateValues.IsValid(updateValues.Insert[i]) == false)
                {
                    modelState.AddModelError($"Insert[{i}]", "error");
                }
            }

            for (int i = 0; i < updateValues.Update.Count; i++)
            {
                //測試用
                //if (updateValues.Update[i].REM_MM != null && updateValues.Update[i].REM_MM.Length > 10)
                //{
                //    modelState.AddModelError($"Update[{i}].REM_MM", "REM_MM太長");
                //}
                if (updateValues.Update[i].ITM_NM == null || updateValues.Update[i].ITM_NM.Length < 1)
                {
                    modelState.AddModelError($"Update[{i}].ITM_NM", "必填");
                }
                if (updateValues.Update[i].PUR_QT < 0)
                {
                    modelState.AddModelError($"Update[{i}].PUR_QT", "不可以小於零");
                }

                if (updateValues.IsValid(updateValues.Update[i]) == false)
                {
                    modelState.AddModelError($"Update[{i}]", "error");
                }
            }

            return(modelState.IsValid);
        }
Esempio n. 5
0
        /// <summary>viewmodel to entity </summary>
        /// <param name="entity"></param>
        private static TR01A ToEntity(TR01AViewModel data)
        {
            var entity = new TR01A();

            if (data != null)
            {
                #region [ 資料處理 ]

                #endregion [ 資料處理 ]

                var objectHelper = new ActWeis.Utility.ObjectHelper();
                objectHelper.CopyValue(data, entity);
            }
            return(entity);
        }
Esempio n. 6
0
 //==========================BeforSave==========================
 public static TR01A BeforSave(TR01AViewModel data)
 {
     if (data.TR01A_ID == 0)//Adding New
     {
         data.PUR_NO      = new PURSysEntities().Database.SqlQuery <string>("select dbo.Get_PUR_NO()").FirstOrDefault();
         data.CREATE_USER = UserInfo.Id;
         data.CREATE_DATE = DateTime.Now;
         data.CFN_YN      = "N";
     }
     else//Update
     {
         TR01Service _Service = new TR01Service();
         var         TR01A    = _Service.GetA(data.TR01A_ID);
         data.CREATE_USER = TR01A.CREATE_USER;
         data.CREATE_DATE = TR01A.CREATE_DATE;
         data.UPDATE_USER = UserInfo.Id;
         data.UPDATE_DATE = DateTime.Now;
     }
     return(ToEntity(data));
 }