Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
            }
        }
Exemplo n.º 3
0
        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);
            }
        }
Exemplo n.º 4
0
        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);
            }
        }