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