Commit a6f3c700 authored by Sebastian Barbosa's avatar Sebastian Barbosa
Browse files

Merge branch 'master' into servicelayer

parents 2c371063 ec9a302e
Pipeline #209 skipped
......@@ -50,10 +50,8 @@ namespace DataAccessLayer
context.SaveChanges();
}
}
//throw new NotImplementedException();
}
public void UpdateEmployee(Employee emp)
......
......@@ -6,38 +6,50 @@ using MongoDB.Bson;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Shared;
namespace DataAccessLayer
{
public class DALEmployeesMongo : IDALEmployees
{
// Documentacion sobre MongoDB y C#
// https://docs.mongodb.org/getting-started/csharp/update/
//TODO: Ver si esta bien tener el cliente y la base estatica en la tabla, me imagino que abre una sesion y no expira pero anda a saber
// No veo nada de pool y de keep alive, no debe de ser muy prolijo tenerlo aca
protected static IMongoClient _client;
protected static IMongoDatabase _database;
static DALEmployeesMongo()
{
private IMongoClient _client;
private IMongoDatabase _database;
public DALEmployeesMongo()
{
_client = new MongoClient();
_database = _client.GetDatabase("tsi_pr1");
_database = _client.GetDatabase("tsi_pr1");
}
public void AddEmployee(Employee emp)
{
throw new NotImplementedException();
var collection = _database.GetCollection<BsonDocument>("EmployeesTPH");
BsonDocument result = collection.Find(new BsonDocument()).Sort(new BsonDocument("ID", -1)).FirstOrDefault();
var document = new BsonDocument
{
{ "ID", result == null ? 1 : result["ID"].ToInt32() + 1},
{ "NAME", emp.Name},
{ "TYPE_EMP", emp is FullTimeEmployee ? 1 : 0},
{ emp is FullTimeEmployee ? "SALARY" : "RATE", emp is FullTimeEmployee ? ((FullTimeEmployee)emp).Salary : ((PartTimeEmployee)emp).HourlyRate},
{ "START_DATE", emp.StartDate}
};
collection.InsertOne(document);
}
public void DeleteEmployee(int id)
{
throw new NotImplementedException();
var collection = _database.GetCollection<BsonDocument>("EmployeesTPH");
var filter = Builders<BsonDocument>.Filter.Eq("ID", id);
collection.DeleteOne(filter);
}
//Bruno
public void UpdateEmployee(Employee emp)
{
// https://docs.mongodb.org/getting-started/csharp/update/
var collection = _database.GetCollection<BsonDocument>("EmployeesTPH");
var filter = Builders<BsonDocument>.Filter.Eq("ID", emp.Id);
var update = Builders<BsonDocument>.Update
......@@ -95,24 +107,21 @@ namespace DataAccessLayer
return employee;
}
private Shared.Entities.Employee fromDocument(BsonDocument document)
private Employee fromDocument(BsonDocument document)
{
Employee result = null;
if (document != null)
{
if (document["TYPE_EMP"].ToInt32() == 1)
{
Shared.Entities.FullTimeEmployee tmp = new FullTimeEmployee();
FullTimeEmployee tmp = new FullTimeEmployee();
tmp.Salary = document["SALARY"].ToInt32();
result = tmp;
}
else
{
Shared.Entities.PartTimeEmployee tmp = new PartTimeEmployee();
PartTimeEmployee tmp = new PartTimeEmployee();
tmp.HourlyRate = document["RATE"].ToDouble();
result = tmp;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment