private void UpdateSlide(string question, SlideType type, SlideEntity slide)
        {
            if (question != slide.Question)
            {
                slide.Question = question;
            }

            if (type != (SlideType)slide.SlideTypeId)
            {
                slide.SlideTypeId = (short)type;
            }
        }
Exemple #2
0
        private SlideDTO ToDTO(SlideEntity entity)
        {
            SlideDTO dto = new SlideDTO();

            dto.CreateTime = entity.CreateTime;
            dto.Id         = entity.Id;
            dto.Code       = entity.Code;
            dto.ImgUrl     = entity.ImgUrl;
            dto.Name       = entity.Name;
            dto.IsEnabled  = entity.IsEnabled;
            dto.Url        = entity.Url;
            return(dto);
        }
Exemple #3
0
        public async Task <SlideDTO> GetModelAsync(long id)
        {
            using (MyDbContext dbc = new MyDbContext())
            {
                SlideEntity entity = await dbc.GetAll <SlideEntity>().SingleOrDefaultAsync(g => g.Id == id);

                if (entity == null)
                {
                    return(null);
                }
                return(ToDTO(entity));
            }
        }
Exemple #4
0
        public async Task <bool> DeleteAsync(long id)
        {
            using (MyDbContext dbc = new MyDbContext())
            {
                SlideEntity entity = await dbc.GetAll <SlideEntity>().SingleOrDefaultAsync(g => g.Id == id);

                if (entity == null)
                {
                    return(false);
                }
                entity.IsDeleted = true;
                await dbc.SaveChangesAsync();

                return(true);
            }
        }
Exemple #5
0
        public async Task <long> AddAsync(string name, string url, string imgUrl, bool isEnabled)
        {
            using (MyDbContext dbc = new MyDbContext())
            {
                SlideEntity entity = new SlideEntity();
                entity.Code      = DateTime.Now.ToString("yyyyMMddHHmmss");
                entity.Name      = name;
                entity.Url       = url;
                entity.ImgUrl    = imgUrl;
                entity.IsEnabled = isEnabled;
                dbc.Slides.Add(entity);
                await dbc.SaveChangesAsync();

                return(entity.Id);
            }
        }
Exemple #6
0
 public int Save(SlideEntity data)
 {
     try
     {
         return(Connection.Db.Query <int>("spSlideSet",
                                          new
         {
             Id = data.Id,
             Image = data.Image,
             Active = data.Active,
         }, commandType: CommandType.StoredProcedure).SingleOrDefault());
     }
     catch (Exception ex)
     {
         Tools.SaveLog.Save(ex);
         return(-1);
     }
 }
Exemple #7
0
 public List <SlideEntity> Search(SlideEntity data)
 {
     try
     {
         return(Connection.Db.Query <SlideEntity>("spSlideSearch",
                                                  new
         {
             Id = data.Id,
             Image = "%" + data.Image + "%",
             Active = data.Active,
         }, commandType: CommandType.StoredProcedure).ToList());
     }
     catch (Exception ex)
     {
         Tools.SaveLog.Save(ex);
         return(new List <SlideEntity>());
     }
 }
Exemple #8
0
        public async Task <bool> UpdateAsync(long id, string name, string url, string imgUrl, bool isEnabled)
        {
            using (MyDbContext dbc = new MyDbContext())
            {
                SlideEntity entity = await dbc.GetAll <SlideEntity>().SingleOrDefaultAsync(g => g.Id == id);

                if (entity == null)
                {
                    return(false);
                }
                entity.Name      = name;
                entity.Url       = url;
                entity.ImgUrl    = imgUrl;
                entity.IsEnabled = isEnabled;
                await dbc.SaveChangesAsync();

                return(true);
            }
        }
        public Slide CreateSlide(int presentationId)
        {
            using (var context = GetContext())
            {
                if (!context.Presentations.Any(p => p.PresentationId == presentationId))
                {
                    throw new NotFoundException(_presentationDoesNotExist);
                }

                var slide = new SlideEntity
                {
                    PresentationId = presentationId,
                    SlideTypeId    = (short)SlideType.MultipleChoice
                };
                var slideEntity = context.Add(slide).Entity;

                context.SaveChanges();

                return(_mapper.Map <Slide>(slideEntity));
            }
        }