From 071d8ccec5eb00e364f1fba3d7d20289665bf797 Mon Sep 17 00:00:00 2001 From: Steve Gordon Date: Mon, 25 Jan 2016 07:16:50 +0000 Subject: [PATCH 1/7] Changing DB model and updating controllers, handlers and views --- .../Campaigns/CampaignListQueryHandler.cs | 3 +- .../Admin/Models/CampaignSummaryModel.cs | 1 + .../Areas/Admin/Views/Campaign/Index.cshtml | 4 + .../Controllers/CampaignController.cs | 8 +- .../20160125071535_CampaignLock.Designer.cs | 689 ++++++++++++++++++ .../Migrations/20160125071535_CampaignLock.cs | 295 ++++++++ .../AllReadyContextModelSnapshot.cs | 2 + .../Web-App/AllReady/Models/Campaign.cs | 1 + .../Web-App/AllReady/Models/CampaignStatus.cs | 12 + 9 files changed, 1010 insertions(+), 5 deletions(-) create mode 100644 AllReadyApp/Web-App/AllReady/Migrations/20160125071535_CampaignLock.Designer.cs create mode 100644 AllReadyApp/Web-App/AllReady/Migrations/20160125071535_CampaignLock.cs create mode 100644 AllReadyApp/Web-App/AllReady/Models/CampaignStatus.cs diff --git a/AllReadyApp/Web-App/AllReady/Areas/Admin/Features/Campaigns/CampaignListQueryHandler.cs b/AllReadyApp/Web-App/AllReady/Areas/Admin/Features/Campaigns/CampaignListQueryHandler.cs index 9eb346fb0..58bb45329 100644 --- a/AllReadyApp/Web-App/AllReady/Areas/Admin/Features/Campaigns/CampaignListQueryHandler.cs +++ b/AllReadyApp/Web-App/AllReady/Areas/Admin/Features/Campaigns/CampaignListQueryHandler.cs @@ -34,7 +34,8 @@ public IEnumerable Handle(CampaignListQuery message) OrganizationName = c.ManagingOrganization.Name, TimeZoneId = c.TimeZoneId, StartDate = c.StartDateTime, - EndDate = c.EndDateTime + EndDate = c.EndDateTime, + Locked = c.Locked }); return campaigns; diff --git a/AllReadyApp/Web-App/AllReady/Areas/Admin/Models/CampaignSummaryModel.cs b/AllReadyApp/Web-App/AllReady/Areas/Admin/Models/CampaignSummaryModel.cs index 8dcf469b8..8caacbf9f 100644 --- a/AllReadyApp/Web-App/AllReady/Areas/Admin/Models/CampaignSummaryModel.cs +++ b/AllReadyApp/Web-App/AllReady/Areas/Admin/Models/CampaignSummaryModel.cs @@ -62,5 +62,6 @@ public CampaignSummaryModel() [EmailAddress] public string PrimaryContactEmail { get; set; } + public bool Locked { get; set; } } } diff --git a/AllReadyApp/Web-App/AllReady/Areas/Admin/Views/Campaign/Index.cshtml b/AllReadyApp/Web-App/AllReady/Areas/Admin/Views/Campaign/Index.cshtml index 59dc943c7..abf55009d 100644 --- a/AllReadyApp/Web-App/AllReady/Areas/Admin/Views/Campaign/Index.cshtml +++ b/AllReadyApp/Web-App/AllReady/Areas/Admin/Views/Campaign/Index.cshtml @@ -40,6 +40,10 @@ @item.Name + @if (item.Locked) + { + + } @if (!string.IsNullOrEmpty(item.Description)) {
@item.Description diff --git a/AllReadyApp/Web-App/AllReady/Controllers/CampaignController.cs b/AllReadyApp/Web-App/AllReady/Controllers/CampaignController.cs index 42e4f3a14..51be30579 100644 --- a/AllReadyApp/Web-App/AllReady/Controllers/CampaignController.cs +++ b/AllReadyApp/Web-App/AllReady/Controllers/CampaignController.cs @@ -3,7 +3,6 @@ using Microsoft.AspNet.Mvc; using AllReady.Models; using AllReady.ViewModels; -using Microsoft.Data.Entity; namespace AllReady.Controllers { @@ -21,7 +20,7 @@ public CampaignController(IAllReadyDataAccess dataAccess) [Route("~/[controller]")] public IActionResult Index() { - return View(_dataAccess.Campaigns.ToViewModel().ToList()); + return View(_dataAccess.Campaigns.Where(c => c.Locked == false).ToViewModel().ToList()); } [HttpGet] @@ -30,7 +29,7 @@ public IActionResult Details(int id) { var campaign = _dataAccess.GetCampaign(id); - if (campaign == null) + if (campaign == null || campaign.Locked == false) HttpNotFound(); return View("Details", new CampaignViewModel(campaign)); @@ -53,6 +52,7 @@ public IActionResult LocationMap(int id) public IEnumerable Get() { return _dataAccess.Campaigns + .Where(c => c.Locked == false) .Select(x => new CampaignViewModel(x)); } @@ -62,7 +62,7 @@ public CampaignViewModel Get(int id) { var campaign = _dataAccess.GetCampaign(id); - if (campaign == null) + if (campaign == null || campaign.Locked == false) HttpNotFound(); return campaign.ToViewModel(); diff --git a/AllReadyApp/Web-App/AllReady/Migrations/20160125071535_CampaignLock.Designer.cs b/AllReadyApp/Web-App/AllReady/Migrations/20160125071535_CampaignLock.Designer.cs new file mode 100644 index 000000000..5caa63689 --- /dev/null +++ b/AllReadyApp/Web-App/AllReady/Migrations/20160125071535_CampaignLock.Designer.cs @@ -0,0 +1,689 @@ +using System; +using Microsoft.Data.Entity; +using Microsoft.Data.Entity.Infrastructure; +using Microsoft.Data.Entity.Metadata; +using Microsoft.Data.Entity.Migrations; +using AllReady.Models; + +namespace AllReady.Migrations +{ + [DbContext(typeof(AllReadyContext))] + [Migration("20160125071535_CampaignLock")] + partial class CampaignLock + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { + modelBuilder + .HasAnnotation("ProductVersion", "7.0.0-rc1-16348") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + modelBuilder.Entity("AllReady.Models.Activity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("CampaignId"); + + b.Property("Description"); + + b.Property("EndDateTime"); + + b.Property("ImageUrl"); + + b.Property("LocationId"); + + b.Property("Name") + .IsRequired(); + + b.Property("NumberOfVolunteersRequired"); + + b.Property("OrganizerId"); + + b.Property("StartDateTime"); + + b.HasKey("Id"); + }); + + modelBuilder.Entity("AllReady.Models.ActivitySignup", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ActivityId"); + + b.Property("AdditionalInfo"); + + b.Property("CheckinDateTime"); + + b.Property("PreferredEmail"); + + b.Property("PreferredPhoneNumber"); + + b.Property("SignupDateTime"); + + b.Property("UserId"); + + b.HasKey("Id"); + }); + + modelBuilder.Entity("AllReady.Models.ActivitySkill", b => + { + b.Property("ActivityId"); + + b.Property("SkillId"); + + b.HasKey("ActivityId", "SkillId"); + }); + + modelBuilder.Entity("AllReady.Models.AllReadyTask", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ActivityId"); + + b.Property("Description"); + + b.Property("EndDateTime"); + + b.Property("Name") + .IsRequired(); + + b.Property("NumberOfVolunteersRequired"); + + b.Property("OrganizationId"); + + b.Property("StartDateTime"); + + b.HasKey("Id"); + }); + + modelBuilder.Entity("AllReady.Models.ApplicationUser", b => + { + b.Property("Id"); + + b.Property("AccessFailedCount"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken(); + + b.Property("Email") + .HasAnnotation("MaxLength", 256); + + b.Property("EmailConfirmed"); + + b.Property("LockoutEnabled"); + + b.Property("LockoutEnd"); + + b.Property("Name"); + + b.Property("NormalizedEmail") + .HasAnnotation("MaxLength", 256); + + b.Property("NormalizedUserName") + .HasAnnotation("MaxLength", 256); + + b.Property("OrganizationId"); + + b.Property("PasswordHash"); + + b.Property("PendingNewEmail"); + + b.Property("PhoneNumber"); + + b.Property("PhoneNumberConfirmed"); + + b.Property("SecurityStamp"); + + b.Property("TimeZoneId") + .IsRequired(); + + b.Property("TwoFactorEnabled"); + + b.Property("UserName") + .HasAnnotation("MaxLength", 256); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasAnnotation("Relational:Name", "EmailIndex"); + + b.HasIndex("NormalizedUserName") + .HasAnnotation("Relational:Name", "UserNameIndex"); + + b.HasAnnotation("Relational:TableName", "AspNetUsers"); + }); + + modelBuilder.Entity("AllReady.Models.Campaign", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("CampaignImpactId"); + + b.Property("Description"); + + b.Property("EndDateTime"); + + b.Property("FullDescription"); + + b.Property("ImageUrl"); + + b.Property("LocationId"); + + b.Property("Locked"); + + b.Property("ManagingOrganizationId"); + + b.Property("Name") + .IsRequired(); + + b.Property("OrganizerId"); + + b.Property("StartDateTime"); + + b.Property("TimeZoneId") + .IsRequired(); + + b.HasKey("Id"); + }); + + modelBuilder.Entity("AllReady.Models.CampaignContact", b => + { + b.Property("CampaignId"); + + b.Property("ContactId"); + + b.Property("ContactType"); + + b.HasKey("CampaignId", "ContactId", "ContactType"); + }); + + modelBuilder.Entity("AllReady.Models.CampaignImpact", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("CurrentImpactLevel"); + + b.Property("Display"); + + b.Property("ImpactType"); + + b.Property("NumericImpactGoal"); + + b.Property("TextualImpactGoal"); + + b.HasKey("Id"); + }); + + modelBuilder.Entity("AllReady.Models.CampaignSponsors", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("CampaignId"); + + b.Property("OrganizationId"); + + b.HasKey("Id"); + }); + + modelBuilder.Entity("AllReady.Models.ClosestLocation", b => + { + b.Property("PostalCode"); + + b.Property("City"); + + b.Property("Distance"); + + b.Property("State"); + + b.HasKey("PostalCode"); + }); + + modelBuilder.Entity("AllReady.Models.Contact", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Email"); + + b.Property("FirstName"); + + b.Property("LastName"); + + b.Property("PhoneNumber"); + + b.HasKey("Id"); + }); + + modelBuilder.Entity("AllReady.Models.Location", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Address1"); + + b.Property("Address2"); + + b.Property("City"); + + b.Property("Country"); + + b.Property("Name"); + + b.Property("PhoneNumber"); + + b.Property("PostalCodePostalCode"); + + b.Property("State"); + + b.HasKey("Id"); + }); + + modelBuilder.Entity("AllReady.Models.Organization", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("LocationId"); + + b.Property("LogoUrl"); + + b.Property("Name") + .IsRequired(); + + b.Property("WebUrl"); + + b.HasKey("Id"); + }); + + modelBuilder.Entity("AllReady.Models.OrganizationContact", b => + { + b.Property("OrganizationId"); + + b.Property("ContactId"); + + b.Property("ContactType"); + + b.HasKey("OrganizationId", "ContactId", "ContactType"); + }); + + modelBuilder.Entity("AllReady.Models.PostalCodeGeo", b => + { + b.Property("PostalCode"); + + b.Property("City"); + + b.Property("State"); + + b.HasKey("PostalCode"); + }); + + modelBuilder.Entity("AllReady.Models.PostalCodeGeoCoordinate", b => + { + b.Property("Latitude"); + + b.Property("Longitude"); + + b.HasKey("Latitude", "Longitude"); + }); + + modelBuilder.Entity("AllReady.Models.Resource", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("CategoryTag"); + + b.Property("Description"); + + b.Property("MediaUrl"); + + b.Property("Name"); + + b.Property("PublishDateBegin"); + + b.Property("PublishDateEnd"); + + b.Property("ResourceUrl"); + + b.HasKey("Id"); + }); + + modelBuilder.Entity("AllReady.Models.Skill", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Description"); + + b.Property("Name") + .IsRequired(); + + b.Property("OwningOrganizationId"); + + b.Property("ParentSkillId"); + + b.HasKey("Id"); + }); + + modelBuilder.Entity("AllReady.Models.TaskSignup", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Status"); + + b.Property("StatusDateTimeUtc"); + + b.Property("StatusDescription"); + + b.Property("TaskId"); + + b.Property("UserId"); + + b.HasKey("Id"); + }); + + modelBuilder.Entity("AllReady.Models.TaskSkill", b => + { + b.Property("TaskId"); + + b.Property("SkillId"); + + b.HasKey("TaskId", "SkillId"); + }); + + modelBuilder.Entity("AllReady.Models.UserSkill", b => + { + b.Property("UserId"); + + b.Property("SkillId"); + + b.HasKey("UserId", "SkillId"); + }); + + modelBuilder.Entity("Microsoft.AspNet.Identity.EntityFramework.IdentityRole", b => + { + b.Property("Id"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken(); + + b.Property("Name") + .HasAnnotation("MaxLength", 256); + + b.Property("NormalizedName") + .HasAnnotation("MaxLength", 256); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .HasAnnotation("Relational:Name", "RoleNameIndex"); + + b.HasAnnotation("Relational:TableName", "AspNetRoles"); + }); + + modelBuilder.Entity("Microsoft.AspNet.Identity.EntityFramework.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ClaimType"); + + b.Property("ClaimValue"); + + b.Property("RoleId") + .IsRequired(); + + b.HasKey("Id"); + + b.HasAnnotation("Relational:TableName", "AspNetRoleClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNet.Identity.EntityFramework.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ClaimType"); + + b.Property("ClaimValue"); + + b.Property("UserId") + .IsRequired(); + + b.HasKey("Id"); + + b.HasAnnotation("Relational:TableName", "AspNetUserClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNet.Identity.EntityFramework.IdentityUserLogin", b => + { + b.Property("LoginProvider"); + + b.Property("ProviderKey"); + + b.Property("ProviderDisplayName"); + + b.Property("UserId") + .IsRequired(); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasAnnotation("Relational:TableName", "AspNetUserLogins"); + }); + + modelBuilder.Entity("Microsoft.AspNet.Identity.EntityFramework.IdentityUserRole", b => + { + b.Property("UserId"); + + b.Property("RoleId"); + + b.HasKey("UserId", "RoleId"); + + b.HasAnnotation("Relational:TableName", "AspNetUserRoles"); + }); + + modelBuilder.Entity("AllReady.Models.Activity", b => + { + b.HasOne("AllReady.Models.Campaign") + .WithMany() + .HasForeignKey("CampaignId"); + + b.HasOne("AllReady.Models.Location") + .WithMany() + .HasForeignKey("LocationId"); + + b.HasOne("AllReady.Models.ApplicationUser") + .WithMany() + .HasForeignKey("OrganizerId"); + }); + + modelBuilder.Entity("AllReady.Models.ActivitySignup", b => + { + b.HasOne("AllReady.Models.Activity") + .WithMany() + .HasForeignKey("ActivityId"); + + b.HasOne("AllReady.Models.ApplicationUser") + .WithMany() + .HasForeignKey("UserId"); + }); + + modelBuilder.Entity("AllReady.Models.ActivitySkill", b => + { + b.HasOne("AllReady.Models.Activity") + .WithMany() + .HasForeignKey("ActivityId"); + + b.HasOne("AllReady.Models.Skill") + .WithMany() + .HasForeignKey("SkillId"); + }); + + modelBuilder.Entity("AllReady.Models.AllReadyTask", b => + { + b.HasOne("AllReady.Models.Activity") + .WithMany() + .HasForeignKey("ActivityId"); + + b.HasOne("AllReady.Models.Organization") + .WithMany() + .HasForeignKey("OrganizationId"); + }); + + modelBuilder.Entity("AllReady.Models.ApplicationUser", b => + { + b.HasOne("AllReady.Models.Organization") + .WithMany() + .HasForeignKey("OrganizationId"); + }); + + modelBuilder.Entity("AllReady.Models.Campaign", b => + { + b.HasOne("AllReady.Models.CampaignImpact") + .WithMany() + .HasForeignKey("CampaignImpactId"); + + b.HasOne("AllReady.Models.Location") + .WithMany() + .HasForeignKey("LocationId"); + + b.HasOne("AllReady.Models.Organization") + .WithMany() + .HasForeignKey("ManagingOrganizationId"); + + b.HasOne("AllReady.Models.ApplicationUser") + .WithMany() + .HasForeignKey("OrganizerId"); + }); + + modelBuilder.Entity("AllReady.Models.CampaignContact", b => + { + b.HasOne("AllReady.Models.Campaign") + .WithMany() + .HasForeignKey("CampaignId"); + + b.HasOne("AllReady.Models.Contact") + .WithMany() + .HasForeignKey("ContactId"); + }); + + modelBuilder.Entity("AllReady.Models.CampaignSponsors", b => + { + b.HasOne("AllReady.Models.Campaign") + .WithMany() + .HasForeignKey("CampaignId"); + + b.HasOne("AllReady.Models.Organization") + .WithMany() + .HasForeignKey("OrganizationId"); + }); + + modelBuilder.Entity("AllReady.Models.Location", b => + { + b.HasOne("AllReady.Models.PostalCodeGeo") + .WithMany() + .HasForeignKey("PostalCodePostalCode"); + }); + + modelBuilder.Entity("AllReady.Models.Organization", b => + { + b.HasOne("AllReady.Models.Location") + .WithMany() + .HasForeignKey("LocationId"); + }); + + modelBuilder.Entity("AllReady.Models.OrganizationContact", b => + { + b.HasOne("AllReady.Models.Contact") + .WithMany() + .HasForeignKey("ContactId"); + + b.HasOne("AllReady.Models.Organization") + .WithMany() + .HasForeignKey("OrganizationId"); + }); + + modelBuilder.Entity("AllReady.Models.Skill", b => + { + b.HasOne("AllReady.Models.Organization") + .WithMany() + .HasForeignKey("OwningOrganizationId"); + + b.HasOne("AllReady.Models.Skill") + .WithMany() + .HasForeignKey("ParentSkillId"); + }); + + modelBuilder.Entity("AllReady.Models.TaskSignup", b => + { + b.HasOne("AllReady.Models.AllReadyTask") + .WithMany() + .HasForeignKey("TaskId"); + + b.HasOne("AllReady.Models.ApplicationUser") + .WithMany() + .HasForeignKey("UserId"); + }); + + modelBuilder.Entity("AllReady.Models.TaskSkill", b => + { + b.HasOne("AllReady.Models.Skill") + .WithMany() + .HasForeignKey("SkillId"); + + b.HasOne("AllReady.Models.AllReadyTask") + .WithMany() + .HasForeignKey("TaskId"); + }); + + modelBuilder.Entity("AllReady.Models.UserSkill", b => + { + b.HasOne("AllReady.Models.Skill") + .WithMany() + .HasForeignKey("SkillId"); + + b.HasOne("AllReady.Models.ApplicationUser") + .WithMany() + .HasForeignKey("UserId"); + }); + + modelBuilder.Entity("Microsoft.AspNet.Identity.EntityFramework.IdentityRoleClaim", b => + { + b.HasOne("Microsoft.AspNet.Identity.EntityFramework.IdentityRole") + .WithMany() + .HasForeignKey("RoleId"); + }); + + modelBuilder.Entity("Microsoft.AspNet.Identity.EntityFramework.IdentityUserClaim", b => + { + b.HasOne("AllReady.Models.ApplicationUser") + .WithMany() + .HasForeignKey("UserId"); + }); + + modelBuilder.Entity("Microsoft.AspNet.Identity.EntityFramework.IdentityUserLogin", b => + { + b.HasOne("AllReady.Models.ApplicationUser") + .WithMany() + .HasForeignKey("UserId"); + }); + + modelBuilder.Entity("Microsoft.AspNet.Identity.EntityFramework.IdentityUserRole", b => + { + b.HasOne("Microsoft.AspNet.Identity.EntityFramework.IdentityRole") + .WithMany() + .HasForeignKey("RoleId"); + + b.HasOne("AllReady.Models.ApplicationUser") + .WithMany() + .HasForeignKey("UserId"); + }); + } + } +} diff --git a/AllReadyApp/Web-App/AllReady/Migrations/20160125071535_CampaignLock.cs b/AllReadyApp/Web-App/AllReady/Migrations/20160125071535_CampaignLock.cs new file mode 100644 index 000000000..e723d1faf --- /dev/null +++ b/AllReadyApp/Web-App/AllReady/Migrations/20160125071535_CampaignLock.cs @@ -0,0 +1,295 @@ +using System; +using System.Collections.Generic; +using Microsoft.Data.Entity.Migrations; + +namespace AllReady.Migrations +{ + public partial class CampaignLock : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey(name: "FK_Activity_Campaign_CampaignId", table: "Activity"); + migrationBuilder.DropForeignKey(name: "FK_ActivitySkill_Activity_ActivityId", table: "ActivitySkill"); + migrationBuilder.DropForeignKey(name: "FK_ActivitySkill_Skill_SkillId", table: "ActivitySkill"); + migrationBuilder.DropForeignKey(name: "FK_Campaign_Organization_ManagingOrganizationId", table: "Campaign"); + migrationBuilder.DropForeignKey(name: "FK_CampaignContact_Campaign_CampaignId", table: "CampaignContact"); + migrationBuilder.DropForeignKey(name: "FK_CampaignContact_Contact_ContactId", table: "CampaignContact"); + migrationBuilder.DropForeignKey(name: "FK_OrganizationContact_Contact_ContactId", table: "OrganizationContact"); + migrationBuilder.DropForeignKey(name: "FK_OrganizationContact_Organization_OrganizationId", table: "OrganizationContact"); + migrationBuilder.DropForeignKey(name: "FK_TaskSkill_Skill_SkillId", table: "TaskSkill"); + migrationBuilder.DropForeignKey(name: "FK_TaskSkill_AllReadyTask_TaskId", table: "TaskSkill"); + migrationBuilder.DropForeignKey(name: "FK_UserSkill_Skill_SkillId", table: "UserSkill"); + migrationBuilder.DropForeignKey(name: "FK_UserSkill_ApplicationUser_UserId", table: "UserSkill"); + migrationBuilder.DropForeignKey(name: "FK_IdentityRoleClaim_IdentityRole_RoleId", table: "AspNetRoleClaims"); + migrationBuilder.DropForeignKey(name: "FK_IdentityUserClaim_ApplicationUser_UserId", table: "AspNetUserClaims"); + migrationBuilder.DropForeignKey(name: "FK_IdentityUserLogin_ApplicationUser_UserId", table: "AspNetUserLogins"); + migrationBuilder.DropForeignKey(name: "FK_IdentityUserRole_IdentityRole_RoleId", table: "AspNetUserRoles"); + migrationBuilder.DropForeignKey(name: "FK_IdentityUserRole_ApplicationUser_UserId", table: "AspNetUserRoles"); + migrationBuilder.AddColumn( + name: "Locked", + table: "Campaign", + nullable: false, + defaultValue: false); + migrationBuilder.AddForeignKey( + name: "FK_Activity_Campaign_CampaignId", + table: "Activity", + column: "CampaignId", + principalTable: "Campaign", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + migrationBuilder.AddForeignKey( + name: "FK_ActivitySkill_Activity_ActivityId", + table: "ActivitySkill", + column: "ActivityId", + principalTable: "Activity", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + migrationBuilder.AddForeignKey( + name: "FK_ActivitySkill_Skill_SkillId", + table: "ActivitySkill", + column: "SkillId", + principalTable: "Skill", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + migrationBuilder.AddForeignKey( + name: "FK_Campaign_Organization_ManagingOrganizationId", + table: "Campaign", + column: "ManagingOrganizationId", + principalTable: "Organization", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + migrationBuilder.AddForeignKey( + name: "FK_CampaignContact_Campaign_CampaignId", + table: "CampaignContact", + column: "CampaignId", + principalTable: "Campaign", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + migrationBuilder.AddForeignKey( + name: "FK_CampaignContact_Contact_ContactId", + table: "CampaignContact", + column: "ContactId", + principalTable: "Contact", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + migrationBuilder.AddForeignKey( + name: "FK_OrganizationContact_Contact_ContactId", + table: "OrganizationContact", + column: "ContactId", + principalTable: "Contact", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + migrationBuilder.AddForeignKey( + name: "FK_OrganizationContact_Organization_OrganizationId", + table: "OrganizationContact", + column: "OrganizationId", + principalTable: "Organization", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + migrationBuilder.AddForeignKey( + name: "FK_TaskSkill_Skill_SkillId", + table: "TaskSkill", + column: "SkillId", + principalTable: "Skill", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + migrationBuilder.AddForeignKey( + name: "FK_TaskSkill_AllReadyTask_TaskId", + table: "TaskSkill", + column: "TaskId", + principalTable: "AllReadyTask", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + migrationBuilder.AddForeignKey( + name: "FK_UserSkill_Skill_SkillId", + table: "UserSkill", + column: "SkillId", + principalTable: "Skill", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + migrationBuilder.AddForeignKey( + name: "FK_UserSkill_ApplicationUser_UserId", + table: "UserSkill", + column: "UserId", + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + migrationBuilder.AddForeignKey( + name: "FK_IdentityRoleClaim_IdentityRole_RoleId", + table: "AspNetRoleClaims", + column: "RoleId", + principalTable: "AspNetRoles", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + migrationBuilder.AddForeignKey( + name: "FK_IdentityUserClaim_ApplicationUser_UserId", + table: "AspNetUserClaims", + column: "UserId", + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + migrationBuilder.AddForeignKey( + name: "FK_IdentityUserLogin_ApplicationUser_UserId", + table: "AspNetUserLogins", + column: "UserId", + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + migrationBuilder.AddForeignKey( + name: "FK_IdentityUserRole_IdentityRole_RoleId", + table: "AspNetUserRoles", + column: "RoleId", + principalTable: "AspNetRoles", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + migrationBuilder.AddForeignKey( + name: "FK_IdentityUserRole_ApplicationUser_UserId", + table: "AspNetUserRoles", + column: "UserId", + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey(name: "FK_Activity_Campaign_CampaignId", table: "Activity"); + migrationBuilder.DropForeignKey(name: "FK_ActivitySkill_Activity_ActivityId", table: "ActivitySkill"); + migrationBuilder.DropForeignKey(name: "FK_ActivitySkill_Skill_SkillId", table: "ActivitySkill"); + migrationBuilder.DropForeignKey(name: "FK_Campaign_Organization_ManagingOrganizationId", table: "Campaign"); + migrationBuilder.DropForeignKey(name: "FK_CampaignContact_Campaign_CampaignId", table: "CampaignContact"); + migrationBuilder.DropForeignKey(name: "FK_CampaignContact_Contact_ContactId", table: "CampaignContact"); + migrationBuilder.DropForeignKey(name: "FK_OrganizationContact_Contact_ContactId", table: "OrganizationContact"); + migrationBuilder.DropForeignKey(name: "FK_OrganizationContact_Organization_OrganizationId", table: "OrganizationContact"); + migrationBuilder.DropForeignKey(name: "FK_TaskSkill_Skill_SkillId", table: "TaskSkill"); + migrationBuilder.DropForeignKey(name: "FK_TaskSkill_AllReadyTask_TaskId", table: "TaskSkill"); + migrationBuilder.DropForeignKey(name: "FK_UserSkill_Skill_SkillId", table: "UserSkill"); + migrationBuilder.DropForeignKey(name: "FK_UserSkill_ApplicationUser_UserId", table: "UserSkill"); + migrationBuilder.DropForeignKey(name: "FK_IdentityRoleClaim_IdentityRole_RoleId", table: "AspNetRoleClaims"); + migrationBuilder.DropForeignKey(name: "FK_IdentityUserClaim_ApplicationUser_UserId", table: "AspNetUserClaims"); + migrationBuilder.DropForeignKey(name: "FK_IdentityUserLogin_ApplicationUser_UserId", table: "AspNetUserLogins"); + migrationBuilder.DropForeignKey(name: "FK_IdentityUserRole_IdentityRole_RoleId", table: "AspNetUserRoles"); + migrationBuilder.DropForeignKey(name: "FK_IdentityUserRole_ApplicationUser_UserId", table: "AspNetUserRoles"); + migrationBuilder.DropColumn(name: "Locked", table: "Campaign"); + migrationBuilder.AddForeignKey( + name: "FK_Activity_Campaign_CampaignId", + table: "Activity", + column: "CampaignId", + principalTable: "Campaign", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + migrationBuilder.AddForeignKey( + name: "FK_ActivitySkill_Activity_ActivityId", + table: "ActivitySkill", + column: "ActivityId", + principalTable: "Activity", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + migrationBuilder.AddForeignKey( + name: "FK_ActivitySkill_Skill_SkillId", + table: "ActivitySkill", + column: "SkillId", + principalTable: "Skill", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + migrationBuilder.AddForeignKey( + name: "FK_Campaign_Organization_ManagingOrganizationId", + table: "Campaign", + column: "ManagingOrganizationId", + principalTable: "Organization", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + migrationBuilder.AddForeignKey( + name: "FK_CampaignContact_Campaign_CampaignId", + table: "CampaignContact", + column: "CampaignId", + principalTable: "Campaign", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + migrationBuilder.AddForeignKey( + name: "FK_CampaignContact_Contact_ContactId", + table: "CampaignContact", + column: "ContactId", + principalTable: "Contact", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + migrationBuilder.AddForeignKey( + name: "FK_OrganizationContact_Contact_ContactId", + table: "OrganizationContact", + column: "ContactId", + principalTable: "Contact", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + migrationBuilder.AddForeignKey( + name: "FK_OrganizationContact_Organization_OrganizationId", + table: "OrganizationContact", + column: "OrganizationId", + principalTable: "Organization", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + migrationBuilder.AddForeignKey( + name: "FK_TaskSkill_Skill_SkillId", + table: "TaskSkill", + column: "SkillId", + principalTable: "Skill", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + migrationBuilder.AddForeignKey( + name: "FK_TaskSkill_AllReadyTask_TaskId", + table: "TaskSkill", + column: "TaskId", + principalTable: "AllReadyTask", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + migrationBuilder.AddForeignKey( + name: "FK_UserSkill_Skill_SkillId", + table: "UserSkill", + column: "SkillId", + principalTable: "Skill", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + migrationBuilder.AddForeignKey( + name: "FK_UserSkill_ApplicationUser_UserId", + table: "UserSkill", + column: "UserId", + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + migrationBuilder.AddForeignKey( + name: "FK_IdentityRoleClaim_IdentityRole_RoleId", + table: "AspNetRoleClaims", + column: "RoleId", + principalTable: "AspNetRoles", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + migrationBuilder.AddForeignKey( + name: "FK_IdentityUserClaim_ApplicationUser_UserId", + table: "AspNetUserClaims", + column: "UserId", + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + migrationBuilder.AddForeignKey( + name: "FK_IdentityUserLogin_ApplicationUser_UserId", + table: "AspNetUserLogins", + column: "UserId", + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + migrationBuilder.AddForeignKey( + name: "FK_IdentityUserRole_IdentityRole_RoleId", + table: "AspNetUserRoles", + column: "RoleId", + principalTable: "AspNetRoles", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + migrationBuilder.AddForeignKey( + name: "FK_IdentityUserRole_ApplicationUser_UserId", + table: "AspNetUserRoles", + column: "UserId", + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + } + } +} diff --git a/AllReadyApp/Web-App/AllReady/Migrations/AllReadyContextModelSnapshot.cs b/AllReadyApp/Web-App/AllReady/Migrations/AllReadyContextModelSnapshot.cs index 264814778..179da4316 100644 --- a/AllReadyApp/Web-App/AllReady/Migrations/AllReadyContextModelSnapshot.cs +++ b/AllReadyApp/Web-App/AllReady/Migrations/AllReadyContextModelSnapshot.cs @@ -171,6 +171,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("LocationId"); + b.Property("Locked"); + b.Property("ManagingOrganizationId"); b.Property("Name") diff --git a/AllReadyApp/Web-App/AllReady/Models/Campaign.cs b/AllReadyApp/Web-App/AllReady/Models/Campaign.cs index 6863e5eff..e16d66150 100644 --- a/AllReadyApp/Web-App/AllReady/Models/Campaign.cs +++ b/AllReadyApp/Web-App/AllReady/Models/Campaign.cs @@ -56,5 +56,6 @@ public class Campaign public List CampaignContacts { get; set; } + public bool Locked { get; set; } } } \ No newline at end of file diff --git a/AllReadyApp/Web-App/AllReady/Models/CampaignStatus.cs b/AllReadyApp/Web-App/AllReady/Models/CampaignStatus.cs new file mode 100644 index 000000000..d6c03734d --- /dev/null +++ b/AllReadyApp/Web-App/AllReady/Models/CampaignStatus.cs @@ -0,0 +1,12 @@ +namespace AllReady.Models +{ + /// + /// Describes the overall status of a campaign + /// + public enum CampaignStatus + { + Draft = 0, + Live= 1, + Locked = 2 + } +} \ No newline at end of file From 657ad35cdfecf854f584d41bfe094ca20e6b738f Mon Sep 17 00:00:00 2001 From: Steve Gordon Date: Tue, 26 Jan 2016 19:11:38 +0000 Subject: [PATCH 2/7] Adding unlock / lock command + UI changes --- .../Admin/Controllers/CampaignController.cs | 17 ++++++++- .../Campaigns/CampaignDetailQueryHandler.cs | 1 + .../Campaigns/LockUnlockCampaignCommand.cs | 9 +++++ .../LockUnlockCampaignCommandHandler.cs | 37 +++++++++++++++++++ .../Areas/Admin/Models/CampaignDetailModel.cs | 2 + .../Areas/Admin/Views/Campaign/Details.cshtml | 31 +++++++++++++++- .../Controllers/CampaignController.cs | 16 ++++---- .../Web-App/AllReady/wwwroot/css/mainPage.css | 3 ++ .../Web-App/AllReady/wwwroot/css/site.css | 10 ++++- 9 files changed, 115 insertions(+), 11 deletions(-) create mode 100644 AllReadyApp/Web-App/AllReady/Areas/Admin/Features/Campaigns/LockUnlockCampaignCommand.cs create mode 100644 AllReadyApp/Web-App/AllReady/Areas/Admin/Features/Campaigns/LockUnlockCampaignCommandHandler.cs diff --git a/AllReadyApp/Web-App/AllReady/Areas/Admin/Controllers/CampaignController.cs b/AllReadyApp/Web-App/AllReady/Areas/Admin/Controllers/CampaignController.cs index e67de4f45..0ef420306 100644 --- a/AllReadyApp/Web-App/AllReady/Areas/Admin/Controllers/CampaignController.cs +++ b/AllReadyApp/Web-App/AllReady/Areas/Admin/Controllers/CampaignController.cs @@ -147,9 +147,24 @@ public IActionResult DeleteConfirmed(int id) { return HttpUnauthorized(); } + _bus.Send(new DeleteCampaignCommand { CampaignId = id }); return RedirectToAction("Index", new { area = "Admin" }); } + // POST: Campaign/Delete/5 + [HttpPost] + [ValidateAntiForgeryToken] + public IActionResult LockUnlock(int id) + { + if (!User.IsUserType(UserType.SiteAdmin)) + { + return HttpUnauthorized(); + } + + _bus.Send(new LockUnlockCampaignCommand { CampaignId = id }); + return RedirectToAction("Details", new { area = "Admin", id = id }); + } + } -} +} \ No newline at end of file diff --git a/AllReadyApp/Web-App/AllReady/Areas/Admin/Features/Campaigns/CampaignDetailQueryHandler.cs b/AllReadyApp/Web-App/AllReady/Areas/Admin/Features/Campaigns/CampaignDetailQueryHandler.cs index 8e0a42a8d..5f5332c9d 100644 --- a/AllReadyApp/Web-App/AllReady/Areas/Admin/Features/Campaigns/CampaignDetailQueryHandler.cs +++ b/AllReadyApp/Web-App/AllReady/Areas/Admin/Features/Campaigns/CampaignDetailQueryHandler.cs @@ -43,6 +43,7 @@ public CampaignDetailModel Handle(CampaignDetailQuery message) EndDate = campaign.EndDateTime, CampaignImpact = campaign.CampaignImpact, Location = campaign.Location.ToModel(), + Locked = campaign.Locked, Activities = campaign.Activities.Select(a => new ActivitySummaryModel { Id = a.Id, diff --git a/AllReadyApp/Web-App/AllReady/Areas/Admin/Features/Campaigns/LockUnlockCampaignCommand.cs b/AllReadyApp/Web-App/AllReady/Areas/Admin/Features/Campaigns/LockUnlockCampaignCommand.cs new file mode 100644 index 000000000..1346ac25e --- /dev/null +++ b/AllReadyApp/Web-App/AllReady/Areas/Admin/Features/Campaigns/LockUnlockCampaignCommand.cs @@ -0,0 +1,9 @@ +using MediatR; + +namespace AllReady.Areas.Admin.Features.Campaigns +{ + public class LockUnlockCampaignCommand : IRequest + { + public int CampaignId {get; set;} + } +} diff --git a/AllReadyApp/Web-App/AllReady/Areas/Admin/Features/Campaigns/LockUnlockCampaignCommandHandler.cs b/AllReadyApp/Web-App/AllReady/Areas/Admin/Features/Campaigns/LockUnlockCampaignCommandHandler.cs new file mode 100644 index 000000000..914f791aa --- /dev/null +++ b/AllReadyApp/Web-App/AllReady/Areas/Admin/Features/Campaigns/LockUnlockCampaignCommandHandler.cs @@ -0,0 +1,37 @@ +using AllReady.Models; +using MediatR; +using System.Linq; + +namespace AllReady.Areas.Admin.Features.Campaigns +{ + public class LockUnlockCampaignCommandHandler : RequestHandler + { + private AllReadyContext _context; + + public LockUnlockCampaignCommandHandler(AllReadyContext context) + { + _context = context; + + } + protected override void HandleCore(LockUnlockCampaignCommand message) + { + var campaign = + _context.Campaigns.SingleOrDefault(c => c.Id == message.CampaignId); + + if (campaign != null) + { + if (campaign.Locked) + { + campaign.Locked = false; + } + else + { + campaign.Locked = true; + } + + _context.Update(campaign); + _context.SaveChanges(); + } + } + } +} \ No newline at end of file diff --git a/AllReadyApp/Web-App/AllReady/Areas/Admin/Models/CampaignDetailModel.cs b/AllReadyApp/Web-App/AllReady/Areas/Admin/Models/CampaignDetailModel.cs index 17662cbe4..7c48b0bbf 100644 --- a/AllReadyApp/Web-App/AllReady/Areas/Admin/Models/CampaignDetailModel.cs +++ b/AllReadyApp/Web-App/AllReady/Areas/Admin/Models/CampaignDetailModel.cs @@ -53,5 +53,7 @@ public class CampaignDetailModel: IPrimaryContactModel [EmailAddress] public string PrimaryContactEmail { get; set; } + public bool Locked { get; set; } + } } diff --git a/AllReadyApp/Web-App/AllReady/Areas/Admin/Views/Campaign/Details.cshtml b/AllReadyApp/Web-App/AllReady/Areas/Admin/Views/Campaign/Details.cshtml index 5cea69c06..dd03b6982 100644 --- a/AllReadyApp/Web-App/AllReady/Areas/Admin/Views/Campaign/Details.cshtml +++ b/AllReadyApp/Web-App/AllReady/Areas/Admin/Views/Campaign/Details.cshtml @@ -1,4 +1,6 @@ @model AllReady.Areas.Admin.Models.CampaignDetailModel +@using AllReady.Security; + @{ ViewBag.Title = Model.Name; }
@@ -11,7 +13,31 @@
-

@Model.Name

+
+

+ @Model.Name +

+ + + @if (User.IsUserType(UserType.SiteAdmin)) + { +
+ + @if (Model.Locked) + { + + } + else + { + + } +
+ } + else if (Model.Locked) + { + This campaign is locked + } +
@@ -24,8 +50,9 @@
+
- +
diff --git a/AllReadyApp/Web-App/AllReady/Controllers/CampaignController.cs b/AllReadyApp/Web-App/AllReady/Controllers/CampaignController.cs index 51be30579..d4724646d 100644 --- a/AllReadyApp/Web-App/AllReady/Controllers/CampaignController.cs +++ b/AllReadyApp/Web-App/AllReady/Controllers/CampaignController.cs @@ -29,8 +29,8 @@ public IActionResult Details(int id) { var campaign = _dataAccess.GetCampaign(id); - if (campaign == null || campaign.Locked == false) - HttpNotFound(); + if (campaign == null || campaign.Locked) + return HttpNotFound(); return View("Details", new CampaignViewModel(campaign)); } @@ -42,7 +42,7 @@ public IActionResult LocationMap(int id) var campaign = _dataAccess.GetCampaign(id); if (campaign == null) - HttpNotFound(); + return HttpNotFound(); return View("Map", new CampaignViewModel(campaign)); } @@ -58,14 +58,16 @@ public IEnumerable Get() // GET api/values/5 [HttpGet("{id}")] - public CampaignViewModel Get(int id) + public ActionResult Get(int id) { var campaign = _dataAccess.GetCampaign(id); - if (campaign == null || campaign.Locked == false) - HttpNotFound(); + if (campaign == null || campaign.Locked) + { + return HttpNotFound(); + } - return campaign.ToViewModel(); + return Json(campaign.ToViewModel()); } } } diff --git a/AllReadyApp/Web-App/AllReady/wwwroot/css/mainPage.css b/AllReadyApp/Web-App/AllReady/wwwroot/css/mainPage.css index 70cbe5675..cc7143788 100644 --- a/AllReadyApp/Web-App/AllReady/wwwroot/css/mainPage.css +++ b/AllReadyApp/Web-App/AllReady/wwwroot/css/mainPage.css @@ -86,3 +86,6 @@ input.main-search { } /* End main page CSS */ +.inline-form { + display: inline-block; +} diff --git a/AllReadyApp/Web-App/AllReady/wwwroot/css/site.css b/AllReadyApp/Web-App/AllReady/wwwroot/css/site.css index 893991968..14707df00 100644 --- a/AllReadyApp/Web-App/AllReady/wwwroot/css/site.css +++ b/AllReadyApp/Web-App/AllReady/wwwroot/css/site.css @@ -312,4 +312,12 @@ Navigation .thermometer-bulb-outline{ stroke: black; stroke-width: 3; -} \ No newline at end of file +} + +.inline-form { + display: inline-block; +} + +h2.inline-form { + padding-right: 10px; +} \ No newline at end of file From 29dfb6ca1aeef7bdfec3ff6d310fe96efcb0b7fb Mon Sep 17 00:00:00 2001 From: Steve Gordon Date: Tue, 26 Jan 2016 19:11:48 +0000 Subject: [PATCH 3/7] Adding tests --- .../Campaigns/CampaignsHandlerTestHelper.cs | 2 + .../EditCampaignCommandHandlerTests.cs | 4 +- .../LockUnlockCampaignCommandHandlerTests.cs | 44 +++++++++++++++++++ 3 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 AllReadyApp/Web-App/AllReady.UnitTest/Areas/Admin/Features/Campaigns/LockUnlockCampaignCommandHandlerTests.cs diff --git a/AllReadyApp/Web-App/AllReady.UnitTest/Areas/Admin/Features/Campaigns/CampaignsHandlerTestHelper.cs b/AllReadyApp/Web-App/AllReady.UnitTest/Areas/Admin/Features/Campaigns/CampaignsHandlerTestHelper.cs index 00e07f7c3..ddf345638 100644 --- a/AllReadyApp/Web-App/AllReady.UnitTest/Areas/Admin/Features/Campaigns/CampaignsHandlerTestHelper.cs +++ b/AllReadyApp/Web-App/AllReady.UnitTest/Areas/Admin/Features/Campaigns/CampaignsHandlerTestHelper.cs @@ -13,6 +13,8 @@ public static void LoadCampaignssHandlerTestData(AllReadyContext context) // Campaigns context.Campaigns.Add(new Campaign { Name = "Campaign 1", ManagingOrganizationId = 1 }); context.Campaigns.Add(new Campaign { Name = "Campaign 2", ManagingOrganizationId = 1 }); + context.Campaigns.Add(new Campaign { Name = "Locked Campaign", ManagingOrganizationId = 1, Locked = true }); + context.Campaigns.Add(new Campaign { Name = "Unlocked Campaign", ManagingOrganizationId = 1, Locked = false }); context.SaveChanges(); } diff --git a/AllReadyApp/Web-App/AllReady.UnitTest/Areas/Admin/Features/Campaigns/EditCampaignCommandHandlerTests.cs b/AllReadyApp/Web-App/AllReady.UnitTest/Areas/Admin/Features/Campaigns/EditCampaignCommandHandlerTests.cs index c9bc01b72..36e40809f 100644 --- a/AllReadyApp/Web-App/AllReady.UnitTest/Areas/Admin/Features/Campaigns/EditCampaignCommandHandlerTests.cs +++ b/AllReadyApp/Web-App/AllReady.UnitTest/Areas/Admin/Features/Campaigns/EditCampaignCommandHandlerTests.cs @@ -19,7 +19,7 @@ public void AddNewCampaign() var result = handler.Handle(new EditCampaignCommand { Campaign = newCampaign }); // Assert - Assert.Equal(3, Context.Campaigns.Count()); + Assert.Equal(5, Context.Campaigns.Count()); Assert.True(result > 0); } @@ -56,7 +56,7 @@ public void UpdatingExistingCampaignUpdatesAllCoreProperties() var savedCampaign = Context.Campaigns.SingleOrDefault(s => s.Id == 2); // Assert - Assert.Equal(2, Context.Campaigns.Count()); + Assert.Equal(4, Context.Campaigns.Count()); Assert.Equal(2, result); Assert.Equal(name, savedCampaign.Name); diff --git a/AllReadyApp/Web-App/AllReady.UnitTest/Areas/Admin/Features/Campaigns/LockUnlockCampaignCommandHandlerTests.cs b/AllReadyApp/Web-App/AllReady.UnitTest/Areas/Admin/Features/Campaigns/LockUnlockCampaignCommandHandlerTests.cs new file mode 100644 index 000000000..6ea12b895 --- /dev/null +++ b/AllReadyApp/Web-App/AllReady.UnitTest/Areas/Admin/Features/Campaigns/LockUnlockCampaignCommandHandlerTests.cs @@ -0,0 +1,44 @@ +using AllReady.Areas.Admin.Features.Campaigns; +using System.Linq; +using Xunit; + +namespace AllReady.UnitTest.Areas.Admin.Features.Campaigns +{ + public class LockUnlockCampaignCommandHandlerTests : InMemoryContextTest + { + [Fact] + public void LockedCampaignIsUnlocked() + { + // Arrange + var handler = new LockUnlockCampaignCommandHandler(Context); + + // Act + var campaign = Context.Campaigns.FirstOrDefault(c => c.Name == "Locked Campaign"); + handler.Handle(new LockUnlockCampaignCommand { CampaignId = campaign.Id }); + var result = Context.Campaigns.FirstOrDefault(c => c.Name == "Locked Campaign"); + + // Assert + Assert.False(result.Locked); // Campaign should now be unlocked + } + + [Fact] + public void UnlockedCampaignIsUnlocked() + { + // Arrange + var handler = new LockUnlockCampaignCommandHandler(Context); + + // Act + var campaign = Context.Campaigns.FirstOrDefault(c => c.Name == "Unlocked Campaign"); + handler.Handle(new LockUnlockCampaignCommand { CampaignId = campaign.Id }); + var result = Context.Campaigns.FirstOrDefault(c => c.Name == "Unlocked Campaign"); + + // Assert + Assert.True(result.Locked); // Campaign should now be locked + } + + protected override void LoadTestData() + { + CampaignsHandlerTestHelper.LoadCampaignssHandlerTestData(Context); + } + } +} \ No newline at end of file From cb803ba409f1ff0a27ae0c1f7584fc3d5eee2c75 Mon Sep 17 00:00:00 2001 From: Steve Gordon Date: Tue, 26 Jan 2016 19:17:10 +0000 Subject: [PATCH 4/7] Cleaning up un-used CampaignStatus --- .../Web-App/AllReady/Models/CampaignStatus.cs | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 AllReadyApp/Web-App/AllReady/Models/CampaignStatus.cs diff --git a/AllReadyApp/Web-App/AllReady/Models/CampaignStatus.cs b/AllReadyApp/Web-App/AllReady/Models/CampaignStatus.cs deleted file mode 100644 index d6c03734d..000000000 --- a/AllReadyApp/Web-App/AllReady/Models/CampaignStatus.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace AllReady.Models -{ - /// - /// Describes the overall status of a campaign - /// - public enum CampaignStatus - { - Draft = 0, - Live= 1, - Locked = 2 - } -} \ No newline at end of file From 5c97feb198c516d1ccc03137f6bf18d5ffe567f1 Mon Sep 17 00:00:00 2001 From: Steve Gordon Date: Wed, 27 Jan 2016 06:27:10 +0000 Subject: [PATCH 5/7] Updating homepage campaign list to filter out locked campaigns --- AllReadyApp/Web-App/AllReady/Controllers/HomeController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AllReadyApp/Web-App/AllReady/Controllers/HomeController.cs b/AllReadyApp/Web-App/AllReady/Controllers/HomeController.cs index f20ee60a7..450e66e32 100644 --- a/AllReadyApp/Web-App/AllReady/Controllers/HomeController.cs +++ b/AllReadyApp/Web-App/AllReady/Controllers/HomeController.cs @@ -17,7 +17,7 @@ public HomeController(IAllReadyDataAccess dataAccess) public IActionResult Index() { - return View(_dataAccess.Campaigns.Where(c => c.EndDateTime.UtcDateTime.Date > DateTime.UtcNow.Date).ToViewModel().OrderBy(vm => vm.EndDate).ToList()); + return View(_dataAccess.Campaigns.Where(c => c.EndDateTime.UtcDateTime.Date > DateTime.UtcNow.Date && c.Locked == false).ToViewModel().OrderBy(vm => vm.EndDate).ToList()); } public IActionResult About() From 8cd0c56c346d0f3890cedbae35a09d449841fae9 Mon Sep 17 00:00:00 2001 From: Steve Gordon Date: Wed, 10 Feb 2016 06:55:25 +0000 Subject: [PATCH 6/7] PR code review updates --- .../Campaigns/LockUnlockCampaignCommandHandlerTests.cs | 2 +- .../Areas/Admin/Controllers/CampaignController.cs | 2 -- .../Campaigns/LockUnlockCampaignCommandHandler.cs | 9 +-------- .../AllReady/Areas/Admin/Views/Campaign/Details.cshtml | 2 +- .../Web-App/AllReady/Controllers/ActivityController.cs | 4 ++-- .../Web-App/AllReady/Controllers/CampaignController.cs | 4 ++-- .../Web-App/AllReady/Controllers/HomeController.cs | 2 +- .../DataAccess/AllReadyDataAccessEF7.Activity.cs | 6 ++++-- 8 files changed, 12 insertions(+), 19 deletions(-) diff --git a/AllReadyApp/Web-App/AllReady.UnitTest/Areas/Admin/Features/Campaigns/LockUnlockCampaignCommandHandlerTests.cs b/AllReadyApp/Web-App/AllReady.UnitTest/Areas/Admin/Features/Campaigns/LockUnlockCampaignCommandHandlerTests.cs index 6ea12b895..02532d7c5 100644 --- a/AllReadyApp/Web-App/AllReady.UnitTest/Areas/Admin/Features/Campaigns/LockUnlockCampaignCommandHandlerTests.cs +++ b/AllReadyApp/Web-App/AllReady.UnitTest/Areas/Admin/Features/Campaigns/LockUnlockCampaignCommandHandlerTests.cs @@ -22,7 +22,7 @@ public void LockedCampaignIsUnlocked() } [Fact] - public void UnlockedCampaignIsUnlocked() + public void UnlockedCampaignIsLocked() { // Arrange var handler = new LockUnlockCampaignCommandHandler(Context); diff --git a/AllReadyApp/Web-App/AllReady/Areas/Admin/Controllers/CampaignController.cs b/AllReadyApp/Web-App/AllReady/Areas/Admin/Controllers/CampaignController.cs index 0ef420306..06712da1b 100644 --- a/AllReadyApp/Web-App/AllReady/Areas/Admin/Controllers/CampaignController.cs +++ b/AllReadyApp/Web-App/AllReady/Areas/Admin/Controllers/CampaignController.cs @@ -152,7 +152,6 @@ public IActionResult DeleteConfirmed(int id) return RedirectToAction("Index", new { area = "Admin" }); } - // POST: Campaign/Delete/5 [HttpPost] [ValidateAntiForgeryToken] public IActionResult LockUnlock(int id) @@ -165,6 +164,5 @@ public IActionResult LockUnlock(int id) _bus.Send(new LockUnlockCampaignCommand { CampaignId = id }); return RedirectToAction("Details", new { area = "Admin", id = id }); } - } } \ No newline at end of file diff --git a/AllReadyApp/Web-App/AllReady/Areas/Admin/Features/Campaigns/LockUnlockCampaignCommandHandler.cs b/AllReadyApp/Web-App/AllReady/Areas/Admin/Features/Campaigns/LockUnlockCampaignCommandHandler.cs index 914f791aa..b528a6079 100644 --- a/AllReadyApp/Web-App/AllReady/Areas/Admin/Features/Campaigns/LockUnlockCampaignCommandHandler.cs +++ b/AllReadyApp/Web-App/AllReady/Areas/Admin/Features/Campaigns/LockUnlockCampaignCommandHandler.cs @@ -20,14 +20,7 @@ protected override void HandleCore(LockUnlockCampaignCommand message) if (campaign != null) { - if (campaign.Locked) - { - campaign.Locked = false; - } - else - { - campaign.Locked = true; - } + campaign.Locked = !campaign.Locked; _context.Update(campaign); _context.SaveChanges(); diff --git a/AllReadyApp/Web-App/AllReady/Areas/Admin/Views/Campaign/Details.cshtml b/AllReadyApp/Web-App/AllReady/Areas/Admin/Views/Campaign/Details.cshtml index dd03b6982..d876ad1ac 100644 --- a/AllReadyApp/Web-App/AllReady/Areas/Admin/Views/Campaign/Details.cshtml +++ b/AllReadyApp/Web-App/AllReady/Areas/Admin/Views/Campaign/Details.cshtml @@ -35,7 +35,7 @@ } else if (Model.Locked) { - This campaign is locked + This campaign has been locked by a site administrator. Locked campaigns are not visible to the public or to volunteers. }
diff --git a/AllReadyApp/Web-App/AllReady/Controllers/ActivityController.cs b/AllReadyApp/Web-App/AllReady/Controllers/ActivityController.cs index 6d9e845fb..abdca360d 100644 --- a/AllReadyApp/Web-App/AllReady/Controllers/ActivityController.cs +++ b/AllReadyApp/Web-App/AllReady/Controllers/ActivityController.cs @@ -30,7 +30,7 @@ public ActivityController(IAllReadyDataAccess allReadyDataAccess, IMediator bus) [Authorize] public IActionResult GetMyActivities() { - var myActivities = _allReadyDataAccess.GetActivitySignups(User.GetUserId()); + var myActivities = _allReadyDataAccess.GetActivitySignups(User.GetUserId()).Where(a => !a.Activity.Campaign.Locked); var signedUp = myActivities.Select(a => new ActivityViewModel(a.Activity)); var viewModel = new MyActivitiesResultsScreenViewModel("My Activities", signedUp); return View("MyActivities", viewModel); @@ -85,7 +85,7 @@ public IActionResult ShowActivity(int id) { var activity = _allReadyDataAccess.GetActivity(id); - if (activity == null) + if (activity == null || activity.Campaign.Locked) { return HttpNotFound(); } diff --git a/AllReadyApp/Web-App/AllReady/Controllers/CampaignController.cs b/AllReadyApp/Web-App/AllReady/Controllers/CampaignController.cs index d4724646d..08c3bac0f 100644 --- a/AllReadyApp/Web-App/AllReady/Controllers/CampaignController.cs +++ b/AllReadyApp/Web-App/AllReady/Controllers/CampaignController.cs @@ -20,7 +20,7 @@ public CampaignController(IAllReadyDataAccess dataAccess) [Route("~/[controller]")] public IActionResult Index() { - return View(_dataAccess.Campaigns.Where(c => c.Locked == false).ToViewModel().ToList()); + return View(_dataAccess.Campaigns.Where(c => !c.Locked).ToViewModel().ToList()); } [HttpGet] @@ -52,7 +52,7 @@ public IActionResult LocationMap(int id) public IEnumerable Get() { return _dataAccess.Campaigns - .Where(c => c.Locked == false) + .Where(c => !c.Locked) .Select(x => new CampaignViewModel(x)); } diff --git a/AllReadyApp/Web-App/AllReady/Controllers/HomeController.cs b/AllReadyApp/Web-App/AllReady/Controllers/HomeController.cs index 450e66e32..57a1ab056 100644 --- a/AllReadyApp/Web-App/AllReady/Controllers/HomeController.cs +++ b/AllReadyApp/Web-App/AllReady/Controllers/HomeController.cs @@ -17,7 +17,7 @@ public HomeController(IAllReadyDataAccess dataAccess) public IActionResult Index() { - return View(_dataAccess.Campaigns.Where(c => c.EndDateTime.UtcDateTime.Date > DateTime.UtcNow.Date && c.Locked == false).ToViewModel().OrderBy(vm => vm.EndDate).ToList()); + return View(_dataAccess.Campaigns.Where(c => c.EndDateTime.UtcDateTime.Date > DateTime.UtcNow.Date && !c.Locked).ToViewModel().OrderBy(vm => vm.EndDate).ToList()); } public IActionResult About() diff --git a/AllReadyApp/Web-App/AllReady/DataAccess/AllReadyDataAccessEF7.Activity.cs b/AllReadyApp/Web-App/AllReady/DataAccess/AllReadyDataAccessEF7.Activity.cs index c3b64aa57..afb77ef1e 100644 --- a/AllReadyApp/Web-App/AllReady/DataAccess/AllReadyDataAccessEF7.Activity.cs +++ b/AllReadyApp/Web-App/AllReady/DataAccess/AllReadyDataAccessEF7.Activity.cs @@ -20,6 +20,7 @@ IEnumerable IAllReadyDataAccess.Activities .Include(a => a.Tasks) .Include(a => a.RequiredSkills) .Include(a => a.UsersSignedUp) + .Where(a => !a.Campaign.Locked) .OrderBy(a => a.EndDateTime) .ToList(); } @@ -90,10 +91,11 @@ IEnumerable IAllReadyDataAccess.GetTasksAssignedToUser(int activityI var unfilteredTasks = _dbContext.TaskSignups .Include(ts => ts.Task) .ThenInclude(t => t.Activity) - .Include(ts => ts.User) + .ThenInclude(t => t.Campaign) + .Include(ts => ts.User) .ToList(); - var finalTasks = unfilteredTasks.Where(ts => ts.Task.Activity.Id == activityId && ts.User.Id == userId).ToList(); + var finalTasks = unfilteredTasks.Where(ts => ts.Task.Activity.Id == activityId && ts.User.Id == userId && !ts.Task.Activity.Campaign.Locked).ToList(); return finalTasks; } From d42179856473004035cfcdeeae26913eaf09ff1d Mon Sep 17 00:00:00 2001 From: Steve Gordon Date: Sat, 13 Feb 2016 11:18:27 +0000 Subject: [PATCH 7/7] Updating data access per PR feedback --- .../Web-App/AllReady/Controllers/ActivityApiController.cs | 4 +++- .../AllReady/DataAccess/AllReadyDataAccessEF7.Activity.cs | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/AllReadyApp/Web-App/AllReady/Controllers/ActivityApiController.cs b/AllReadyApp/Web-App/AllReady/Controllers/ActivityApiController.cs index 6c0543959..4da08a18e 100644 --- a/AllReadyApp/Web-App/AllReady/Controllers/ActivityApiController.cs +++ b/AllReadyApp/Web-App/AllReady/Controllers/ActivityApiController.cs @@ -35,7 +35,9 @@ public ActivityApiController(IAllReadyDataAccess allReadyDataAccess, IMediator b [HttpGet] public IEnumerable Get() { - return _allReadyDataAccess.Activities.Select(a => new ActivityViewModel(a)); + return _allReadyDataAccess.Activities + .Where(c => !c.Campaign.Locked) + .Select(a => new ActivityViewModel(a)); } // GET api/values/5 diff --git a/AllReadyApp/Web-App/AllReady/DataAccess/AllReadyDataAccessEF7.Activity.cs b/AllReadyApp/Web-App/AllReady/DataAccess/AllReadyDataAccessEF7.Activity.cs index afb77ef1e..520d0d733 100644 --- a/AllReadyApp/Web-App/AllReady/DataAccess/AllReadyDataAccessEF7.Activity.cs +++ b/AllReadyApp/Web-App/AllReady/DataAccess/AllReadyDataAccessEF7.Activity.cs @@ -16,11 +16,11 @@ IEnumerable IAllReadyDataAccess.Activities return _dbContext.Activities .Include(a => a.Location) .Include(a => a.Location.PostalCode) + .Include(a => a.Campaign) .Include(a => a.Campaign.ManagingOrganization) .Include(a => a.Tasks) .Include(a => a.RequiredSkills) .Include(a => a.UsersSignedUp) - .Where(a => !a.Campaign.Locked) .OrderBy(a => a.EndDateTime) .ToList(); }