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

            return(Ok(dto));
        }
Ejemplo n.º 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());
        }
Ejemplo n.º 3
0
        public IHttpActionResult Put([FromBody] ThemeDto dto)
        {
            Theme entity = ModelMapper.Map <Theme>(dto);

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

            themeRepository.Insert(theme);
            return(theme.Id.ToString());
        }
Ejemplo n.º 5
0
 public static Theme ToModel(this ThemeDto themeDto)
 {
     return(new Theme()
     {
         Id = themeDto.Id,
         Name = themeDto.Name
     });
 }
Ejemplo n.º 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));
        }
Ejemplo n.º 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());
        }
Ejemplo n.º 8
0
 public static Theme MapToEntity(this ThemeDto dto)
 {
     return(new Theme()
     {
         Id = dto.Id,
         Title = dto.Title,
     });
 }
Ejemplo n.º 9
0
        public async Task <IActionResult> Edit(ThemeDto themeDto)
        {
            if (ModelState.IsValid)
            {
                await _themeService.UpdateAsync(themeDto);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(themeDto));
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 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}."));
     }
 }
Ejemplo n.º 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."));
     }
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 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;
            }
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 24
0
 public async Task <ActionResponse <ThemeDto> > Update([FromBody] ThemeDto request)
 {
     return(await themeService.Update(request));
 }
Ejemplo n.º 25
0
 public async Task UpdateAsync(ThemeDto dto)
 {
     _unitOfWork.ThemeRepository.Update(dto.MapToEntity());
     await _unitOfWork.SaveAsync();
 }