Пример #1
0
        public ActionResult EditModel(dynamic model, Func <object, bool> pred = null)//model is new
        {
            if (ModelState.IsValid)
            {
                var managementItem = IoCConfig.Invoke_EntityManagementService(model);
                var service        = managementItem.GetService();
                var old            = service.FindById(model.Id);
                if (old == null)
                {
                    return(ErrorNotExist());
                }
                var adding_model = model.ToModel(old);
                //nếu gọi code trong hàm cha (AddDeal) thì phải cast sang kiểu con (Deal)
                //vd: var adding_model = model.ToModel() as Deal;
                if (adding_model == null)
                {
                    var error_msg = model.ErrorMessage != null ? model.ErrorMessage : "";
                    return(Error(error_msg));
                }

                //return managementItem.CheckAndEdit(adding_model);//update new to old
                var res = managementItem.CheckAndEdit(adding_model);
                if (pred != null)
                {
                    pred(adding_model);
                }

                return(res);
            }

            return(Error());
        }
Пример #2
0
        public ActionResult AddModel(dynamic model, Func <object, bool> pred = null)
        {
            if (ModelState.IsValid)
            {
                var managementItem = IoCConfig.Invoke_EntityManagementService(model);

                var adding_model = model.ToModel();
                //nếu gọi code trong hàm cha (AddDeal) thì phải cast sang kiểu con (Deal)
                //vd: var adding_model = model.ToModel() as Deal;
                if (adding_model == null)
                {
                    var error_msg = model.ErrorMessage != null ? model.ErrorMessage : "";
                    return(Error(error_msg));
                }

                //return managementItem.Add(adding_model);
                var res = managementItem.Add(adding_model);
                if (pred != null)
                {
                    pred(adding_model);
                }

                return(res);
            }

            return(Error());
        }