private GoodsAreaDTO ToDTO(GoodsAreaEntity entity) { GoodsAreaDTO dto = new GoodsAreaDTO(); dto.CreateTime = entity.CreateTime; dto.Description = entity.Description; dto.Id = entity.Id; dto.Note = entity.Note; dto.Title = entity.Title; return(dto); }
public async Task <GoodsAreaDTO> GetModelAsync(long id) { using (MyDbContext dbc = new MyDbContext()) { GoodsAreaEntity entity = await dbc.GetAll <GoodsAreaEntity>().SingleOrDefaultAsync(g => g.Id == id); if (entity == null) { return(null); } return(ToDTO(entity)); } }
public async Task <long> GetIdByTitleAsync(string title) { using (MyDbContext dbc = new MyDbContext()) { GoodsAreaEntity entity = await dbc.GetAll <GoodsAreaEntity>().SingleOrDefaultAsync(g => g.Title == title); if (entity == null) { return(0); } return(entity.Id); } }
public async Task <long> AddAsync(string title, string description, string note) { using (MyDbContext dbc = new MyDbContext()) { GoodsAreaEntity entity = new GoodsAreaEntity(); entity.Title = title; entity.Description = description; entity.Note = note; dbc.GoodsAreas.Add(entity); await dbc.SaveChangesAsync(); return(entity.Id); } }
public async Task <bool> DeleteAsync(long id) { using (MyDbContext dbc = new MyDbContext()) { GoodsAreaEntity entity = await dbc.GetAll <GoodsAreaEntity>().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 title, string description, string note) { using (MyDbContext dbc = new MyDbContext()) { GoodsAreaEntity entity = await dbc.GetAll <GoodsAreaEntity>().SingleOrDefaultAsync(g => g.Id == id); if (entity == null) { return(false); } entity.Title = title; entity.Description = description; entity.Note = note; await dbc.SaveChangesAsync(); return(true); } }