Skip to content

Commit

Permalink
initial add roommate completed
Browse files Browse the repository at this point in the history
  • Loading branch information
ArabellaJi committed Oct 5, 2023
1 parent 32128b8 commit 1210ca0
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Gordon360/Controllers/HousingController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Microsoft.AspNetCore.Mvc;
using System;
using System.Security.Claims;
using System.Threading.Tasks;

namespace Gordon360.Controllers
{
Expand Down Expand Up @@ -243,5 +244,18 @@ public ActionResult<ApartmentApplicationViewModel[]> GetAllApartmentApplication(
return NotFound();
}
}

/// <summary>
/// Update roommate information
/// </summary>
/// <returns></returns>
[HttpPut]
[Route("housing_lottery/{roommate}")]
public async Task<ActionResult<FacultyStaffProfileViewModel>> UpdateRoommate(string roommate)
{
var username = AuthUtils.GetUsername(User);
await _housingService.UpdateRoommateAsync(username, roommate);
return Ok();
}
}
}
13 changes: 13 additions & 0 deletions Gordon360/Documentation/Gordon360.xml

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

16 changes: 16 additions & 0 deletions Gordon360/Models/CCT/Context/CCTContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public CCTContext(DbContextOptions<CCTContext> options)
public virtual DbSet<RequestView> RequestView { get; set; }
public virtual DbSet<RoleType> RoleType { get; set; }
public virtual DbSet<RoomAssign> RoomAssign { get; set; }
public virtual DbSet<Roommate> Roommate { get; set; }
public virtual DbSet<Rooms> Rooms { get; set; }
public virtual DbSet<Save_Bookings> Save_Bookings { get; set; }
public virtual DbSet<Save_Rides> Save_Rides { get; set; }
Expand Down Expand Up @@ -512,7 +513,11 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)

modelBuilder.Entity<Participant>(entity =>
{
entity.Property(e => e.AllowEmails).HasDefaultValueSql("((1))");
entity.Property(e => e.ID).ValueGeneratedOnAdd();
entity.Property(e => e.SpecifiedGender).IsFixedLength();
});

modelBuilder.Entity<ParticipantActivity>(entity =>
Expand Down Expand Up @@ -622,6 +627,12 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
entity.Property(e => e.SESS_CDE).IsFixedLength();
});

modelBuilder.Entity<Roommate>(entity =>
{
entity.HasKey(e => new { e.ID, e.RoommateName })
.HasName("PK__Roommate__A9AF9368B01FE07C");
});

modelBuilder.Entity<Save_Bookings>(entity =>
{
entity.HasKey(e => new { e.ID, e.rideID });
Expand Down Expand Up @@ -662,6 +673,11 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
.HasForeignKey(d => d.TypeID)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_Series_SeriesType");
entity.HasOne(d => d.Winner)
.WithMany(p => p.Series)
.HasForeignKey(d => d.WinnerID)
.HasConstraintName("FK_Series_Team");
});

modelBuilder.Entity<SeriesSurface>(entity =>
Expand Down
4 changes: 4 additions & 0 deletions Gordon360/Models/CCT/Context/efpt.CCT.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@
"Name": "[dbo].[Users]",
"ObjectType": 0
},
{
"Name": "[Housing].[Roommate]",
"ObjectType": 0
},
{
"Name": "[RecIM].[Activity]",
"ObjectType": 0
Expand Down
25 changes: 25 additions & 0 deletions Gordon360/Models/CCT/Housing/Roommate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// <auto-generated> This file has been auto generated by EF Core Power Tools. </auto-generated>
#nullable disable
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;

namespace Gordon360.Models.CCT
{
[Table("Roommate", Schema = "Housing")]
public partial class Roommate
{
[Key]
public int ID { get; set; }
[Required]
[StringLength(128)]
[Unicode(false)]
public string Name { get; set; }
[Key]
[StringLength(128)]
[Unicode(false)]
public string RoommateName { get; set; }
}
}
25 changes: 25 additions & 0 deletions Gordon360/Services/HousingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
using Gordon360.Enums;
using Gordon360.Static.Methods;
using Microsoft.EntityFrameworkCore;
using Gordon360.Models.webSQL.Context;
using System.Threading.Tasks;

namespace Gordon360.Services
{
Expand Down Expand Up @@ -537,5 +539,28 @@ public bool ChangeApplicationDateSubmitted(int applicationID)
_context.SaveChanges();
return true;
}

/// <summary>
/// roommate imformation setting
/// </summary>
/// <param name="username"> The username for the user who complete the aplication form </param>
/// <param name="roommate_name"> The name of the selected roommate </param>
public async Task UpdateRoommateAsync(string username, string roommate_name)
{
var GordonID = _context.ACCOUNT.FirstOrDefault(a => a.AD_Username == username)?.gordon_id;
if (GordonID == null)
{
throw new ResourceNotFoundException() { ExceptionMessage = "The applicant could not be found" };
}
var newRoommate = new Roommate
{
ID = int.Parse(GordonID),
Name = username,
RoommateName = roommate_name
}; ;
await _context.Roommate.AddAsync(newRoommate);

_context.SaveChanges();
}
}
}
1 change: 1 addition & 0 deletions Gordon360/Services/ServiceInterfaces.cs
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ public interface IHousingService
int EditApplication(string username, string sess_cde, int applicationID, string newEditorUsername, List<ApartmentApplicantViewModel> newApartmentApplicants, List<ApartmentChoiceViewModel> newApartmentChoices);
bool ChangeApplicationEditor(string username, int applicationID, string newEditorUsername);
bool ChangeApplicationDateSubmitted(int applicationID);
Task UpdateRoommateAsync(string username, string roommate_name);
}

public interface IAcademicCheckInService
Expand Down

0 comments on commit 1210ca0

Please sign in to comment.