Browse Source

Add auto update when case is set to cured/certified, image handling improved

master
Daniel Gyulai 4 years ago
parent
commit
efe19ba453
  1. 3
      CoviDok/BLL/User/Handlers/ICaseHandler.cs
  2. 19
      CoviDok/BLL/User/Managers/CaseManager.cs
  3. 2
      CoviDok/Controllers/AssistantController.cs
  4. 14
      CoviDok/Data/Model/Image.cs
  5. 26
      CoviDok/Data/MySQL/MySqlCaseHandler.cs
  6. 2
      CoviDok/Data/MySQL/MySqlContext.cs

3
CoviDok/BLL/User/Handlers/ICaseHandler.cs

@ -17,10 +17,11 @@ namespace CoviDok.BLL.User.Handlers
public Task UpdateCase(int id, Case Case, Update update);
public Task SetCase(int id, CaseStatus status);
public Task SetCase(int id, CaseStatus status, Update message);
public bool IsAuthorized(int ID, Case c);
public List<Update> GetUpdatesForCase(int id);
public Update GetUpadte(int id);
public bool IsAssistantOfDoctor(int id, int doctorID);
}
}

19
CoviDok/BLL/User/Managers/CaseManager.cs

@ -39,7 +39,14 @@ namespace CoviDok.BLL.User.Managers
if (c == null) throw new KeyNotFoundException();
if (handler.IsAuthorized(s.ID, c) && s.Type == Api.Role.Ast)
{
await handler.SetCase(id, CaseStatus.Cured);
Update update = new Update {
CaseID = c.Id,
SenderID = s.ID,
SenderRole = s.Type,
CreatedDate = DateTime.Now,
Content = "Case set to 'Certified'"
};
await handler.SetCase(id, CaseStatus.Cured, update);
}
else
{
@ -53,7 +60,15 @@ namespace CoviDok.BLL.User.Managers
if (c == null) throw new KeyNotFoundException();
if (s.ID == c.DoctorID)
{
await handler.SetCase(id, CaseStatus.Cured);
Update update = new Update
{
CaseID = c.Id,
SenderID = s.ID,
SenderRole = s.Type,
CreatedDate = DateTime.Now,
Content = "Case set to 'Cured'"
};
await handler.SetCase(id, CaseStatus.Cured, update);
}
else
{

2
CoviDok/Controllers/AssistantController.cs

@ -22,7 +22,7 @@ namespace CoviDok.Controllers
[HttpGet("{id}")]
public async Task<ActionResult<PublicAssistant>> GetDoctor(int id)
public async Task<ActionResult<PublicAssistant>> GetAssistant(int id)
{
try
{

14
CoviDok/Data/Model/Image.cs

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace CoviDok.Data.Model
{
public class Image
{
public int Id { get; set; }
public int UpdateID { get; set; }
public string ImageID { get; set; }
}
}

26
CoviDok/Data/MySQL/MySqlCaseHandler.cs

@ -21,10 +21,13 @@ namespace CoviDok.Data.MySQL
return c;
}
public async Task SetCase(int id, CaseStatus status)
public async Task SetCase(int id, CaseStatus status, Update message)
{
Case c = await context.Cases.FindAsync(id);
message.CaseID = c.Id;
context.Updates.Add(message);
c.CaseStatus = status;
c.Updates.Add(message);
await context.SaveChangesAsync();
}
@ -35,7 +38,17 @@ namespace CoviDok.Data.MySQL
public Update GetUpadte(int id)
{
return (from u in context.Updates where u.Id == id select u).First();
Update update = (from u in context.Updates where u.Id == id select u).First();
if (update != null)
{
update.Images = (from i in context.Images where i.UpdateID == update.Id select i.ImageID).ToList();
}
return update;
}
public bool IsAssistantOfDoctor(int id, int doctorID)
{
return context.Assistants.Any( (a) => a.Id == id && a.DoctorId == doctorID);
}
public async Task<List<Case>> Filter(CaseFilter filter)
@ -81,6 +94,15 @@ namespace CoviDok.Data.MySQL
string[] forbidden = { "Updates" };
PropertyCopier<Case>.Copy(Case, c, forbidden);
context.Updates.Add(update);
foreach (string ImageID in update.Images)
{
Image image = new Image
{
UpdateID = update.Id,
ImageID = ImageID
};
context.Images.Add(image);
}
update.CreatedDate = DateTime.Now;
c.Updates.Add(update);
await context.SaveChangesAsync();

2
CoviDok/Data/MySQL/MySqlContext.cs

@ -15,8 +15,8 @@ namespace CoviDok.Data.MySQL
public DbSet<Child> Children { get; set; }
public DbSet<Case> Cases { get; set; }
public DbSet<Update> Updates { get; set; }
public DbSet<RoleUser> RoleUsers { get; set; }
public DbSet<Image> Images { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseMySQL("server=mysql;database=covidok;user=covidok;password=covidok");

Loading…
Cancel
Save