Esempio n. 1
0
        public async Task <IActionResult> Create([FromForm] CampaignViewModel campaignVM)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(new JsonResult(new { viewmodel = campaignVM, message = ModelState.Values })));
            }

            var campaign = await campaignVM.ConvertAndSaveToDb(db);

            return(new JsonResult(campaign)
            {
                StatusCode = StatusCodes.Status200OK
            });
        }
Esempio n. 2
0
        [HttpPut]         //TODO Read UserId and compare to Campaign.OwnerId
        public async Task <IActionResult> Update([FromForm] CampaignViewModel campaignVM)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(new JsonResult(new { viewmodel = campaignVM, message = ModelState.Values })));
            }

            var campaign = db.Campaigns
                           .Where(p => p.Id == campaignVM.Id)
                           .Include(x => x.Category)
                           .Include(x => x.Tags)
                           .Include(x => x.Images)
                           .Include(x => x.Videos)
                           .First();

            campaign = await campaignVM.ConvertAndSaveToDb(db, campaign);

            return(new JsonResult(campaign)
            {
                StatusCode = StatusCodes.Status200OK
            });
        }