Skip to content

Commit

Permalink
Fix save logic for Campaigns
Browse files Browse the repository at this point in the history
  • Loading branch information
dpaquette committed Mar 7, 2018
1 parent 9fe8737 commit 27c7fc8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using AllReady.Areas.Admin.ViewModels.Organization;
Expand All @@ -24,7 +24,13 @@ public async Task<int> Handle(EditCampaignCommand message)
.Include(l => l.Location)
.Include(tc => tc.CampaignContacts)
.Include(i => i.CampaignGoals)
.SingleOrDefaultAsync(c => c.Id == message.Campaign.Id) ?? new Campaign();
.SingleOrDefaultAsync(c => c.Id == message.Campaign.Id);

if (campaign == null)
{
campaign = new Campaign();
_context.Campaigns.Add(campaign);
}

campaign.Name = message.Campaign.Name;
campaign.Description = message.Campaign.Description;
Expand All @@ -45,9 +51,7 @@ public async Task<int> Handle(EditCampaignCommand message)
campaign.Featured = message.Campaign.Featured;
campaign.Published = message.Campaign.Published;
campaign.Headline = message.Campaign.Headline;

_context.AddOrUpdate(campaign);


await _context.SaveChangesAsync();

return campaign.Id;
Expand Down Expand Up @@ -99,4 +103,4 @@ private void CreateUpdateOrDeleteCampaignPrimaryContact(Campaign campaign, IPrim
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace AllReady.Extensions
{
public static class ContextExtensions
{
//TODO: This shouldn't be necessary and it kind of weird. I supsect this is from an early beta version
/// <summary>
/// Handles correctly attaching an object to the context for cases where it may be new or modified.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion AllReadyApp/Web-App/AllReady/Models/Location.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public static Location UpdateModel(this Location location, LocationEditViewModel
}
else
{
if (location == null || locationEditModel.Id.GetValueOrDefault() != 0)
if (location == null || locationEditModel.Id.GetValueOrDefault() == 0)
{
location = new Location();
}
Expand Down

0 comments on commit 27c7fc8

Please sign in to comment.