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


                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_InOutCategoryModel model)
        {
            try
            {
                Spl_InOutCategory 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.Category   = model.Category;



                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);
            }
        }
        public virtual Spl_InOutCategoryModel GetById(object id)
        {
            if (IsExists(id))
            {
                Spl_InOutCategory      entity = m_Rep.GetById(id);
                Spl_InOutCategoryModel model  = new Spl_InOutCategoryModel();
                model.Id         = entity.Id;
                model.Name       = entity.Name;
                model.CreateTime = entity.CreateTime;
                model.Category   = entity.Category;

                return(model);
            }
            else
            {
                return(null);
            }
        }
示例#4
0
        public virtual async Task <Tuple <ValidationErrors, bool> > CreateAsync(Spl_InOutCategoryModel model)
        {
            ValidationErrors errors = new ValidationErrors();

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

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


                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));
            }
        }
        /// <summary>
        /// 保存数据
        /// </summary>
        public virtual void SaveImportData(IEnumerable <Spl_InOutCategoryModel> list)
        {
            try
            {
                using (DBContainer db = new DBContainer())
                {
                    foreach (var model in list)
                    {
                        Spl_InOutCategory entity = new Spl_InOutCategory();
                        entity.Id         = ResultHelper.NewId;
                        entity.Name       = model.Name;
                        entity.CreateTime = ResultHelper.NowTime;
                        entity.Category   = model.Category;

                        db.Spl_InOutCategory.Add(entity);
                    }
                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }