Ejemplo n.º 1
0
        /// <summary>
        /// 保存数据
        /// </summary>
        public virtual void SaveImportData(IEnumerable <Spl_WarehouseModel> list)
        {
            try
            {
                using (DBContainer db = new DBContainer())
                {
                    foreach (var model in list)
                    {
                        Spl_Warehouse entity = new Spl_Warehouse();
                        entity.Id                  = ResultHelper.NewId;
                        entity.Name                = model.Name;
                        entity.Code                = model.Code;
                        entity.IsDefault           = model.IsDefault;
                        entity.ContactPerson       = model.ContactPerson;
                        entity.ContactPhone        = model.ContactPhone;
                        entity.Address             = model.Address;
                        entity.Remark              = model.Remark;
                        entity.Enable              = model.Enable;
                        entity.CreateTime          = ResultHelper.NowTime;
                        entity.WarehouseCategoryId = model.WarehouseCategoryId;

                        db.Spl_Warehouse.Add(entity);
                    }
                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Ejemplo n.º 2
0
        public virtual async Task <Spl_WarehouseModel> GetByIdAsync(object id)
        {
            if (IsExists(id))
            {
                Spl_Warehouse entity = await m_Rep.GetByIdAsync(id);

                Spl_WarehouseModel model = new Spl_WarehouseModel();
                model.Id                  = entity.Id;
                model.Name                = entity.Name;
                model.Code                = entity.Code;
                model.IsDefault           = entity.IsDefault;
                model.ContactPerson       = entity.ContactPerson;
                model.ContactPhone        = entity.ContactPhone;
                model.Address             = entity.Address;
                model.Remark              = entity.Remark;
                model.Enable              = entity.Enable;
                model.CreateTime          = entity.CreateTime;
                model.WarehouseCategoryId = entity.WarehouseCategoryId;

                return(model);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 3
0
        public virtual async Task <Tuple <ValidationErrors, bool> > CreateAsync(Spl_WarehouseModel model)
        {
            ValidationErrors errors = new ValidationErrors();

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

                if (entity != null)
                {
                    errors.Add(Resource.PrimaryRepeat);
                    return(new Tuple <ValidationErrors, bool>(errors, false));
                }
                entity                     = new Spl_Warehouse();
                entity.Id                  = model.Id;
                entity.Name                = model.Name;
                entity.Code                = model.Code;
                entity.IsDefault           = model.IsDefault;
                entity.ContactPerson       = model.ContactPerson;
                entity.ContactPhone        = model.ContactPhone;
                entity.Address             = model.Address;
                entity.Remark              = model.Remark;
                entity.Enable              = model.Enable;
                entity.CreateTime          = model.CreateTime;
                entity.WarehouseCategoryId = model.WarehouseCategoryId;


                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));
            }
        }
Ejemplo n.º 4
0
        public virtual bool Edit(ref ValidationErrors errors, Spl_WarehouseModel model)
        {
            try
            {
                Spl_Warehouse entity = m_Rep.GetById(model.Id);
                if (entity == null)
                {
                    errors.Add(Resource.Disable);
                    return(false);
                }
                entity.Id                  = model.Id;
                entity.Name                = model.Name;
                entity.Code                = model.Code;
                entity.IsDefault           = model.IsDefault;
                entity.ContactPerson       = model.ContactPerson;
                entity.ContactPhone        = model.ContactPhone;
                entity.Address             = model.Address;
                entity.Remark              = model.Remark;
                entity.Enable              = model.Enable;
                entity.CreateTime          = model.CreateTime;
                entity.WarehouseCategoryId = model.WarehouseCategoryId;



                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);
            }
        }