private SettingTypeDTO ToDTO(SettingTypeEntity entity) { SettingTypeDTO dto = new SettingTypeDTO(); dto.CreateTime = entity.CreateTime; dto.Id = entity.Id; dto.Name = entity.Name; dto.Description = entity.Description; dto.Sort = entity.Sort; dto.IsEnabled = entity.IsEnabled; return(dto); }
public async Task <SettingTypeDTO> GetModelAsync(long id) { using (MyDbContext dbc = new MyDbContext()) { SettingTypeEntity entity = await dbc.GetAll <SettingTypeEntity>().SingleOrDefaultAsync(p => p.Id == id); if (entity == null) { return(null); } return(ToDTO(entity)); } }
public async Task <long> AddAsync(string name, string description, int sort) { using (MyDbContext dbc = new MyDbContext()) { SettingTypeEntity entity = new SettingTypeEntity(); entity.Name = name; entity.Description = description; entity.Sort = sort; dbc.SettingTypes.Add(entity); await dbc.SaveChangesAsync(); return(entity.Id); } }
public async Task <bool> DelAsync(long id) { using (MyDbContext dbc = new MyDbContext()) { SettingTypeEntity entity = await dbc.GetAll <SettingTypeEntity>().SingleOrDefaultAsync(p => p.Id == id); if (entity == null) { return(false); } entity.IsDeleted = true; await dbc.SaveChangesAsync(); return(true); } }
public async Task <long> EditAsync(long id, string name, string description, int sort) { using (MyDbContext dbc = new MyDbContext()) { SettingTypeEntity entity = await dbc.GetAll <SettingTypeEntity>().SingleOrDefaultAsync(p => p.Id == id); if (entity == null) { return(-1); } entity.Name = name; entity.Description = description; entity.Sort = sort; await dbc.SaveChangesAsync(); return(entity.Id); } }