Example #1
0
        public IHttpActionResult Get(int id)
        {
            Theme    entity = this.themes.Get(id);
            ThemeDto dto    = ModelMapper.Map <ThemeDto>(entity);

            return(Ok(dto));
        }
Example #2
0
        public async Task <IActionResult> PutTheme(int id, ThemeDto theme)
        {
            CommonResponse <ThemeDto> response = new CommonResponse <ThemeDto>();

            if (id != theme.Id)
            {
                response.Error = new Error {
                    Status = 400, Message = "There was a mismatch with the provided id and the object."
                };
                return(BadRequest(response));
            }
            // Map to model
            Theme themeModel = _mapper.Map <Theme>(theme);

            _context.Entry(themeModel).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ThemeExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #3
0
        public IHttpActionResult Put([FromBody] ThemeDto dto)
        {
            Theme entity = ModelMapper.Map <Theme>(dto);

            this.themes.Change(entity);
            return(Ok());
        }
        public string AddTheme([FromBody] ThemeDto themeDto)
        {
            var theme = mapper.Map <Theme>(themeDto);

            themeRepository.Insert(theme);
            return(theme.Id.ToString());
        }
Example #5
0
 public static Theme ToModel(this ThemeDto themeDto)
 {
     return(new Theme()
     {
         Id = themeDto.Id,
         Name = themeDto.Name
     });
 }
Example #6
0
        public IHttpActionResult Post([FromBody] ThemeDto dto)
        {
            Theme entity = ModelMapper.Map <Theme>(dto);

            this.themes.Add(entity);
            dto = ModelMapper.Map <ThemeDto>(entity);
            return(Ok(dto));
        }
Example #7
0
        /// <summary>
        /// 设置UI主题
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task SettingTheme(ThemeDto input)
        {
            await SettingManager.ChangeSettingForApplicationAsync(AppSettingNames.Theme.ShowPageTab, input.ShowPageTab.ToString());

            await SettingManager.ChangeSettingForApplicationAsync(AppSettingNames.Theme.ShowHeaderMenus, input.ShowHeaderMenus.ToString());

            await SettingManager.ChangeSettingForApplicationAsync(AppSettingNames.Theme.MaxTabCount, input.MaxTabCount.ToString());
        }
Example #8
0
 public static Theme MapToEntity(this ThemeDto dto)
 {
     return(new Theme()
     {
         Id = dto.Id,
         Title = dto.Title,
     });
 }
Example #9
0
        public async Task <IActionResult> Edit(ThemeDto themeDto)
        {
            if (ModelState.IsValid)
            {
                await _themeService.UpdateAsync(themeDto);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(themeDto));
        }
Example #10
0
 /// <summary>
 ///    From Theme dto To Theme pivot.
 /// </summary>
 /// <param name="themeDto">theme dto to assemble.</param>
 /// <returns>Themepivot result.</returns>
 public static ThemePivot ToPivot(this ThemeDto themeDto)
 {
     if (themeDto == null)
     {
         return(null);
     }
     return(new ThemePivot
     {
         ThemeId = themeDto.ThemeId
     });
 }
        public async Task CreateAsync(ThemeDto themeDto)
        {
            var theme = new Theme
            {
                Id     = themeDto.Id,
                UserId = themeDto.UserId,
                Name   = themeDto.Name
            };

            await _repositoryTheme.CreateAsync(theme);

            await _repositoryTheme.SaveChangesAsync();
        }
Example #12
0
 public async Task <ActionResponse <ThemeDto> > Update(ThemeDto entityDto)
 {
     try
     {
         var entityToUpdate = mapper.Map <ThemeDto, Theme>(entityDto);
         unitOfWork.GetGenericRepository <Theme>().Update(entityToUpdate);
         unitOfWork.Save();
         return(await ActionResponse <ThemeDto>
                .ReturnSuccess(mapper.Map <Theme, ThemeDto>(entityToUpdate)));
     }
     catch (Exception)
     {
         return(await ActionResponse <ThemeDto> .ReturnError($"Greška prilikom ažuriranja teme: {entityDto.Name}."));
     }
 }
Example #13
0
 public async Task <ActionResponse <ThemeDto> > Insert(ThemeDto entityDto)
 {
     try
     {
         var entityToAdd = mapper.Map <ThemeDto, Theme>(entityDto);
         unitOfWork.GetGenericRepository <Theme>().Add(entityToAdd);
         unitOfWork.Save();
         mapper.Map(entityToAdd, entityDto);
         return(await ActionResponse <ThemeDto> .ReturnSuccess(entityDto, "Tema uspješno upisana."));
     }
     catch (Exception)
     {
         return(await ActionResponse <ThemeDto> .ReturnError("Greška prilikom upisivanja teme."));
     }
 }
Example #14
0
        public async Task <ActionResult <ThemeDto> > CreateTheme([FromBody] ThemeDto themeDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var dto = await _themeService.CreateEntityAsync(themeDto);

            if (dto == null)
            {
                return(StatusCode(500));
            }

            return(Ok(dto));
        }
        public static ThemeDto ToThemeDto(this Theme theme)
        {
            if (theme == null)
            {
                return(null);
            }

            var themeDto = new ThemeDto
            {
                Id           = theme.Id,
                Name         = theme.Name,
                QuestionList = theme.Questions.Select(x => x.ToQuestionDto()).ToList()
            };

            return(themeDto);
        }
Example #16
0
        public async Task <ThemeDto> CreateEntityAsync(ThemeDto themeDto)
        {
            var entity = _mapper.Map <ThemeDto, Theme>(themeDto);

            entity = await _uow.ThemeRepository.CreateAsync(entity);

            var result = await _uow.SaveAsync();

            if (!result || entity == null)
            {
                return(null);
            }

            var dto = _mapper.Map <Theme, ThemeDto>(entity);

            return(dto);
        }
        public async Task <IActionResult> CreateFromGame(ThemeActionsViewModel model)
        {
            if (ModelState.IsValid)
            {
                var userId = await _accountManager.GetUserIdByNameAsync(User.Identity.Name);

                var themeDto = new ThemeDto
                {
                    UserId = userId,
                    Name   = model.Name
                };

                await _themeManager.CreateAsync(themeDto);

                return(RedirectToAction("Create", "Game"));
            }

            return(View(model));
        }
 public bool AddTheme([FromBody] ThemeDto theme)
 {
     try
     {
         using (var context = new ServiceContext())
         {
             var themeEntity = new Theme();
             themeEntity.UserID     = theme.UserID;
             themeEntity.ThemeName  = theme.ThemeName;
             themeEntity.Updatetime = DateTime.Now;
             context.Theme.Add(themeEntity);
             context.SaveChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
Example #19
0
        public ThemeDto AddTheme(ThemeDto themeDto)
        {
            _logger.Information("AddTheme");

            try
            {
                var theme = _mapper.Map <ThemesDb>(themeDto);
                _context.Themes.Add(theme);
                _context.Users.Include(x => x.Claims);
                _context.Users.Include(x => x.Logins);
                _context.Users.Include(x => x.Roles);
                _context.SaveChanges();
            }
            catch (UpdateException ex)
            {
                _logger.Error("Connection to db is failed", ex);
            }

            return(themeDto);
        }
        private void AuthorizePut(HttpActionContext actionContext)
        {
            int organiserId;

            string controller = actionContext.ControllerContext.ControllerDescriptor.ControllerName;

            switch (controller)
            {
            case "Organisation":
                OrganisationDto organisationDto = (OrganisationDto)actionContext.ActionArguments["dto"];
                Organisation    organisation    = this.Organisations.Get(organisationDto.Id);
                organiserId = organisation.OrganiserId;
                break;

            case "Subtheme":
                SubthemeDto subthemeDto = (SubthemeDto)actionContext.ActionArguments["dto"];
                Subtheme    subtheme    = this.Subthemes.Get(subthemeDto.Id);
                organiserId = subtheme.OrganiserId;
                break;

            case "Theme":
                ThemeDto themeDto = (ThemeDto)actionContext.ActionArguments["dto"];
                Theme    theme    = this.Themes.Get(themeDto.Id);
                organiserId = themeDto.OrganiserId;
                break;

            case "Session":
                SessionDto sessionDto = (SessionDto)actionContext.ActionArguments["dto"];
                Session    session    = this.Sessions.Get(sessionDto.Id, collections: true);

                this.AuthorizeOrganiser(session.Organisers);

                return;

            default:        // will be unauthorized
                organiserId = -1;
                break;
            }

            this.AuthorizeOrganiser(organiserId);
        }
        private void AuthorizePost(HttpActionContext actionContext)
        {
            int organiserId;

            string controller = actionContext.ControllerContext.ControllerDescriptor.ControllerName;

            switch (controller)
            {
            case "Session":
            {
                SessionDto sessionDto = (SessionDto)actionContext.ActionArguments["dto"];
                Subtheme   subtheme   = this.Subthemes.Get(sessionDto.SubthemeId);
                organiserId = subtheme.OrganiserId;
            }
            break;

            case "Subtheme":
            {
                SubthemeDto subthemeDto = (SubthemeDto)actionContext.ActionArguments["dto"];
                Theme       theme       = this.Themes.Get(subthemeDto.ThemeId);
                organiserId = theme.OrganiserId;
            }
            break;

            case "Theme":
            {
                ThemeDto     themeDto     = (ThemeDto)actionContext.ActionArguments["dto"];
                Organisation organisation = this.Organisations.Get(themeDto.OrganisationId);
                organiserId = organisation.OrganiserId;
            }
            break;

            default:        // to prevent the dto from being null
                organiserId = -1;
                break;
            }

            this.AuthorizeOrganiser(organiserId);
        }
Example #22
0
        public List<ThemeDto> GetThemes([FromUri] int userID)
        {
            try
            {
                using (var context = new ServiceContext())
                {
                    var themeListEntity = context.Theme.Where(t => t.UserID == userID)
                                                 .Include(t => t.Images);

                    var themeLsitDto = new List<ThemeDto>();
                    foreach (var theme in themeListEntity)
                    {
                        themeLsitDto.Add(ThemeDto.Map(theme));
                    }
                    return themeLsitDto;
                }
            }
            catch (Exception)
            {

                throw;
            }
        }
Example #23
0
        public async Task <ThemeDto> GetByIdAsync(int id)
        {
            Theme themeEntity = await _unitOfWork.ThemeRepository.ReadAsync(id);

            if (themeEntity == null)
            {
                throw new Exception("Nothing was found by this Id");
            }

            ThemeDto theme = themeEntity.MapToDto();

            List <TestDto>     tests        = new();
            IEnumerable <Test> testEntities = await _unitOfWork.TestRepository
                                              .GetByConditionAsync(test => test.ThemeId == themeEntity.Id);

            foreach (var entity in testEntities)
            {
                tests.Add(entity.MapToDto());
            }

            theme.Tests = tests;
            return(theme);
        }
Example #24
0
 public async Task <ActionResponse <ThemeDto> > Update([FromBody] ThemeDto request)
 {
     return(await themeService.Update(request));
 }
Example #25
0
 public async Task UpdateAsync(ThemeDto dto)
 {
     _unitOfWork.ThemeRepository.Update(dto.MapToEntity());
     await _unitOfWork.SaveAsync();
 }