Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
G10TSI1
Practico1
Commits
a6f3c700
Commit
a6f3c700
authored
Apr 03, 2016
by
Sebastian Barbosa
Browse files
Merge branch 'master' into servicelayer
parents
2c371063
ec9a302e
Pipeline
#209
skipped
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
DataAccessLayer/DALEmployeesEF.cs
View file @
a6f3c700
...
...
@@ -50,10 +50,8 @@ namespace DataAccessLayer
context
.
SaveChanges
();
}
}
//throw new NotImplementedException();
}
public
void
UpdateEmployee
(
Employee
emp
)
...
...
DataAccessLayer/DALEmployeesMongo.cs
View file @
a6f3c700
...
...
@@ -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
;
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment