コード例 #1
0
        public IActionResult Create([FromBody] CampaignInputModel inputModel)
        {
            if (inputModel == null)
            {
                return(BadRequest());
            }


            var campaign = inputModel.ToEntity();

            if (!_productStore.Exists(campaign.ProductId))
            {
                ModelState.AddModelError("Product", $"Product '{campaign.ProductId}' does not exists.");
                return(BadRequest(ModelState));
            }

            campaign = _service.Create(campaign);
            campaign = _service.GetById(campaign.Id);
            if (null == campaign)
            {
                return(NoContent());
            }

            var outputModel = CampaignOutputModel.FromEntity(campaign);

            return(CreatedAtRoute("ViewCampaign",
                                  new { id = outputModel.Id }, outputModel));
        }
コード例 #2
0
        // GET: Campaigns/Details/5
        public IActionResult Details(int?id)
        {
            Campaign campaign = FetchOrDefault(id);

            if (null == campaign)
            {
                return(NotFound());
            }

            return(View(CampaignOutputModel.FromEntity(campaign)));
        }
コード例 #3
0
        public ActionResult <CampaignOutputModel> Get(int id)
        {
            Campaign campaign = _service.GetById(id);

            if (null == campaign)
            {
                return(NoContent());
            }

            return(CampaignOutputModel.FromEntity(campaign));
        }
コード例 #4
0
        public IActionResult Create([FromForm] CampaignInputModel inputModel)
        {
            if (!ModelState.IsValid)
            {
                ViewData["ProductId"] = new SelectList(_productStore.List(), "Id", "Name");
                return(View(inputModel));
            }

            var campaign = inputModel.ToEntity();

            if (!_productStore.Exists(campaign.ProductId))
            {
                ModelState.AddModelError("Product", $"Product '{campaign.ProductId}' does not exists.");
                return(BadRequest(ModelState));
            }

            campaign = _service.Create(campaign);

            var outputModel = CampaignOutputModel.FromEntity(campaign);

            return(RedirectToAction(nameof(Index)));
        }