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