public void Post([FromBody] CampaignViewModel campaign) { if (campaign == null) { HttpBadRequest(); } var exists = _dataAccess.GetCampaign(campaign.Id) != null; _dataAccess.AddCampaign(campaign.ToModel(_dataAccess)); }
public async Task <IActionResult> Create(Campaign campaign) { var currentUser = await _userManager.GetCurrentUser(Context); if (currentUser == null) { return(new HttpUnauthorizedResult()); } // Workaround: Sometimes AssociatedTenant is missing when using UserManager var currentUserWithAssociatedTenant = _dataAccess.GetUser(currentUser.Id); if (!await UserIsTenantAdminOfCampaign(currentUserWithAssociatedTenant, campaign)) { return(new HttpUnauthorizedResult()); } if (ModelState.IsValid) { await _dataAccess.AddCampaign(campaign); return(await Task.FromResult(RedirectToAction("Index", new { area = "Admin" }))); } return(await Task.FromResult(WithTenants(View("Edit", campaign)))); }
public async Task <IActionResult> Create(Campaign campaign) { if (!UserIsTenantAdminOfCampaign(campaign)) { return(new HttpUnauthorizedResult()); } if (ModelState.IsValid) { await _dataAccess.AddCampaign(campaign); return(await Task.FromResult(RedirectToAction("Index", new { area = "Admin" }))); } return(await Task.FromResult(WithTenants(View("Edit", campaign)))); }