Nearing feature complete for driver auth
This commit is contained in:
+20
-10
@@ -34,7 +34,11 @@ namespace MileageTraker.Web.DAL
|
||||
log.VehiclePreviousLog = previousLog;
|
||||
var nextLog = SearchNextLog(log);
|
||||
if (nextLog != null)
|
||||
{
|
||||
nextLog.VehiclePreviousLog = log;
|
||||
nextLog.User = _db.Users.Find(nextLog.User.UserId);
|
||||
_db.Entry(nextLog).State = EntityState.Modified;
|
||||
}
|
||||
|
||||
_db.SaveChanges();
|
||||
|
||||
@@ -43,14 +47,7 @@ namespace MileageTraker.Web.DAL
|
||||
|
||||
public void UpdateLog(Log log)
|
||||
{
|
||||
_db.Logs.Attach(log);
|
||||
var original = _db.Logs.Find(log.LogId);
|
||||
|
||||
// ignore these properties while updating
|
||||
log.Created = original.Created;
|
||||
log.Source = original.Source;
|
||||
log.UserAgent = original.UserAgent;
|
||||
log.UserHostAddress = original.UserHostAddress;
|
||||
// note: assumes log is already attached to current context
|
||||
|
||||
// remove from the list
|
||||
var nextLog =
|
||||
@@ -58,7 +55,11 @@ namespace MileageTraker.Web.DAL
|
||||
where l.VehiclePreviousLogId == log.LogId
|
||||
select l).FirstOrDefault();
|
||||
if (nextLog != null)
|
||||
{
|
||||
nextLog.VehiclePreviousLogId = log.VehiclePreviousLogId;
|
||||
nextLog.User = _db.Users.Find(nextLog.User.UserId);
|
||||
_db.Entry(nextLog).State = EntityState.Modified;
|
||||
}
|
||||
|
||||
log.VehiclePreviousLog = null;
|
||||
log.VehiclePreviousLogId = null;
|
||||
@@ -69,8 +70,13 @@ namespace MileageTraker.Web.DAL
|
||||
log.VehiclePreviousLogId = previousLog.LogId;
|
||||
var newNextLog = SearchNextLog(log);
|
||||
if (newNextLog != null)
|
||||
{
|
||||
newNextLog.VehiclePreviousLogId = log.LogId;
|
||||
newNextLog.User = _db.Users.Find(newNextLog.User.UserId);
|
||||
_db.Entry(newNextLog).State = EntityState.Modified;
|
||||
}
|
||||
|
||||
log.User = _db.Users.Find(log.User.UserId);
|
||||
_db.Entry(log).State = EntityState.Modified;
|
||||
_db.SaveChanges();
|
||||
|
||||
@@ -83,7 +89,11 @@ namespace MileageTraker.Web.DAL
|
||||
|
||||
var nextLog = GetNextLog(log.LogId);
|
||||
if (nextLog != null)
|
||||
{
|
||||
nextLog.VehiclePreviousLog = log.VehiclePreviousLog;
|
||||
nextLog.User = _db.Users.Find(nextLog.User.UserId);
|
||||
_db.Entry(nextLog).State = EntityState.Modified;
|
||||
}
|
||||
|
||||
_db.Logs.Remove(log);
|
||||
_db.SaveChanges();
|
||||
@@ -247,11 +257,11 @@ namespace MileageTraker.Web.DAL
|
||||
return logs;
|
||||
}
|
||||
|
||||
public IEnumerable<Log> GetRecentLogsByEmployee(string employeeName)
|
||||
public IEnumerable<Log> GetRecentLogsByUsername(string username)
|
||||
{
|
||||
return
|
||||
(from l in _db.Logs
|
||||
where l.User.FullName == employeeName
|
||||
where l.User.Username == username
|
||||
orderby l.Created descending
|
||||
select l)
|
||||
.Take(3)
|
||||
|
||||
Reference in New Issue
Block a user