/// <summary>
        /// 保存数据
        /// </summary>
        public virtual void SaveImportData(IEnumerable <Spl_WareUnitConvertModel> list)
        {
            try
            {
                using (DBContainer db = new DBContainer())
                {
                    foreach (var model in list)
                    {
                        Spl_WareUnitConvert entity = new Spl_WareUnitConvert();
                        entity.Id          = ResultHelper.NewId;
                        entity.Name        = model.Name;
                        entity.MainUnit    = model.MainUnit;
                        entity.AssistUnit  = model.AssistUnit;
                        entity.ConvertRate = model.ConvertRate;
                        entity.CreateTime  = ResultHelper.NowTime;

                        db.Spl_WareUnitConvert.Add(entity);
                    }
                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        public virtual Spl_WareUnitConvertModel GetById(object id)
        {
            if (IsExists(id))
            {
                Spl_WareUnitConvert      entity = m_Rep.GetById(id);
                Spl_WareUnitConvertModel model  = new Spl_WareUnitConvertModel();
                model.Id          = entity.Id;
                model.Name        = entity.Name;
                model.MainUnit    = entity.MainUnit;
                model.AssistUnit  = entity.AssistUnit;
                model.ConvertRate = entity.ConvertRate;
                model.CreateTime  = entity.CreateTime;

                return(model);
            }
            else
            {
                return(null);
            }
        }
Пример #3
0
        public virtual async Task <Tuple <ValidationErrors, bool> > CreateAsync(Spl_WareUnitConvertModel model)
        {
            ValidationErrors errors = new ValidationErrors();

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

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


                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 virtual bool Create(ref ValidationErrors errors, Spl_WareUnitConvertModel model)
        {
            try
            {
                Spl_WareUnitConvert entity = m_Rep.GetById(model.Id);
                if (entity != null)
                {
                    errors.Add(Resource.PrimaryRepeat);
                    return(false);
                }
                entity             = new Spl_WareUnitConvert();
                entity.Id          = model.Id;
                entity.Name        = model.Name;
                entity.MainUnit    = model.MainUnit;
                entity.AssistUnit  = model.AssistUnit;
                entity.ConvertRate = model.ConvertRate;
                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);
            }
        }
        public virtual bool Edit(ref ValidationErrors errors, Spl_WareUnitConvertModel model)
        {
            try
            {
                Spl_WareUnitConvert entity = m_Rep.GetById(model.Id);
                if (entity == null)
                {
                    errors.Add(Resource.Disable);
                    return(false);
                }
                entity.Id          = model.Id;
                entity.Name        = model.Name;
                entity.MainUnit    = model.MainUnit;
                entity.AssistUnit  = model.AssistUnit;
                entity.ConvertRate = model.ConvertRate;
                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);
            }
        }