Started to create authorization portion pt.2
This commit is contained in:
75
BrightGlimmer.Domain/Service/Address.cs
Normal file
75
BrightGlimmer.Domain/Service/Address.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Text;
|
||||
|
||||
namespace BrightGlimmer.Domain.Service
|
||||
{
|
||||
[Table("Addresses")]
|
||||
public class Address : Entity
|
||||
{
|
||||
public string StreetAddress1 { get; private set; }
|
||||
public string StreetAddress2 { get; private set; }
|
||||
public string City { get; private set; }
|
||||
public string StateCode { get; private set; }
|
||||
public string County { get; private set; }
|
||||
public string ZipCode { get; private set; }
|
||||
[JsonIgnore]
|
||||
public decimal Latitude { get; private set; }
|
||||
[JsonIgnore]
|
||||
public decimal Longitude { get; private set; }
|
||||
|
||||
protected Address() { }
|
||||
|
||||
public Address(string streetAddress1,
|
||||
string streetAddress2,
|
||||
string city,
|
||||
string stateCode,
|
||||
string county,
|
||||
string zipCode)
|
||||
{
|
||||
StreetAddress1 = streetAddress1;
|
||||
StreetAddress2 = streetAddress2;
|
||||
City = city;
|
||||
StateCode = stateCode;
|
||||
County = county;
|
||||
ZipCode = zipCode;
|
||||
}
|
||||
|
||||
public Address(string streetAddress1,
|
||||
string streetAddress2,
|
||||
string city,
|
||||
string stateCode,
|
||||
string county,
|
||||
string zipCode,
|
||||
decimal latitude,
|
||||
decimal longitude)
|
||||
{
|
||||
StreetAddress1 = streetAddress1;
|
||||
StreetAddress2 = streetAddress2;
|
||||
City = city;
|
||||
StateCode = stateCode;
|
||||
County = county;
|
||||
ZipCode = zipCode;
|
||||
Latitude = latitude;
|
||||
Longitude = longitude;
|
||||
}
|
||||
|
||||
internal void Update(Address address)
|
||||
{
|
||||
StreetAddress1 = address.StreetAddress1;
|
||||
StreetAddress2 = address.StreetAddress2;
|
||||
City = address.City;
|
||||
StateCode = address.StateCode;
|
||||
County = address.County;
|
||||
ZipCode = address.ZipCode;
|
||||
}
|
||||
|
||||
public void SetLatitudeAndLongitude(decimal latitude, decimal longitude)
|
||||
{
|
||||
Latitude = latitude;
|
||||
Longitude = longitude;
|
||||
}
|
||||
}
|
||||
}
|
||||
47
BrightGlimmer.Domain/Service/AssignedCourse.cs
Normal file
47
BrightGlimmer.Domain/Service/AssignedCourse.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Text;
|
||||
|
||||
namespace BrightGlimmer.Domain.Service
|
||||
{
|
||||
[Table("AssignedCourses")]
|
||||
public class AssignedCourse : Entity
|
||||
{
|
||||
public decimal? Grade { get; set; }
|
||||
public bool IsActive { get; set; }
|
||||
public string Term { get; set; }
|
||||
|
||||
public virtual Student Student { get; private set; }
|
||||
public virtual Course Course { get; private set; }
|
||||
|
||||
protected AssignedCourse() { }
|
||||
|
||||
public AssignedCourse(bool isActive, string term)
|
||||
{
|
||||
IsActive = isActive;
|
||||
Term = term;
|
||||
}
|
||||
|
||||
public AssignedCourse(decimal grade, bool isActive, string term)
|
||||
{
|
||||
Grade = grade;
|
||||
IsActive = isActive;
|
||||
Term = term;
|
||||
}
|
||||
|
||||
public AssignedCourse(AssignedCourse assignedCourse)
|
||||
{
|
||||
Grade = assignedCourse.Grade;
|
||||
IsActive = assignedCourse.IsActive;
|
||||
Term = assignedCourse.Term;
|
||||
}
|
||||
|
||||
public void Update(AssignedCourse assignedCourse)
|
||||
{
|
||||
Grade = assignedCourse.Grade;
|
||||
IsActive = assignedCourse.IsActive;
|
||||
Term = assignedCourse.Term;
|
||||
}
|
||||
}
|
||||
}
|
||||
31
BrightGlimmer.Domain/Service/Course.cs
Normal file
31
BrightGlimmer.Domain/Service/Course.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Text;
|
||||
|
||||
namespace BrightGlimmer.Domain.Service
|
||||
{
|
||||
[Table("Courses")]
|
||||
public class Course : Entity
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Description { get; set; }
|
||||
public string Code { get; set; }
|
||||
|
||||
protected Course() { }
|
||||
|
||||
public Course(string name, string description, string code)
|
||||
{
|
||||
Name = name;
|
||||
Description = description;
|
||||
Code = code;
|
||||
}
|
||||
|
||||
public void Update(Course course)
|
||||
{
|
||||
Name = course.Name;
|
||||
Description = course.Description;
|
||||
Code = course.Code;
|
||||
}
|
||||
}
|
||||
}
|
||||
42
BrightGlimmer.Domain/Service/Phone.cs
Normal file
42
BrightGlimmer.Domain/Service/Phone.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Text;
|
||||
|
||||
namespace BrightGlimmer.Domain.Service
|
||||
{
|
||||
[Table("Phones")]
|
||||
public class Phone : Entity
|
||||
{
|
||||
[JsonProperty]
|
||||
public PhoneType Type { get; private set; }
|
||||
[JsonProperty]
|
||||
public int AreaCode { get; private set; }
|
||||
[JsonProperty]
|
||||
public int Number { get; private set; }
|
||||
|
||||
protected Phone() { }
|
||||
|
||||
public Phone(PhoneType type, int areaCode, int number)
|
||||
{
|
||||
Type = type;
|
||||
AreaCode = areaCode;
|
||||
Number = number;
|
||||
}
|
||||
|
||||
public Phone(Phone phone)
|
||||
{
|
||||
Type = phone.Type;
|
||||
AreaCode = phone.AreaCode;
|
||||
Number = phone.Number;
|
||||
}
|
||||
|
||||
internal void Update(Phone phone)
|
||||
{
|
||||
Type = phone.Type;
|
||||
AreaCode = phone.AreaCode;
|
||||
Number = Number;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
BrightGlimmer.Domain/Service/PhoneType.cs
Normal file
11
BrightGlimmer.Domain/Service/PhoneType.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace BrightGlimmer.Domain.Service
|
||||
{
|
||||
public enum PhoneType
|
||||
{
|
||||
HOMEPHONE, CELLPHONE, WORKPHONE
|
||||
}
|
||||
}
|
||||
81
BrightGlimmer.Domain/Service/Student.cs
Normal file
81
BrightGlimmer.Domain/Service/Student.cs
Normal file
@@ -0,0 +1,81 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace BrightGlimmer.Domain.Service
|
||||
{
|
||||
[Table("Students")]
|
||||
public class Student : Entity
|
||||
{
|
||||
[NotMapped]
|
||||
private readonly int MAX_STUDENT_NUMBER = 100000000;
|
||||
|
||||
public int StudentNumber { get; private set; }
|
||||
public string FirstName { get; set; }
|
||||
public string MiddleName { get; set; }
|
||||
public string LastName { get; set; }
|
||||
public string Email { get; set; }
|
||||
public virtual Address Address { get; private set; }
|
||||
public string ProfilePictureUrl { get; set; }
|
||||
|
||||
private readonly List<Phone> phones = new List<Phone>();
|
||||
public virtual IReadOnlyList<Phone> Phones => phones;
|
||||
|
||||
private readonly List<AssignedCourse> assignedCourses = new List<AssignedCourse>();
|
||||
public virtual IReadOnlyList<AssignedCourse> AssignedCourses => assignedCourses;
|
||||
|
||||
protected Student() { }
|
||||
|
||||
public Student(string firstName,
|
||||
string lastName,
|
||||
string email,
|
||||
List<Phone> phones,
|
||||
Address address) : base()
|
||||
{
|
||||
StudentNumber = new Random().Next(MAX_STUDENT_NUMBER); /* TODO: Optimize student number creation */
|
||||
FirstName = firstName;
|
||||
LastName = lastName;
|
||||
Email = email;
|
||||
Address = address;
|
||||
this.phones = phones;
|
||||
}
|
||||
|
||||
public void Update(Student student)
|
||||
{
|
||||
FirstName = student.FirstName;
|
||||
MiddleName = student.MiddleName;
|
||||
LastName = student.LastName;
|
||||
Email = student.Email;
|
||||
}
|
||||
|
||||
public void UpdateAddress(Address address)
|
||||
{
|
||||
Address.Update(address);
|
||||
}
|
||||
|
||||
public bool UpdatePhone(Phone phone)
|
||||
{
|
||||
var existingPhone = Phones.SingleOrDefault(x => x.Id == phone.Id);
|
||||
if (existingPhone == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
existingPhone.Update(phone);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void AddPhone(Phone phone)
|
||||
{
|
||||
phones.Add(new Phone(phone));
|
||||
}
|
||||
|
||||
public void AddAssignedCourse(AssignedCourse assignedCourse)
|
||||
{
|
||||
assignedCourses.Add(new AssignedCourse(assignedCourse));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user