public virtual bool Create(ref ValidationErrors errors, Spl_ProductCategoryModel model)
        {
            try
            {
                Spl_ProductCategory entity = m_Rep.GetById(model.Id);
                if (entity != null)
                {
                    errors.Add(Resource.PrimaryRepeat);
                    return(false);
                }
                entity            = new Spl_ProductCategory();
                entity.Id         = model.Id;
                entity.Name       = model.Name;
                entity.CreateTime = model.CreateTime;
                entity.CreateBy   = model.CreateBy;


                if (m_Rep.Create(entity))
                {
                    return(true);
                }
                else
                {
                    errors.Add(Resource.InsertFail);
                    return(false);
                }
            }
            catch (Exception ex)
            {
                errors.Add(ex.Message);
                ExceptionHander.WriteException(ex);
                return(false);
            }
        }
        public virtual bool Edit(ref ValidationErrors errors, Spl_ProductCategoryModel model)
        {
            try
            {
                Spl_ProductCategory entity = m_Rep.GetById(model.Id);
                if (entity == null)
                {
                    errors.Add(Resource.Disable);
                    return(false);
                }
                entity.Id         = model.Id;
                entity.Name       = model.Name;
                entity.CreateTime = model.CreateTime;
                entity.CreateBy   = model.CreateBy;



                if (m_Rep.Edit(entity))
                {
                    return(true);
                }
                else
                {
                    errors.Add(Resource.NoDataChange);
                    return(false);
                }
            }
            catch (Exception ex)
            {
                errors.Add(ex.Message);
                ExceptionHander.WriteException(ex);
                return(false);
            }
        }
示例#3
0
        public ActionResult Edit(string id)
        {
            ViewBag.Perm = GetPermission();
            Spl_ProductCategoryModel entity = m_BLL.GetById(id);

            return(View(entity));
        }
示例#4
0
        /// <summary>
        /// 校验Excel数据,这个方法一般用于重写校验逻辑
        /// </summary>
        public virtual bool CheckImportData(string fileName, List <Spl_ProductCategoryModel> list, ref ValidationErrors errors)
        {
            var targetFile = new FileInfo(fileName);

            if (!targetFile.Exists)
            {
                errors.Add("导入的数据文件不存在");
                return(false);
            }

            var excelFile = new ExcelQueryFactory(fileName);

            //对应列头
            excelFile.AddMapping <Spl_ProductCategoryModel>(x => x.Name, "Name");
            excelFile.AddMapping <Spl_ProductCategoryModel>(x => x.CreateTime, "CreateTime");
            excelFile.AddMapping <Spl_ProductCategoryModel>(x => x.CreateBy, "CreateBy");

            //SheetName
            var excelContent = excelFile.Worksheet <Spl_ProductCategoryModel>(0);
            int rowIndex     = 1;

            //检查数据正确性
            foreach (var row in excelContent)
            {
                var errorMessage = new StringBuilder();
                var entity       = new Spl_ProductCategoryModel();
                entity.Id         = row.Id;
                entity.Name       = row.Name;
                entity.CreateTime = row.CreateTime;
                entity.CreateBy   = row.CreateBy;

                //=============================================================================
                if (errorMessage.Length > 0)
                {
                    errors.Add(string.Format(
                                   "第 {0} 列发现错误:{1}{2}",
                                   rowIndex,
                                   errorMessage,
                                   "<br/>"));
                }
                list.Add(entity);
                rowIndex += 1;
            }
            if (errors.Count > 0)
            {
                return(false);
            }
            return(true);
        }
        public virtual Spl_ProductCategoryModel GetById(string id)
        {
            if (IsExists(id))
            {
                Spl_ProductCategory      entity = m_Rep.GetById(id);
                Spl_ProductCategoryModel model  = new Spl_ProductCategoryModel();
                model.Id         = entity.Id;
                model.Name       = entity.Name;
                model.CreateTime = entity.CreateTime;
                model.CreateBy   = entity.CreateBy;

                return(model);
            }
            else
            {
                return(null);
            }
        }
示例#6
0
        public virtual async Task <Spl_ProductCategoryModel> GetByIdAsync(object id)
        {
            if (IsExists(id))
            {
                Spl_ProductCategory entity = await m_Rep.GetByIdAsync(id);

                Spl_ProductCategoryModel model = new Spl_ProductCategoryModel();
                model.Id         = entity.Id;
                model.Name       = entity.Name;
                model.CreateTime = entity.CreateTime;
                model.CreateBy   = entity.CreateBy;

                return(model);
            }
            else
            {
                return(null);
            }
        }
 public JsonResult Edit(Spl_ProductCategoryModel model)
 {
     if (model != null && ModelState.IsValid)
     {
         if (m_BLL.Edit(ref errors, model))
         {
             LogHandler.WriteServiceLog(GetUserId(), "Id" + model.Id + ",Name" + model.Name, "成功", "修改", "Spl_ProductCategory");
             return(Json(JsonHandler.CreateMessage(1, Resource.EditSucceed)));
         }
         else
         {
             string ErrorCol = errors.Error;
             LogHandler.WriteServiceLog(GetUserId(), "Id" + model.Id + ",Name" + model.Name + "," + ErrorCol, "失败", "修改", "Spl_ProductCategory");
             return(Json(JsonHandler.CreateMessage(0, Resource.EditFail + ErrorCol)));
         }
     }
     else
     {
         return(Json(JsonHandler.CreateMessage(0, Resource.EditFail)));
     }
 }
 public JsonResult Create(Spl_ProductCategoryModel model)
 {
     model.Id         = ResultHelper.NewId;
     model.CreateTime = ResultHelper.NowTime;
     if (model != null && ModelState.IsValid)
     {
         if (m_BLL.Create(ref errors, model))
         {
             LogHandler.WriteServiceLog(GetUserId(), "Id" + model.Id + ",Name" + model.Name, "成功", "创建", "Spl_ProductCategory");
             return(Json(JsonHandler.CreateMessage(1, Resource.InsertSucceed)));
         }
         else
         {
             string ErrorCol = errors.Error;
             LogHandler.WriteServiceLog(GetUserId(), "Id" + model.Id + ",Name" + model.Name + "," + ErrorCol, "失败", "创建", "Spl_ProductCategory");
             return(Json(JsonHandler.CreateMessage(0, Resource.InsertFail + ErrorCol)));
         }
     }
     else
     {
         return(Json(JsonHandler.CreateMessage(0, Resource.InsertFail)));
     }
 }
示例#9
0
        public virtual async Task <Tuple <ValidationErrors, bool> > CreateAsync(Spl_ProductCategoryModel model)
        {
            ValidationErrors errors = new ValidationErrors();

            try
            {
                Spl_ProductCategory entity = await m_Rep.GetByIdAsync(model.Id);

                if (entity != null)
                {
                    errors.Add(Resource.PrimaryRepeat);
                    return(new Tuple <ValidationErrors, bool>(errors, false));
                }
                entity            = new Spl_ProductCategory();
                entity.Id         = model.Id;
                entity.Name       = model.Name;
                entity.CreateTime = model.CreateTime;
                entity.CreateBy   = model.CreateBy;


                if (await m_Rep.CreateAsync(entity))
                {
                    return(new Tuple <ValidationErrors, bool>(errors, true));
                }
                else
                {
                    errors.Add(Resource.InsertFail);
                    return(new Tuple <ValidationErrors, bool>(errors, false));
                }
            }
            catch (Exception ex)
            {
                errors.Add(ex.Message);
                ExceptionHander.WriteException(ex);
                return(new Tuple <ValidationErrors, bool>(errors, false));
            }
        }
        public ActionResult Edit(string id)
        {
            Spl_ProductCategoryModel entity = m_BLL.GetById(id);

            return(View(entity));
        }