private MainGoodsTypeDTO ToDTO(MainGoodsTypeEntity entity) { MainGoodsTypeDTO dto = new MainGoodsTypeDTO(); dto.CreateTime = entity.CreateTime; dto.Id = entity.Id; dto.Description = entity.Description; dto.Name = entity.Name; dto.ImgUrl = entity.ImgUrl; return(dto); }
public async Task <long> AddAsync(string name, string imgUrl, string description) { using (MyDbContext dbc = new MyDbContext()) { MainGoodsTypeEntity entity = new MainGoodsTypeEntity(); entity.Name = name; entity.ImgUrl = imgUrl; entity.Description = description; dbc.MainGoodsTypes.Add(entity); await dbc.SaveChangesAsync(); return(entity.Id); } }
public async Task <bool> DeleteAsync(long id) { using (MyDbContext dbc = new MyDbContext()) { MainGoodsTypeEntity entity = await dbc.GetAll <MainGoodsTypeEntity>().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()) { MainGoodsTypeEntity entity = await dbc.GetAll <MainGoodsTypeEntity>().SingleOrDefaultAsync(g => g.Id == id); if (entity == null) { return(false); } entity.Name = name; entity.ImgUrl = imgUrl; entity.Description = description; await dbc.SaveChangesAsync(); return(true); } }