public static DoorAccessLogViewModel GetViewModel(this DoorAccessLog doorAccessLogObject) { var doorAccessLogViewModel = new DoorAccessLogViewModel(); if (doorAccessLogObject != null) { doorAccessLogViewModel.AccessDenied = doorAccessLogObject.accessdenied ?? true; doorAccessLogViewModel.Date = doorAccessLogObject.date ?? DateTime.Now; doorAccessLogViewModel.Door = doorAccessLogObject.Door.GetViewModel(); doorAccessLogViewModel.User = doorAccessLogObject.User.GetViewModel(); doorAccessLogViewModel.Status = doorAccessLogObject.state ?? true; } return(doorAccessLogViewModel); }
// DoorAccessLog repo public void LogAccessToDoorByUser(int doorId, int userId, bool locked, bool accessDenied) { try { var doorAccessLog = new DoorAccessLog() { date = DateTime.Now, accessdenied = accessDenied, state = locked, userid = userId, doorid = doorId }; doorAccessLogRepo.Insert(doorAccessLog); doorAccessLogRepo.Save(); } catch (Exception ex) { Console.Write(ex.Message); } }