Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

M.tenorio #10

Merged
merged 5 commits into from
May 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions BizData/Entities/Historial.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Text;

Expand All @@ -7,10 +7,12 @@ namespace BizData.Entities
public class Historial
{
public int HistorialID { get; set; }
public string EstadoViaje { get; set; }

public virtual Itinerario Viaje { get; set; }
//The owner of Viaje can be get through Viaje
//as well of the dates.
public string Comentario { get; set; }
public Estado Estado { get; set; }
public DateTime Fecha { get; set; }

public virtual Usuario Usuario { get; set; }
public virtual Itinerario Itinerario { get; set; }
}
}
19 changes: 19 additions & 0 deletions BizData/Entities/Itinerario.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,31 @@

namespace BizData.Entities
{
public enum Estado
{
Creado,
PendienteAprobacionJefeArea,
AprobadoJefeArea,
PendienteAprobacionDecano,
AprobadoDecano,
PendienteAprobacionRector,
AprobadoRector,
PendientePasaporte,
AprobadoPasaporte,
PendienteVisas,
AprobadasVisas,
PendienteRealizacion,
Realizado,
Cancelado
}

public class Itinerario
{
public string status { get; set; }
public int ItinerarioID { get; set; }
public DateTime? FechaInicio { get; set; }
public DateTime? FechaFin { get; set; }
public Estado Estado { get; set; }

public virtual Usuario Usuario { get; set; }
public virtual ICollection<Viaje> Viajes { get; set; }
Expand Down
5 changes: 2 additions & 3 deletions BizData/Entities/Viaje.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ public class Viaje
public string MotivoViaje { get; set; }
public DateTime? FechaInicio { get; set; }
public DateTime? FechaFin { get; set; }

public virtual Usuario Usuario { get; set; }
public virtual Itinerario Itinerario { get; set; }
public virtual Pais Pais { get; set; }
public virtual Ciudad Ciudad { get; set; }
public virtual Institucion Institucion { get; set; }
public virtual Itinerario Itinerario { get; set; }
}
}
22 changes: 8 additions & 14 deletions BizDbAccess/Repositories/HistorialDbAccess.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using BizData.Entities;
using BizData.Entities;
using BizDbAccess.GenericInterfaces;
using DataLayer.EfCode;
using System;
using System.Collections.Generic;

using System.Linq;
using System.Collections.Generic;
using System.Text;

namespace BizDbAccess.Repositories
Expand All @@ -27,24 +28,17 @@ public void Delete(Historial entity)
_context.Historial.Remove(entity);
}

public IEnumerable<Historial> GetAll() => _context.Historial;
public IEnumerable<Historial> GetAll() => _context.Historial.OrderBy(item => item.Fecha);

public Historial Update(Historial entity, Historial toUpd)
{
if (toUpd == null)
throw new Exception("Historial to be updated no exist");

toUpd.EstadoViaje = entity.EstadoViaje ?? toUpd.EstadoViaje;
toUpd.Viaje = entity.Viaje ?? toUpd.Viaje;

_context.Historial.Update(toUpd);
return toUpd;
throw new NotImplementedException();
}

public Historial GetHistorial(string estadoViaje, Itinerario viaje)
public Historial GetHistorial(Estado estadoViaje, Itinerario viaje)
{
return _context.Historial.Where(h => h.EstadoViaje == estadoViaje &&
h.Viaje.Usuario.Id == viaje.Usuario.Id)
return _context.Historial.Where(h => h.Estado == estadoViaje &&
h.Itinerario.Usuario.Id == viaje.Usuario.Id)
.SingleOrDefault();
}
}
Expand Down
1 change: 0 additions & 1 deletion BizDbAccess/Repositories/ViajeDbAccess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public Viaje Update(Viaje entity, Viaje toUpd)
toUpd.FechaInicio = entity.FechaInicio ?? toUpd.FechaFin;
toUpd.MotivoViaje = entity.MotivoViaje ?? toUpd.MotivoViaje;
toUpd.Pais = entity.Pais ?? toUpd.Pais;
toUpd.Usuario = entity.Usuario ?? toUpd.Usuario;
toUpd.Ciudad = entity.Ciudad ?? toUpd.Ciudad;

_context.Viajes.Update(toUpd);
Expand Down
2 changes: 1 addition & 1 deletion BizLogic/Administration/PaisCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public Pais ToPais()
return new Pais
{
Nombre = Name,
Region = Region
Region = Region == null ? null : Region
};
}
}
Expand Down
2 changes: 1 addition & 1 deletion BizLogic/Workflow/Concrete/RegisterHistorialAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public Historial Action(Historial dto)
{
try
{
var result = _dbAccess.GetHistorial(dto.EstadoViaje, dto.Viaje);
var result = _dbAccess.GetHistorial(dto.Estado, dto.Itinerario);

if (result != null)
throw new InvalidOperationException();
Expand Down
7 changes: 2 additions & 5 deletions BizLogic/Workflow/ViajeCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,14 @@ public class ViajeCommand
public DateTime? FechaInicio { get; set; }
public DateTime? FechaFin { get; set; }

public Usuario Usuario { get; set; }
public Pais Pais { get; set; }
public Ciudad Ciudad { get; set; }
//public Institucion Institucion { get; set; }
public Itinerario Itinerario { get; set; }

public ViajeCommand(int itinerarioID, string usuarioID, string paisName, string motivo, DateTime? fechaInicio, DateTime? fechaFin)
public ViajeCommand(int itinerarioID, string paisName, string motivo, DateTime? fechaInicio, DateTime? fechaFin)
{
ItinerarioID = itinerarioID;
UsuarioId = usuarioID;
FechaInicio = fechaInicio;
FechaFin = fechaFin;
PaisName = paisName;
Expand All @@ -35,9 +33,8 @@ public Viaje ToViaje()
return new Viaje()
{
MotivoViaje = Motivo,
Usuario = Usuario,
Pais = Pais,
Ciudad = Ciudad
//Ciudad = Ciudad
// Institucion = Institucion
};
}
Expand Down
13 changes: 13 additions & 0 deletions BizLogic/WorkflowManager/Actions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace BizLogic.WorkflowManager
{
public enum Action
{
Ignorar,
Aprobar,
Rechazar
}
}
172 changes: 172 additions & 0 deletions BizLogic/WorkflowManager/WorkflowManagerGuest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
using BizData.Entities;
using BizDbAccess.GenericInterfaces;
using BizDbAccess.Repositories;
using System;
using System.Collections.Generic;
using System.Text;

namespace BizLogic.WorkflowManager
{
public class WorkflowManagerGuest
{
private HistorialDbAccess _historial { get; set; }
private IUnitOfWork _context { get; set; }

public WorkflowManagerGuest(IUnitOfWork context)
{
_context = context;
_historial = new HistorialDbAccess(_context);
}

public void CrearViaje(Itinerario itinerario, string claimTipoUsuario)
{
var historial_entity = new Historial
{
Estado = Estado.Creado,
Itinerario = itinerario,
Fecha = DateTime.Now
};
_historial.Add(historial_entity);
_context.Commit();

if (claimTipoUsuario == "Trabajador")
{
itinerario.Estado = Estado.PendienteAprobacionJefeArea;
return;
}
if (claimTipoUsuario == "JefeArea")
{
itinerario.Estado = Estado.PendienteAprobacionDecano;
return;
}
if (claimTipoUsuario == "Decano")
{
itinerario.Estado = Estado.PendienteAprobacionDecano;
return;
}
if (claimTipoUsuario == "Rector")
{
itinerario.Estado = Estado.PendienteRealizacion;
return;
}
}

public void ManageActionJefeArea(Itinerario itinerario, Action action, Usuario usuario, string comentario)
{
var historial_entity = new Historial
{
Itinerario = itinerario,
Usuario = usuario,
Fecha = DateTime.Now,
Comentario = comentario
};

if (action == Action.Aprobar)
{
historial_entity.Estado = Estado.AprobadoJefeArea;
_historial.Add(historial_entity);
_context.Commit();

itinerario.Estado = Estado.PendienteAprobacionDecano;
return;
}

if (action == Action.Rechazar)
{
historial_entity.Estado = itinerario.Estado;
_historial.Add(historial_entity);
_context.Commit();
return;
}
}

public void ManageActionDecano(Itinerario itinerario, Action action, Usuario usuario, string comentario)
{
var historial_entity = new Historial
{
Itinerario = itinerario,
Usuario = usuario,
Fecha = DateTime.Now,
Comentario = comentario
};

if (action == Action.Aprobar)
{
historial_entity.Estado = Estado.AprobadoDecano;
_historial.Add(historial_entity);
_context.Commit();

itinerario.Estado = Estado.PendienteAprobacionRector;
return;
}

if (action == Action.Rechazar)
{
historial_entity.Estado = itinerario.Estado;
_historial.Add(historial_entity);
_context.Commit();
return;
}
}

public void ManageActionRector(Itinerario itinerario, Action action, Usuario usuario, string comentario)
{
var historial_entity = new Historial
{
Estado = Estado.AprobadoRector,
Itinerario = itinerario,
Usuario = usuario,
Fecha = DateTime.Now,
Comentario = comentario
};

if (action == Action.Aprobar)
{
historial_entity.Estado = Estado.AprobadoRector;
_historial.Add(historial_entity);
_context.Commit();

itinerario.Estado = Estado.PendienteRealizacion;
return;
}

if (action == Action.Rechazar)
{
historial_entity.Estado = itinerario.Estado;
_historial.Add(historial_entity);
_context.Commit();
return;
}
}

public void ManageActionRealizacion(Itinerario itinerario)
{
itinerario.Estado = Estado.Realizado;

var historial_entity = new Historial
{
Estado = itinerario.Estado,
Itinerario = itinerario,
Fecha = DateTime.Now
};
_historial.Add(historial_entity);
_context.Commit();
}

public void CancelarItinerario(Itinerario itinerario, Usuario usuario, string comentario)
{
itinerario.Estado = Estado.Cancelado;

var historial_entity = new Historial
{
Estado = itinerario.Estado,
Itinerario = itinerario,
Usuario = usuario,
Fecha = DateTime.Now,
Comentario = comentario
};
_historial.Add(historial_entity);
_context.Commit();
}
}
}
Loading