Skip to content

Commit

Permalink
Extend user table and add photo table
Browse files Browse the repository at this point in the history
  • Loading branch information
marvac committed Jan 13, 2019
1 parent 6d85a66 commit aacb783
Show file tree
Hide file tree
Showing 6 changed files with 341 additions and 1 deletion.
1 change: 1 addition & 0 deletions Data/DataContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public class DataContext : DbContext
{
public DbSet<Value> Values { get; set; }
public DbSet<User> Users { get; set; }
public DbSet<Photo> Photos { get; set; }

public DataContext(DbContextOptions<DataContext> options) : base(options)
{
Expand Down
107 changes: 107 additions & 0 deletions Migrations/20190113212812_ExtendUserClass.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

141 changes: 141 additions & 0 deletions Migrations/20190113212812_ExtendUserClass.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
using System;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;

namespace Friendster.Migrations
{
public partial class ExtendUserClass : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<DateTime>(
name: "BirthDate",
table: "Users",
nullable: false,
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));

migrationBuilder.AddColumn<string>(
name: "City",
table: "Users",
nullable: true);

migrationBuilder.AddColumn<string>(
name: "Country",
table: "Users",
nullable: true);

migrationBuilder.AddColumn<DateTime>(
name: "DateCreated",
table: "Users",
nullable: false,
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));

migrationBuilder.AddColumn<int>(
name: "Gender",
table: "Users",
nullable: false,
defaultValue: 0);

migrationBuilder.AddColumn<string>(
name: "Interests",
table: "Users",
nullable: true);

migrationBuilder.AddColumn<string>(
name: "Introduction",
table: "Users",
nullable: true);

migrationBuilder.AddColumn<string>(
name: "KnownAs",
table: "Users",
nullable: true);

migrationBuilder.AddColumn<DateTime>(
name: "LastActive",
table: "Users",
nullable: false,
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));

migrationBuilder.AddColumn<int>(
name: "LookingFor",
table: "Users",
nullable: false,
defaultValue: 0);

migrationBuilder.CreateTable(
name: "Photos",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
Url = table.Column<string>(nullable: true),
Description = table.Column<string>(nullable: true),
DateAdded = table.Column<DateTime>(nullable: false),
IsMain = table.Column<bool>(nullable: false),
UserId = table.Column<int>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Photos", x => x.Id);
table.ForeignKey(
name: "FK_Photos_Users_UserId",
column: x => x.UserId,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});

migrationBuilder.CreateIndex(
name: "IX_Photos_UserId",
table: "Photos",
column: "UserId");
}

protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Photos");

migrationBuilder.DropColumn(
name: "BirthDate",
table: "Users");

migrationBuilder.DropColumn(
name: "City",
table: "Users");

migrationBuilder.DropColumn(
name: "Country",
table: "Users");

migrationBuilder.DropColumn(
name: "DateCreated",
table: "Users");

migrationBuilder.DropColumn(
name: "Gender",
table: "Users");

migrationBuilder.DropColumn(
name: "Interests",
table: "Users");

migrationBuilder.DropColumn(
name: "Introduction",
table: "Users");

migrationBuilder.DropColumn(
name: "KnownAs",
table: "Users");

migrationBuilder.DropColumn(
name: "LastActive",
table: "Users");

migrationBuilder.DropColumn(
name: "LookingFor",
table: "Users");
}
}
}
51 changes: 51 additions & 0 deletions Migrations/DataContextModelSnapshot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,55 @@ protected override void BuildModel(ModelBuilder modelBuilder)
.HasAnnotation("Relational:MaxIdentifierLength", 128)
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);

modelBuilder.Entity("Friendster.Models.Photo", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);

b.Property<DateTime>("DateAdded");

b.Property<string>("Description");

b.Property<bool>("IsMain");

b.Property<string>("Url");

b.Property<int>("UserId");

b.HasKey("Id");

b.HasIndex("UserId");

b.ToTable("Photos");
});

modelBuilder.Entity("Friendster.Models.User", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);

b.Property<DateTime>("BirthDate");

b.Property<string>("City");

b.Property<string>("Country");

b.Property<DateTime>("DateCreated");

b.Property<int>("Gender");

b.Property<string>("Interests");

b.Property<string>("Introduction");

b.Property<string>("KnownAs");

b.Property<DateTime>("LastActive");

b.Property<int>("LookingFor");

b.Property<byte[]>("PasswordHash");

b.Property<byte[]>("PasswordSalt");
Expand All @@ -48,6 +91,14 @@ protected override void BuildModel(ModelBuilder modelBuilder)

b.ToTable("Values");
});

modelBuilder.Entity("Friendster.Models.Photo", b =>
{
b.HasOne("Friendster.Models.User", "User")
.WithMany("Photos")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade);
});
#pragma warning restore 612, 618
}
}
Expand Down
19 changes: 19 additions & 0 deletions Models/Photo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Friendster.Models
{
public class Photo
{
public int Id { get; set; }
public string Url { get; set; }
public string Description { get; set; }
public DateTime DateAdded { get; set; }
public bool IsMain { get; set; }

public User User { get; set; }
public int UserId { get; set; }
}
}
23 changes: 22 additions & 1 deletion Models/User.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,31 @@
namespace Friendster.Models
using System;
using System.Collections.Generic;

namespace Friendster.Models
{
public class User
{
public int Id { get; set; }
public string Username { get; set; }
public byte[] PasswordHash { get; set; }
public byte[] PasswordSalt { get; set; }
public Gender Gender { get; set; }
public DateTime BirthDate { get; set; }
public string KnownAs { get; set; }
public DateTime DateCreated { get; set; }
public DateTime LastActive { get; set; }
public string Introduction { get; set; }
public Gender LookingFor { get; set; }
public string Interests { get; set; }
public string City { get; set; }
public string Country { get; set; }
public ICollection<Photo> Photos { get; set; }
}

public enum Gender
{
Male,
Female,
Both
}
}

0 comments on commit aacb783

Please sign in to comment.