Exemple #1
0
        public bool CreatePublisher(PublisherCreateDto publisherToCreateDto)
        {
            var publisherToCreate = MapConfig.Mapper.Map <Publisher>(publisherToCreateDto);

            _publisherContext.Add(publisherToCreate);
            return(Save());
        }
Exemple #2
0
 public ActionResult <Publisher> Create(PublisherCreateDto PublisherCreateDto)
 {
     try
     {
         return(service.Create(PublisherCreateDto));
     }
     catch (Exception error)
     {
         return(Conflict(error.Message));
     }
 }
Exemple #3
0
        public Publisher Create(PublisherCreateDto dto)
        {
            dto.Name = FormatString.Trim_MultiSpaces_Title(dto.Name, true);
            var isExist = GetDetail(dto.Name);

            if (isExist != null)
            {
                throw new Exception(dto.Name + " existed");
            }

            var entity = new Publisher
            {
                Name  = dto.Name,
                Image = FormatString.Trim_MultiSpaces_Title(dto.Image, true)
            };

            return(repository.Add(entity));
        }
        public IActionResult CreatePublisher([FromBody] PublisherCreateDto newPublisher)
        {
            if (newPublisher == null)
            {
                return(BadRequest(ModelState));
            }

            if (_unitOfWork.PublisherRepository.PublisherExists(newPublisher.Id))
            {
                ModelState.AddModelError("", "Such publisher Exists!");
                return(StatusCode(404, ModelState));
            }

            if (!_unitOfWork.PublisherRepository.CreatePublisher(newPublisher))
            {
                ModelState.AddModelError("", $"Something went wrong saving the publisher " + $"{newPublisher.PublisherName}");
                return(StatusCode(500, ModelState));
            }

            _unitOfWork.Commit();

            return(CreatedAtRoute("GetPublisherById", new { publisherId = newPublisher.Id }, newPublisher));
        }