示例#1
0
        private GoodsTypeDTO ToDTO(GoodsTypeEntity entity)
        {
            GoodsTypeDTO dto = new GoodsTypeDTO();

            dto.CreateTime  = entity.CreateTime;
            dto.Description = entity.Description;
            dto.Id          = entity.Id;
            dto.Name        = entity.Name;
            dto.ImgUrl      = entity.ImgUrl;
            return(dto);
        }
示例#2
0
        public async Task <GoodsTypeDTO> GetModelAsync(long id)
        {
            using (MyDbContext dbc = new MyDbContext())
            {
                GoodsTypeEntity entity = await dbc.GetAll <GoodsTypeEntity>().AsNoTracking().SingleOrDefaultAsync(g => g.Id == id);

                if (entity == null)
                {
                    return(null);
                }
                return(ToDTO(entity));
            }
        }
示例#3
0
        public int AddType(GoodsTypeEntity goodsType)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into tbtype (type_name)");
            strSql.Append("values");
            strSql.Append("(@TypeName)");
            strSql.Append(";SELECT @@IDENTITY");
            SqlParameter[] paras =
            {
                new SqlParameter("@TypeName", goodsType.TypeName)
            };
            return(Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.connStr, CommandType.Text, strSql.ToString(), paras)));
        }
示例#4
0
        public async Task <long> AddAsync(string name, string imgUrl, string description)
        {
            using (MyDbContext dbc = new MyDbContext())
            {
                GoodsTypeEntity entity = new GoodsTypeEntity();
                entity.Description = description;
                entity.ImgUrl      = imgUrl;
                entity.Name        = name;
                dbc.GoodsTypes.Add(entity);
                await dbc.SaveChangesAsync();

                return(entity.Id);
            }
        }
示例#5
0
        public async Task <bool> DeleteAsync(long id)
        {
            using (MyDbContext dbc = new MyDbContext())
            {
                GoodsTypeEntity entity = await dbc.GetAll <GoodsTypeEntity>().SingleOrDefaultAsync(g => g.Id == id);

                if (entity == null)
                {
                    return(false);
                }
                entity.IsDeleted = true;
                await dbc.SaveChangesAsync();

                return(true);
            }
        }
示例#6
0
        public async Task <bool> UpdateAsync(long id, string name, string imgUrl, string description)
        {
            using (MyDbContext dbc = new MyDbContext())
            {
                GoodsTypeEntity entity = await dbc.GetAll <GoodsTypeEntity>().SingleOrDefaultAsync(g => g.Id == id);

                if (entity == null)
                {
                    return(false);
                }
                entity.Name        = name;
                entity.Description = description;
                entity.ImgUrl      = imgUrl;
                await dbc.SaveChangesAsync();

                return(true);
            }
        }
示例#7
0
        public bool EditType(GoodsTypeEntity goodsType)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update  tbtype set");
            strSql.Append("type_name=@TypeName");
            strSql.Append("where id=@TypeID");
            SqlParameter[] paras =
            {
                new SqlParameter("@TypeName", goodsType.TypeName),
                new SqlParameter("@TypeID",   goodsType.TypeID)
            };
            object obj = SqlHelper.ExecuteNonQuery(SqlHelper.connStr, CommandType.Text, strSql.ToString(), paras);

            if (Convert.ToInt32(obj) > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }