Continued to work on the update student handler
This commit is contained in:
@@ -9,6 +9,10 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="JsonNet.PrivateSettersContractResolvers.Source" Version="0.1.0">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
<PackageReference Include="MediatR" Version="6.0.0" />
|
<PackageReference Include="MediatR" Version="6.0.0" />
|
||||||
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="6.0.1" />
|
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="6.0.1" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.All" />
|
<PackageReference Include="Microsoft.AspNetCore.All" />
|
||||||
|
|||||||
@@ -43,7 +43,8 @@ namespace BrightGlimmer.Api.Controllers
|
|||||||
[HttpPut]
|
[HttpPut]
|
||||||
public async Task<ActionResult> Update([FromBody]UpdateStudentCommand command)
|
public async Task<ActionResult> Update([FromBody]UpdateStudentCommand command)
|
||||||
{
|
{
|
||||||
|
var student = await mediator.Send(command);
|
||||||
|
return new JsonResult(student);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -24,7 +24,12 @@ namespace BrightGlimmer.Api
|
|||||||
// This method gets called by the runtime. Use this method to add services to the container.
|
// This method gets called by the runtime. Use this method to add services to the container.
|
||||||
public void ConfigureServices(IServiceCollection services)
|
public void ConfigureServices(IServiceCollection services)
|
||||||
{
|
{
|
||||||
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
|
services.AddMvc()
|
||||||
|
.SetCompatibilityVersion(CompatibilityVersion.Version_2_1)
|
||||||
|
.AddJsonOptions(options =>
|
||||||
|
{
|
||||||
|
options.SerializerSettings.ContractResolver = new PrivateSetterContractResolver()
|
||||||
|
});
|
||||||
|
|
||||||
services.AddMediatR();
|
services.AddMediatR();
|
||||||
services.AddMediatR(typeof(Cqrs.Cqrs).Assembly); // Registers handlers in services project
|
services.AddMediatR(typeof(Cqrs.Cqrs).Assembly); // Registers handlers in services project
|
||||||
|
|||||||
@@ -9,12 +9,12 @@ namespace BrightGlimmer.Domain
|
|||||||
[Table("Addresses")]
|
[Table("Addresses")]
|
||||||
public class Address : Entity
|
public class Address : Entity
|
||||||
{
|
{
|
||||||
public string StreetAddress1 { get; set; }
|
public string StreetAddress1 { get; private set; }
|
||||||
public string StreetAddress2 { get; set; }
|
public string StreetAddress2 { get; private set; }
|
||||||
public string City { get; set; }
|
public string City { get; private set; }
|
||||||
public string StateCode { get; set; }
|
public string StateCode { get; private set; }
|
||||||
public string County { get; set; }
|
public string County { get; private set; }
|
||||||
public string ZipCode { get; set; }
|
public string ZipCode { get; private set; }
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public decimal Latitude { get; private set; }
|
public decimal Latitude { get; private set; }
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
@@ -56,9 +56,14 @@ namespace BrightGlimmer.Domain
|
|||||||
Longitude = longitude;
|
Longitude = longitude;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Update(Address address)
|
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)
|
public void SetLatitudeAndLongitude(decimal latitude, decimal longitude)
|
||||||
|
|||||||
@@ -29,5 +29,19 @@ namespace BrightGlimmer.Domain
|
|||||||
IsActive = isActive;
|
IsActive = isActive;
|
||||||
Term = term;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,9 +8,9 @@ namespace BrightGlimmer.Domain
|
|||||||
[Table("Courses")]
|
[Table("Courses")]
|
||||||
public class Course : Entity
|
public class Course : Entity
|
||||||
{
|
{
|
||||||
public string Name { get; private set; }
|
public string Name { get; set; }
|
||||||
public string Description { get; private set; }
|
public string Description { get; set; }
|
||||||
public string Code { get; private set; }
|
public string Code { get; set; }
|
||||||
|
|
||||||
private Course() { }
|
private Course() { }
|
||||||
|
|
||||||
@@ -20,5 +20,12 @@ namespace BrightGlimmer.Domain
|
|||||||
Description = description;
|
Description = description;
|
||||||
Code = code;
|
Code = code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Update(Course course)
|
||||||
|
{
|
||||||
|
Name = course.Name;
|
||||||
|
Description = course.Description;
|
||||||
|
Code = course.Code;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ using System.Text;
|
|||||||
|
|
||||||
namespace BrightGlimmer.Domain
|
namespace BrightGlimmer.Domain
|
||||||
{
|
{
|
||||||
public class Entity
|
public abstract class Entity
|
||||||
{
|
{
|
||||||
[Key]
|
[Key]
|
||||||
public Guid Id { get; private set; }
|
public Guid Id { get; private set; }
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using Newtonsoft.Json;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@@ -8,9 +9,12 @@ namespace BrightGlimmer.Domain
|
|||||||
[Table("Phones")]
|
[Table("Phones")]
|
||||||
public class Phone : Entity
|
public class Phone : Entity
|
||||||
{
|
{
|
||||||
public PhoneType Type { get; set; }
|
[JsonProperty]
|
||||||
public int AreaCode { get; set; }
|
public PhoneType Type { get; private set; }
|
||||||
public int Number { get; set; }
|
[JsonProperty]
|
||||||
|
public int AreaCode { get; private set; }
|
||||||
|
[JsonProperty]
|
||||||
|
public int Number { get; private set; }
|
||||||
|
|
||||||
private Phone() { }
|
private Phone() { }
|
||||||
|
|
||||||
@@ -20,5 +24,19 @@ namespace BrightGlimmer.Domain
|
|||||||
AreaCode = areaCode;
|
AreaCode = areaCode;
|
||||||
Number = number;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace BrightGlimmer.Domain
|
namespace BrightGlimmer.Domain
|
||||||
@@ -47,18 +48,33 @@ namespace BrightGlimmer.Domain
|
|||||||
MiddleName = student.MiddleName;
|
MiddleName = student.MiddleName;
|
||||||
LastName = student.LastName;
|
LastName = student.LastName;
|
||||||
Email = student.Email;
|
Email = student.Email;
|
||||||
|
}
|
||||||
|
|
||||||
if ()
|
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)
|
public void AddPhone(Phone phone)
|
||||||
{
|
{
|
||||||
phones.Add(phone);
|
phones.Add(new Phone(phone));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddAssignedCourse(AssignedCourse assignedCourse)
|
public void AddAssignedCourse(AssignedCourse assignedCourse)
|
||||||
{
|
{
|
||||||
assignedCourses.Add(assignedCourse);
|
assignedCourses.Add(new AssignedCourse(assignedCourse));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ using BrightGlimmer.Service.Commands;
|
|||||||
using MediatR;
|
using MediatR;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@@ -28,11 +29,30 @@ namespace BrightGlimmer.Service.Handlers.CommandHandlers
|
|||||||
student.LastName = request.LastName;
|
student.LastName = request.LastName;
|
||||||
student.Email = request.Email;
|
student.Email = request.Email;
|
||||||
|
|
||||||
if (student.Address != null)
|
if (request.Address != null)
|
||||||
{
|
{
|
||||||
|
/* TODO: CALL TO SET LAT LONG */
|
||||||
|
student.UpdateAddress(request.Address);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (student.Phones != null)
|
||||||
|
{
|
||||||
|
var newPhones = new List<Phone>();
|
||||||
|
foreach (var phone in request.Phones)
|
||||||
|
{
|
||||||
|
if (!student.UpdatePhone(phone))
|
||||||
|
{
|
||||||
|
newPhones.Add(phone);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var newPhone in newPhones)
|
||||||
|
{
|
||||||
|
student.AddPhone(newPhone);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await repository.UnitOfWork.SaveChangesAsync();
|
||||||
return student;
|
return student;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user