示例#1
0
        public async Task <JsonResult> AddPublisher(Publisher publisher)
        {
            var task    = Task.Run(() => _publisherServices.CreateAsync(publisher));
            var quoteId = await task;

            return(Json(quoteId, JsonRequestBehavior.AllowGet));
        }
示例#2
0
        public void CreateAsync_CallsService_Always()
        {
            var viewModel = GetModifyPublisherViewModel();

            _apiPublisherController.CreateAsync(viewModel);

            A.CallTo(() => _publisherServices.CreateAsync(A <ModifyPublisherDto> ._)).MustHaveHappenedOnceExactly();
        }
示例#3
0
        public async Task <IActionResult> CreateAsync(ModifyPublisherViewModel viewModel)
        {
            viewModel.Id = Guid.NewGuid().ToString();

            var dto = _mapper.Map <ModifyPublisherDto>(viewModel);
            await _publisherServices.CreateAsync(dto);

            _logger.LogDebug($"Create new publisher with name {viewModel.CompanyName}");

            return(CreatedAtAction(nameof(GetByIdAsync), new { id = viewModel.Id }, viewModel));
        }
示例#4
0
        public async Task <ActionResult> Create(CreatePublisherInput input)
        {
            try
            {
                await _publisherService.CreateAsync(input);

                return(Ok());
            }
            catch (Exception ex)
            {
                return(NotFound(ex));
            }
        }
示例#5
0
        public async Task <IActionResult> CreateAsync(ModifyPublisherViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View("Create", viewModel));
            }

            var dto = _mapper.Map <ModifyPublisherDto>(viewModel);
            await _publisherServices.CreateAsync(dto);

            _logger.LogDebug($"Create new publisher with name {viewModel.CompanyName}");

            return(RedirectToAction(nameof(GetAllAsync)));
        }
示例#6
0
        public async Task <HttpResponseMessage> Add([FromBody] PublisherCreateModel model)
        {
            HttpResponseMessage returnMessage = new HttpResponseMessage();

            var role   = mapper.Map <PublisherDto>(model);
            var result = await service.CreateAsync(role);

            if (result.IsSuccess)
            {
                string message = ($"Student Created - {result.Entity.Id}");
                returnMessage = new HttpResponseMessage(HttpStatusCode.Created);
                returnMessage.RequestMessage = new HttpRequestMessage(HttpMethod.Post, message);
            }
            else
            {
                returnMessage = new HttpResponseMessage(HttpStatusCode.ExpectationFailed);
                returnMessage.RequestMessage = new HttpRequestMessage(HttpMethod.Post, result.GetErrorString());
            }

            return(returnMessage);
        }