Ejemplo n.º 1
0
        public ActionResult Add([ModelBinder(typeof(JsonBinder <LocationEntity>))] LocationEntity entity)
        {
            LocationProvider provider = new LocationProvider();

            if (entity.LocalNum.IsEmpty())
            {
                entity.LocalNum     = SequenceProvider.GetSequence(typeof(LocationEntity));
                entity.LocalBarCode = entity.LocalBarCode.IsEmpty() ? entity.LocalNum : entity.LocalBarCode;
                entity.IsForbid     = (int)EBool.No;
                entity.IsDelete     = (int)EIsDelete.NotDelete;
                entity.UnitNum      = "";
                entity.UnitName     = "";
                entity.CreateTime   = DateTime.Now;
                int line = provider.Add(entity);
                if (line > 0)
                {
                    this.ReturnJson.AddProperty("d", "success");
                }
            }
            else
            {
                entity.LocalBarCode = entity.LocalBarCode.IsEmpty() ? entity.LocalNum : entity.LocalBarCode;
                entity.Include(a => new { a.LocalName, a.LocalBarCode, a.StorageNum, a.LocalType, a.IsDefault });
                entity.Where(a => a.LocalNum == entity.LocalNum);
                int line = provider.Update(entity);
                if (line > 0)
                {
                    this.ReturnJson.AddProperty("d", "success");
                }
            }
            return(Content(this.ReturnJson.ToString()));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public int Update(LocationEntity entity)
        {
            using (TransactionScope ts = new TransactionScope())
            {
                string Key = string.Format(CacheKey.JOOSHOW_LOCATION_CACHE, this.CompanyID);

                if (entity.IsDefault == (int)EBool.Yes)
                {
                    LocationEntity location = new LocationEntity();
                    location.IsDefault = (int)EBool.No;
                    location.IncludeIsDefault(true);
                    location.Where(a => a.LocalType == entity.LocalType)
                    .And(a => a.CompanyID == this.CompanyID)
                    ;
                    this.Location.Update(location);

                    LocationEntity temp = new LocationEntity();
                    temp.IsDefault = (int)EBool.No;
                    temp.IncludeIsDefault(true);
                    temp.Where(a => a.CompanyID == this.CompanyID);
                    this.Location.Update(temp);
                }

                //绑定仓库信息
                StorageProvider      storageProvider = new StorageProvider(this.CompanyID);
                List <StorageEntity> listStorage     = storageProvider.GetList();
                listStorage = listStorage.IsNull() ? new List <StorageEntity>() : listStorage;
                if (entity.StorageNum.IsEmpty())
                {
                    StorageEntity storage = listStorage.FirstOrDefault(a => a.IsDefault == (int)EBool.Yes);
                    if (storage != null)
                    {
                        entity.StorageNum  = storage.StorageNum;
                        entity.StorageType = storage.StorageType;
                    }
                }
                else
                {
                    StorageEntity storage = listStorage.FirstOrDefault(a => a.StorageNum == entity.StorageNum);
                    if (storage != null)
                    {
                        entity.StorageType = storage.StorageType;
                    }
                }
                if (entity.UnitName.IsEmpty() && !entity.UnitNum.IsEmpty())
                {
                    MeasureProvider      provider    = new MeasureProvider(this.CompanyID);
                    List <MeasureEntity> listMeasure = provider.GetList();
                    listMeasure = listMeasure.IsNull() ? new List <MeasureEntity>() : listMeasure;
                    MeasureEntity measureEntity = listMeasure.FirstOrDefault(a => a.SN == entity.UnitNum);
                    entity.UnitName = measureEntity != null ? measureEntity.MeasureName : entity.UnitName;
                }
                entity.UnitNum  = entity.UnitNum.IsEmpty() ? "" : entity.UnitNum;
                entity.UnitName = entity.UnitName.IsEmpty() ? "" : entity.UnitName;

                entity.Include(a => new { a.LocalBarCode, a.LocalName, a.StorageNum, a.StorageType, a.LocalType, a.Rack, a.Length, a.Width, a.Height, a.X, a.Y, a.Z, a.UnitNum, a.UnitName, a.Remark, a.IsForbid, a.IsDefault });
                entity.Where(a => a.LocalNum == entity.LocalNum)
                .And(a => a.CompanyID == this.CompanyID)
                ;
                int line = this.Location.Update(entity);
                if (line > 0)
                {
                    CacheHelper.Remove(Key);
                }
                ts.Complete();
                return(line);
            }
        }