Пример #1
0
        public JsonResult Post([FromBody] ThemeViewModel vm)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var newTheme = Mapper.Map <Theme>(vm);

                    _repository.AddTheme(newTheme);

                    if (_repository.SaveAll())
                    {
                        Response.StatusCode = (int)HttpStatusCode.Created;
                        return(Json(Mapper.Map <ThemeViewModel>(newTheme)));
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(Json(new { ex.Message }));
            }
            Response.StatusCode = (int)HttpStatusCode.BadRequest;
            return(Json(new { Message = "Validation Failed.", ModelState }));
        }
Пример #2
0
        /// <summary>
        ///     Method adds provided themes
        /// </summary>
        /// <param name="theme">Theme that needed to be added</param>
        /// <returns>Theme that was added</returns>
        public Theme AddTheme(Theme theme)
        {
            var themes = _themeRepository.GetAllThemes();

            if (themes.SingleOrDefault(x => x.Name == theme.Name) != null)
            {
                return(null);
            }
            var result = _themeRepository.AddTheme(theme);

            return(result);
        }
Пример #3
0
 public void AddTheme(Theme theme)
 {
     themeRepository.AddTheme(theme);
 }