public async Task <IActionResult> Edit(ActivityDetailModel activity, IFormFile fileUpload) { if (activity == null) { return(HttpBadRequest()); } //TODO: Use the query pattern here int organizationId = _dataAccess.GetManagingOrganizationId(activity.Id); if (!User.IsOrganizationAdmin(organizationId)) { return(HttpUnauthorized()); } if (activity.EndDateTime < activity.StartDateTime) { ModelState.AddModelError(nameof(activity.EndDateTime), "End date cannot be earlier than the start date"); } CampaignSummaryModel campaign = _mediator.Send(new CampaignSummaryQuery { CampaignId = activity.CampaignId }); if (activity.StartDateTime < campaign.StartDate) { ModelState.AddModelError(nameof(activity.StartDateTime), "Start date cannot be earlier than the campaign start date " + campaign.StartDate.ToString("d")); } if (activity.EndDateTime > campaign.EndDate) { ModelState.AddModelError(nameof(activity.EndDateTime), "End date cannot be later than the campaign end date " + campaign.EndDate.ToString("d")); } if (ModelState.IsValid) { if (fileUpload != null) { if (fileUpload.IsAcceptableImageContentType()) { activity.ImageUrl = await _imageService.UploadActivityImageAsync(campaign.OrganizationId, activity.Id, fileUpload); } else { ModelState.AddModelError("ImageUrl", "You must upload a valid image file for the logo (.jpg, .png, .gif)"); return(View(activity)); } } var id = _mediator.Send(new EditActivityCommand { Activity = activity }); return(RedirectToAction("Details", "Activity", new { area = "Admin", id = id })); } return(View(activity)); }
public async Task <IActionResult> Edit(ActivityDetailModel activity, IFormFile fileUpload) { if (activity == null) { return(HttpBadRequest()); } //TODO: Use the query pattern here var organizationId = _dataAccess.GetManagingOrganizationId(activity.Id); if (!User.IsOrganizationAdmin(organizationId)) { return(HttpUnauthorized()); } CampaignSummaryModel campaign = await _mediator.SendAsync(new CampaignSummaryQuery { CampaignId = activity.CampaignId }); var validator = new ActivityDetailModelValidator(_mediator); var errors = await validator.Validate(activity, campaign); errors.ForEach(e => ModelState.AddModelError(e.Key, e.Value)); if (ModelState.IsValid) { if (fileUpload != null) { if (fileUpload.IsAcceptableImageContentType()) { activity.ImageUrl = await _imageService.UploadActivityImageAsync(campaign.OrganizationId, activity.Id, fileUpload); } else { ModelState.AddModelError("ImageUrl", "You must upload a valid image file for the logo (.jpg, .png, .gif)"); return(View(activity)); } } var id = _mediator.Send(new EditActivityCommand { Activity = activity }); return(RedirectToAction("Details", "Activity", new { area = "Admin", id = id })); } return(View(activity)); }
public int Handle(ManagingOrganizationIdByEventIdQuery message) { return(dataAccess.GetManagingOrganizationId(message.EventId)); }
public int Handle(ManagingOrganizationIdByActivityIdQuery message) { return(dataAccess.GetManagingOrganizationId(message.ActivityId)); }