Beispiel #1
0
        public async Task <IActionResult> CreatePublisherAsync([FromBody] PublisherCreateModel publisher)
        {
            await publisherService.CreatePublisher(new CreatePublisherDto()
            {
                Name = publisher.Name
            });

            return(StatusCode((int)HttpStatusCode.Created, "Publisher was added"));
        }
Beispiel #2
0
        public void CreatePublisher_ValidMethodParameter_True()
        {
            //assign
            Publisher          returnNull   = null;
            CreatePublisherDto newPublisher = new CreatePublisherDto()
            {
                Name = "Ubisoft"
            };

            publisherRepositoryMoq.Setup((p) => p.GetSingleAsync(It.IsAny <Expression <Func <Publisher, bool> > >()))
            .Returns(Task.FromResult(returnNull));

            //act
            service.CreatePublisher(newPublisher);

            //assign
            publisherRepositoryMoq.Verify(p => p.Create(It.IsAny <Publisher>()), Times.Once);
            unitofworkMoq.Verify(p => p.CommitAsync(), Times.Once);
        }
        public IActionResult Create([FromForm] PublisherViewModel publisher)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var publisherModel = _mapper.Map <Publisher>(publisher);

            _publisherService.CreatePublisher(publisherModel);
            var publisherOrigin = _publisherService.GetPublisherByCompany(publisher.CompanyName);

            _publisherService.AddPublisherTranslate(publisher.CompanyNameRu, publisher.DescriptionRu, publisher.HomePageRu, "ru", publisherOrigin.Id);

            return(StatusCode(StatusCodes.Status201Created));
        }
        public ActionResult Create(PublisherCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            //  var service = new PublisherService();

            if (_publisherService.CreatePublisher(model))
            {
                TempData["SaveResult"] = "Your publisher was added.";
                return(RedirectToAction("Index"));
            }
            ModelState.AddModelError("", "Publisher could not be added.");
            return(View(model));
        }
        public IActionResult OnPost()
        {
            if (ModelState.IsValid)
            {
                if (Publisher.Id == 0)
                {
                    Publisher           = publisherService.CreatePublisher(Publisher);
                    TempData["Message"] = "Publisher Created!";
                }
                else
                {
                    Publisher           = publisherService.UpdatePublisher(Publisher);
                    TempData["Message"] = "Publisher Upadated!";
                }
                publisherService.Commit();
                return(RedirectToPage("PublisherList", new { id = Publisher.Id }));
            }

            return(Page());
        }
Beispiel #6
0
        public IActionResult Edit(Publisher publisher)
        {
            if (ModelState.IsValid)
            {
                if (publisher.Id == 0)
                {
                    publisher           = publisherService.CreatePublisher(publisher);
                    TempData["Message"] = "Publisher Created";
                }
                else
                {
                    publisher           = publisherService.UpdatePublisher(publisher);
                    TempData["Message"] = "Publisher Updated!";
                }

                publisherService.Commit();
                return(RedirectToAction("Index"));
            }

            return(View(publisher));
        }
        //[ValidateAntiForgeryToken]
        public IActionResult Create(PublisherViewModel model)
        {
            if (ModelState.IsValid)
            {
                var publisher = new Publisher()
                {
                    Name        = model.Name,
                    Description = model.Description,
                    CountryId   = model.CountryId
                };

                var result = _publisherService.CreatePublisher(publisher);

                model.Id = publisher.Id;

                if (result.Succedeed)
                {
                    return(Json(model));
                }

                return(NotFound(result));
            }
            return(PartialView(model));
        }
Beispiel #8
0
        public async Task <HttpResponseMessage> Create([FromBody] PublisherModel publisher)
        {
            var result = await _publisherService.CreatePublisher(publisher);

            return(result.CreateRespose(HttpStatusCode.Created, HttpStatusCode.BadRequest));
        }