Beispiel #1
0
        public override void CreateOne()
        {
            MockGenreRepository.Setup(r => r.Create(It.IsAny <Genre>())).Returns(MockGenre);

            var entity = _service.Create(MockGenreBO);

            Assert.NotNull(entity);
        }
Beispiel #2
0
        public void createTest()
        {
            var id = genreService.Create(testName);

            var dbEntity = cdDb.Genres.SingleOrDefault(x => x.Id == id);

            Assert.IsNotNull(dbEntity);

            cdDb.Genres.Remove(dbEntity);
            cdDb.SaveChanges();
        }
        public ActionResult Create(GenreEditorModel genreEditorModel, string[] parentGenre)
        {
            if (_genreService.Get(genreEditorModel.Genre.Name) != null)
            {
                ModelState.AddModelError("Name", Resources.Genre.GenreResource.NameExistsError);
            }

            if (ModelState.IsValid)
            {
                var genre = Mapper.Map <GenreViewModel, Genre>(genreEditorModel.Genre);

                var parent = _genreService.Get(parentGenre[0]);

                if (parent != null)
                {
                    genre.ParentId = parent.Id;
                }

                SetTranslate(genre.GenreTranslates, genreEditorModel.Genre);

                _genreService.Create(genre);

                return(RedirectToAction("Index"));
            }

            var genreModel = new GenreEditorModel
            {
                ParentGenres = CreateSelectList(),
                Genre        = genreEditorModel.Genre,
            };

            return(View(genreModel));
        }
        public IActionResult PostGenre([FromBody] GenreModel genreModel)
        {
            _logger.LogInformation($"{nameof(GenreController)} : {nameof(PostGenre)} was called.");
            try
            {
                if (genreModel == null)
                {
                    return(BadRequest("Genre is required"));
                }

                if (_genreService.FindById(genreModel.Id) != null)
                {
                    return(Conflict("Genre already exists"));
                }

                _genreService.Create(genreModel);
                _genreService.Save();
                return(Ok("Genre Created"));
            }
            catch (DbException exception)
            {
                _logger.LogError(exception.Message);
                return(BadRequest(exception.Message));
            }
            catch (Exception exception)
            {
                _logger.LogError(exception.Message);
                throw;
            }
        }
        public async Task<IActionResult> CreateGenre(GenreViewModel model)
        {
            var genre = await _genreService.Create(model.ToDTO());

            var genreViewModel = genre.ToViewModel();

            return Created("post", genreViewModel);
        }
Beispiel #6
0
        public IHttpActionResult CreateGenre(GenreModel model)
        {
            var genre = Mapper.Map <GenreModel, GenreDTO>(model);

            _genreService.Create(genre);

            return(Ok("Genre created"));
        }
Beispiel #7
0
        public ActionResult Create(GenrePostModel model)
        {
            var genre = _mapper.Map <GenreModel>(model);

            _genreService.Create(genre);

            return(RedirectToAction("Index"));
        }
Beispiel #8
0
        public int Create(CreateGenreViewModel createGenreViewModel)
        {
            Validate(createGenreViewModel);

            return(genreService.Create(new CreateGenreRequest()
            {
                Description = createGenreViewModel.Description,
            }));
        }
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            await _genreService.Create(GenreCreation);

            return(RedirectToPage("../GenreRazor/Index"));
        }
Beispiel #10
0
        public async Task <ActionResult> Post(GenreDTO dto)
        {
            var result = await _genreService.Create(dto);

            if (result)
            {
                return(Ok());
            }
            return(BadRequest());
        }
Beispiel #11
0
 public ActionResult CreateGenre(GenreDTO model)
 {
     if (ModelState.IsValid)
     {
         genreService.Create(model);
         return(RedirectToAction("AllGenres", "Libraryan"));
     }
     else
     {
         ModelState.AddModelError("", "Заполните все необходимые поля!");
     }
     return(View());
 }
Beispiel #12
0
 public ActionResult Create(string name, int?idParent)
 {
     try
     {
         genreService.Create(name, idParent);
         string Message = "Genre Created";
         InternalNotification.Success(Message);
     }
     catch (Exception ex)
     {
         InternalNotification.Error(ex);
     }
     return(RedirectToAction("index"));
 }
Beispiel #13
0
        public async Task <IActionResult> Create([FromBody] GenreCreateRequest request)
        {
            try
            {
                var genre = await _genreService.Create(request);

                return(CreatedAtAction(nameof(Get), new { id = genre.Id }, genre));
            }
            catch (Exception exception)
            {
                return(BadRequest(new
                {
                    exception.Message
                }));
            }
        }
Beispiel #14
0
        public HttpResponseMessage Put([FromBody] CreateGenreModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }

            if (model.ParentGenreId != null && model.ParentGenreId == default(int))
            {
                model.ParentGenreId = null;
            }

            int genreId = _genreService.Create(model.Name, model.ParentGenreId);

            return(Request.CreateResponse(HttpStatusCode.Created, genreId));
        }
Beispiel #15
0
        public async Task <IActionResult> Post([FromBody] CreateGenreDTO dto)
        {
            var validator = new GenreFluentValidator(_context);
            var errors    = await validator.ValidateAsync(dto);

            if (!errors.IsValid)
            {
                return(UnprocessableEntity(ValidationFormatter.Format(errors)));
            }

            try {
                await _genreService.Create(dto);

                return(StatusCode(201));
            } catch (Exception) {
                return(StatusCode(500, new { ServerErrorResponse.Message }));
            }
        }
        public ActionResult New(CreateGenreViewModel model)
        {
            if (!ModelState.IsValid)
            {
                List <GenreDto> genres = _genreService.GetAllGenres().ToList();
                genres.Insert(0, new GenreDto {
                    Id = 0, Name = Resource.Default
                });
                model.Genres = new SelectList(genres, "Id", "Name", genres.First().Id);

                return(View(model));
            }

            if (model.ParentGenreId != null && model.ParentGenreId == default(int))
            {
                model.ParentGenreId = null;
            }

            _genreService.Create(model.Name, model.ParentGenreId);

            return(RedirectToAction("GetAll"));
        }
Beispiel #17
0
        public IActionResult Create([Bind("Id,Name,Color")] GenreViewModel genre)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var newGenre = _mapper.Map <GenreViewModel, GenreDTO>(genre);
                    _service.Create(newGenre);
                }
                catch (Exception e)
                {
                    return(View("Error", new ErrorViewModel
                    {
                        RequestId = Request.HttpContext.TraceIdentifier,
                        Exception = e
                    }));
                }

                return(RedirectToAction(nameof(Index)));
            }
            return(View(genre));
        }
Beispiel #18
0
 public async Task Create(GenreDto dto)
 {
     var genre = _mapper.Map <Genre>(dto);
     await _genreService.Create(genre);
 }
Beispiel #19
0
 public Task <int> Create(GenreInputDtos inputDto)
 {
     return(genreService.Create(inputDto));
 }
        public async Task <IActionResult> Post([FromBody] NewGenreDto data)
        {
            var result = await _genreService.Create(data);

            return(new JsonResult(result));
        }
Beispiel #21
0
        // POST: api/Genre
        public void Post(GenreViewModel genre)
        {
            var model = Mapper.Map <GenreModel>(genre);

            genreService.Create(model);
        }
Beispiel #22
0
 public void Create_should_throw_ArgumentNullException_when_input_entity_is_null()
 {
     // Act & Assert
     Assert.Throws <ArgumentNullException>(() => _genreService.Create(null));
 }
 public ActionResult Create(GenreViewModel genre)
 {
     genreService.Create(mapper.Map <Genre>(genre));
     return(RedirectToAction("Index"));
 }