Merge branch 'feature/Attachments' into develop

# Conflicts:
#	Step/Controllers/WebApi/MaintenanceController.cs
This commit is contained in:
Lucio Maranta
2018-06-19 17:12:44 +02:00
13 changed files with 256 additions and 22 deletions
@@ -285,6 +285,55 @@ namespace Step.Database.Controllers
dbCtx.SaveChanges();
}
public List<MaintenanceFileModel> FindAttachmentByMaintenance(int maintenanceId)
{
return dbCtx
.MaintenanceFiles
.Where(x => x.MaintenanceId == maintenanceId)
.ToList();
}
public MaintenanceFileModel FindAttachmentById(int attachmentId)
{
return dbCtx
.MaintenanceFiles
.Where(x => x.AttachmentId == attachmentId)
.FirstOrDefault();
}
public MaintenanceFileModel AddAttachment(string fileName, string localFileName ,int maintenanceId)
{
MaintenanceFileModel file = new MaintenanceFileModel()
{
FileName = fileName,
LocalFileName = localFileName,
MaintenanceId = maintenanceId
};
dbCtx.MaintenanceFiles.Add(file);
dbCtx.SaveChanges();
return file;
}
public void DeleteAttachment(int attachmentId)
{
MaintenanceFileModel file = dbCtx.MaintenanceFiles.Where(x => x.AttachmentId == attachmentId).FirstOrDefault();
if (file != null)
{
dbCtx.MaintenanceFiles.Remove(file);
dbCtx.SaveChanges();
}
}
public void DeleteAttachment(MaintenanceFileModel attachment)
{
dbCtx.MaintenanceFiles.Remove(attachment);
dbCtx.SaveChanges();
}
#endregion
}
}
+1
View File
@@ -27,6 +27,7 @@ namespace Step.Database
public DbSet<MaintenanceModel> Maintenances { get; set; }
public DbSet<PerformedMaintenanceModel> PerformedMaintenances { get; set; }
public DbSet<MaintenanceNoteModel> MaintenancesNotes { get; set; }
public DbSet<MaintenanceFileModel> MaintenanceFiles { get; set; }
// Create migration string
public static string CONNECTION_STRING = "Server = " + "localhost" + "; Database=" + DATABASE_NAME +";Uid="+ DATABASE_USER +";Pwd="+ DATABASE_PWD +";";
@@ -13,7 +13,7 @@ namespace Step.Database.Migrations
string IMigrationMetadata.Id
{
get { return "201806141227365_InitMigration"; }
get { return "201806191402402_InitMigration"; }
}
string IMigrationMetadata.Source
@@ -71,6 +71,19 @@ namespace Step.Database.Migrations
})
.PrimaryKey(t => t.id);
CreateTable(
"dbo.maintenance_file",
c => new
{
id = c.Int(nullable: false, identity: true),
file_name = c.String(unicode: false),
local_file_name = c.String(unicode: false),
maintenance_id = c.Int(nullable: false),
})
.PrimaryKey(t => t.id)
.ForeignKey("dbo.maintenance", t => t.maintenance_id, cascadeDelete: true)
.Index(t => t.maintenance_id);
CreateTable(
"dbo.maintenance",
c => new
@@ -98,11 +111,11 @@ namespace Step.Database.Migrations
id = c.Int(nullable: false, identity: true),
message = c.String(unicode: false),
user_id = c.Int(nullable: false),
maintenance_id = c.Int(),
maintenance_id = c.Int(nullable: false),
timestamp = c.DateTime(nullable: false, precision: 0),
})
.PrimaryKey(t => t.id)
.ForeignKey("dbo.maintenance", t => t.maintenance_id)
.ForeignKey("dbo.maintenance", t => t.maintenance_id, cascadeDelete: true)
.ForeignKey("dbo.user", t => t.user_id, cascadeDelete: true)
.Index(t => t.user_id)
.Index(t => t.maintenance_id);
@@ -140,6 +153,7 @@ namespace Step.Database.Migrations
DropForeignKey("dbo.performed_maintenance", "maintenance", "dbo.maintenance");
DropForeignKey("dbo.maintenance_note", "user_id", "dbo.user");
DropForeignKey("dbo.maintenance_note", "maintenance_id", "dbo.maintenance");
DropForeignKey("dbo.maintenance_file", "maintenance_id", "dbo.maintenance");
DropForeignKey("dbo.maintenance", "user_id", "dbo.user");
DropForeignKey("dbo.machine_user", "user_id", "dbo.user");
DropForeignKey("dbo.machine_user", "role_id", "dbo.role");
@@ -149,12 +163,14 @@ namespace Step.Database.Migrations
DropIndex("dbo.maintenance_note", new[] { "maintenance_id" });
DropIndex("dbo.maintenance_note", new[] { "user_id" });
DropIndex("dbo.maintenance", new[] { "user_id" });
DropIndex("dbo.maintenance_file", new[] { "maintenance_id" });
DropIndex("dbo.machine_user", new[] { "role_id" });
DropIndex("dbo.machine_user", "unique_machine_user");
DropTable("dbo.session");
DropTable("dbo.performed_maintenance");
DropTable("dbo.maintenance_note");
DropTable("dbo.maintenance");
DropTable("dbo.maintenance_file");
DropTable("dbo.user");
DropTable("dbo.role");
DropTable("dbo.machine_user");
+5 -5
View File
@@ -77,9 +77,9 @@
<Compile Include="Controllers\UsersController.cs" />
<Compile Include="Controllers\MachinesUsersController.cs" />
<Compile Include="DatabaseContext.cs" />
<Compile Include="Migrations\201806141227365_InitMigration.cs" />
<Compile Include="Migrations\201806141227365_InitMigration.Designer.cs">
<DependentUpon>201806141227365_InitMigration.cs</DependentUpon>
<Compile Include="Migrations\201806191402402_InitMigration.cs" />
<Compile Include="Migrations\201806191402402_InitMigration.Designer.cs">
<DependentUpon>201806191402402_InitMigration.cs</DependentUpon>
</Compile>
<Compile Include="Migrations\Configuration.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
@@ -115,8 +115,8 @@
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Migrations\201806141227365_InitMigration.resx">
<DependentUpon>201806141227365_InitMigration.cs</DependentUpon>
<EmbeddedResource Include="Migrations\201806191402402_InitMigration.resx">
<DependentUpon>201806191402402_InitMigration.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />