// GET: Campaign/Edit/5 public async Task <IActionResult> Edit(int?id) { var currentUser = await _userManager.GetCurrentUser(Context); if (currentUser == null) { return(new HttpUnauthorizedResult()); } if (id == null) { return(new HttpStatusCodeResult(404)); } Campaign campaign = _dataAccess.GetCampaign((int)id); if (!await UserIsTenantAdminOfCampaign(currentUser, campaign)) { return(new HttpUnauthorizedResult()); } if (campaign == null) { return(new HttpStatusCodeResult(404)); } return(await Task.FromResult(WithTenants(View(campaign)))); }
public IActionResult Details(int id) { var campaign = _dataAccess.GetCampaign(id); if (campaign == null) { HttpNotFound(); } return(View("Details", new CampaignViewModel(campaign))); }
// GET: Campaign/Edit/5 public async Task <IActionResult> Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(404)); } Campaign campaign = _dataAccess.GetCampaign((int)id); if (!UserIsTenantAdminOfCampaign(campaign)) { return(new HttpUnauthorizedResult()); } if (campaign == null) { return(new HttpStatusCodeResult(404)); } return(await Task.FromResult(WithTenants(View(campaign)))); }
/// <summary> /// Returns null when there is no matching campaign for the campaign Id. /// </summary> public static Activity ToModel(this ActivityViewModel activity, IAllReadyDataAccess dataAccess) { var campaign = dataAccess.GetCampaign(activity.CampaignId); if (campaign == null) { return(null); } Activity newActivity = new Activity() { Id = activity.Id, Campaign = campaign, EndDateTimeUtc = activity.EndDateTime.UtcDateTime, StartDateTimeUtc = activity.StartDateTime.UtcDateTime, Location = new Location() { Address1 = activity.Location.Address1, Address2 = activity.Location.Address2, City = activity.Location.City, Country = "US", PostalCode = activity.Location.PostalCode, State = activity.Location.State }, Name = activity.Title }; var tasks = new List <AllReadyTask>(); foreach (TaskViewModel tvm in activity.Tasks) { tasks.Add(new AllReadyTask() { Activity = newActivity, Name = tvm.Name, Id = tvm.Id, Description = tvm.Description }); } newActivity.Tasks = tasks; return(newActivity); }
public void Put(int id, [FromBody] ActivityViewModel value) { var activity = _allReadyDataAccess.GetActivity(value.Id); if (activity == null) { this.HttpBadRequest(); } var associatedCampaign = _allReadyDataAccess.GetCampaign(value.CampaignId); var tenant = _allReadyDataAccess.GetTenant(value.TenantId); // TODO: Helper method to do this kind of conversion. activity.Campaign = associatedCampaign; activity.EndDateTimeUtc = value.EndDateTime.UtcDateTime; activity.Location = value.Location.ToModel(); activity.Name = value.Title; activity.StartDateTimeUtc = value.StartDateTime.UtcDateTime; activity.Tasks = value.Tasks.ToModel(_allReadyDataAccess).ToList(); activity.Tenant = tenant; _allReadyDataAccess.UpdateActivity(activity); }
/// <summary> /// Returns null when there is no matching campaign for the campaign Id. /// </summary> public static Activity ToModel(this ActivityViewModel activity, IAllReadyDataAccess dataAccess) { var campaign = dataAccess.GetCampaign(activity.CampaignId); if (campaign == null) return null; Activity newActivity = new Activity() { Id = activity.Id, Campaign = campaign, EndDateTimeUtc = activity.EndDateTime.UtcDateTime, StartDateTimeUtc = activity.StartDateTime.UtcDateTime, Location = new Location() { Address1 = activity.Location.Address1, Address2 = activity.Location.Address2, City = activity.Location.City, Country = "US", PostalCode = activity.Location.PostalCode, State = activity.Location.State }, Name = activity.Title }; var tasks = new List<AllReadyTask>(); foreach (TaskViewModel tvm in activity.Tasks) { tasks.Add(new AllReadyTask() { Activity = newActivity, Name = tvm.Name, Id = tvm.Id, Description = tvm.Description }); } newActivity.Tasks = tasks; return newActivity; }
public Campaign Handle(CampaignByCampaignIdQuery message) { return(_dataAccess.GetCampaign(message.CampaignId)); }