Пример #1
0
 public void Create(ThemeVM model)
 {
     _unitOfWork.Themes.Create(new Theme {
         Name = model.Name, Description = model.Description
     });
     _unitOfWork.Save();
 }
Пример #2
0
        public void Update(ThemeVM model)
        {
            _unitOfWork.Themes.Update(new Theme {
                ThemeId = model.ThemeId, Name = model.Name, Description = model.Description
            });

            _unitOfWork.Save();
        }
        public IActionResult Get(int id)
        {
            ThemeVM theme = _themeService.GetAll().FirstOrDefault(x => x.ThemeId == id);

            if (theme == null)
            {
                return(NotFound());
            }

            return(new ObjectResult(theme));
        }
        public IActionResult Delete(int id)
        {
            ThemeVM theme = _themeService.GetById(id);

            if (theme == null)
            {
                return(NotFound());
            }

            _themeService.Delete(theme.ThemeId);

            return(Ok(theme));
        }
        public IActionResult Put([FromBody] ThemeVM model)
        {
            ThemeVM theme = _themeService.GetAll().Where(x => x.Name == model.Name && x.Description == model.Description).FirstOrDefault();

            if (theme != null)
            {
                ModelState.AddModelError(string.Empty, "Data not change");

                return(BadRequest(ModelState));
            }

            _themeService.Update(model);

            return(Ok(model));
        }
        public IActionResult Post([FromBody] ThemeVM model)
        {
            ThemeVM theme = _themeService.GetAll().Where(x => x.Name == model.Name).FirstOrDefault();

            if (theme != null)
            {
                ModelState.AddModelError(string.Empty, "Theme is already exists");

                return(BadRequest(ModelState));
            }

            _themeService.Create(model);

            return(Ok(model));
        }
Пример #7
0
 public void Test2()
 {
     var     controller = new ApiThemeController(_themeService);
     ThemeVM theme      = _themeService.GetAll().FirstOrDefault(x => x.ThemeId == 1);
 }
        public IActionResult Details(int id)
        {
            ThemeVM theme = _themeService.GetById(id);

            return(View(theme));
        }