Example #1
0
        public static ResultHelper <BA03A> BeforeSave(BA03AModel model, BA03A entity, EntityState state)
        {
            var errMsg = ""; if (state == EntityState.Added) //新增

            {
                errMsg = Validation(model);

                ToEntity(model, ref entity);
                entity.CREATE_USER = "******";
                entity.CREATE_DATE = DateTime.Now;
            }
            else if (state == EntityState.Modified)//修改
            {
                errMsg = entity == null ? "資料已被刪除" : Validation(model);

                ToEntity(model, ref entity);
                entity.UPDATE_USER = "******";
                entity.UPDATE_DATE = DateTime.Now;
            }
            else //刪除
            {
                errMsg = entity == null ? "資料已被刪除" : "";
            }

            return(new ResultHelper <BA03A>()
            {
                Data = entity, Message = errMsg
            });
        }
Example #2
0
        public ActionResult Insert(BA03AModel model, SearchViewModel search)
        {
            model.ModelState = ModelState;
            var result = Save(model, null, EntityState.Added);

            return(ResultHandler(result, search));
        }
Example #3
0
        public ResultHelper <BA03A> Save(BA03AModel model, BA03A entity, EntityState state)
        {
            var result = BA03Business.BeforeSave(model, entity, state);

            result.Message += _Service.SaveChanges(result.Data, state, result.Message);

            return(result);
        }
Example #4
0
        public ActionResult Update(BA03AModel model, SearchViewModel search)
        {
            model.ModelState = ModelState;
            var item   = _Service.GetByKey(model.BA03A_ID);
            var result = Save(model, item, EntityState.Modified);

            return(ResultHandler(result, search));
        }
Example #5
0
 public ActionResult EditForm(BA03AModel model)
 {
     if (model == null || model.BA03A_ID == 0)//新增的時候初始化
     {
         ModelState.Clear();
     }
     return(PartialView("_EditForm", model));
 }
Example #6
0
        public static BA03AModel FromEntity(BA03A entity)
        {
            var data = new BA03AModel();

            if (entity != null)
            {
                var objectHelper = new ObjectHelper();
                objectHelper.CopyValue(entity, data);
            }
            return(data);
        }
Example #7
0
        public static void ToEntity(BA03AModel model, ref BA03A entity)
        {
            if (entity == null)
            {
                entity = new BA03A();
            }
            List <string> exclusiveList = new List <string>()
            {
                "CREATE_USER", "CREATE_DATE", "LASTUPDATE_USER", "LASTUPDATE_DATE"
            };
            var objectHelper = new ObjectHelper();

            objectHelper.CopyValue(model, entity, exclusiveList);
        }
Example #8
0
        public static string Validation(BA03AModel master)
        {
            List <string> errMsgList = new List <string>();

            //if (master.REM_MM.Length > 10)
            //{
            //    master.ModelState.AddModelError("REM_MM", "太長");
            //}
            if (!master.ModelState.IsValid)
            {
                errMsgList.Add("請檢查紅色驚嘆號");
            }
            return(string.Join("<br />", errMsgList));
        }