Exemple #1
0
        public virtual bool Create(ref ValidationErrors errors, Spl_TestClassModel model)
        {
            try
            {
                Spl_TestClass entity = m_Rep.GetById(model.Id);
                if (entity != null)
                {
                    errors.Add(Resource.PrimaryRepeat);
                    return(false);
                }
                entity            = new Spl_TestClass();
                entity.Id         = model.Id;
                entity.Name       = model.Name;
                entity.Sort       = model.Sort;
                entity.CreateTime = model.CreateTime;


                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);
            }
        }
Exemple #2
0
        public virtual bool Edit(ref ValidationErrors errors, Spl_TestClassModel model)
        {
            try
            {
                Spl_TestClass entity = m_Rep.GetById(model.Id);
                if (entity == null)
                {
                    errors.Add(Resource.Disable);
                    return(false);
                }
                entity.Id         = model.Id;
                entity.Name       = model.Name;
                entity.Sort       = model.Sort;
                entity.CreateTime = model.CreateTime;



                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);
            }
        }
Exemple #3
0
        public virtual Spl_TestClassModel GetById(object id)
        {
            if (IsExists(id))
            {
                Spl_TestClass      entity = m_Rep.GetById(id);
                Spl_TestClassModel model  = new Spl_TestClassModel();
                model.Id         = entity.Id;
                model.Name       = entity.Name;
                model.Sort       = entity.Sort;
                model.CreateTime = entity.CreateTime;

                return(model);
            }
            else
            {
                return(null);
            }
        }
Exemple #4
0
        /// <summary>
        /// 保存数据
        /// </summary>
        public virtual void SaveImportData(IEnumerable <Spl_TestClassModel> list)
        {
            try
            {
                using (DBContainer db = new DBContainer())
                {
                    foreach (var model in list)
                    {
                        Spl_TestClass entity = new Spl_TestClass();
                        entity.Id         = 0;
                        entity.Name       = model.Name;
                        entity.Sort       = model.Sort;
                        entity.CreateTime = ResultHelper.NowTime;

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