public PageResult <object> FindByAffectedUser(ODataQueryOptions <UserHistoryDto> options, string searchTerm, int userK) { var userHistories = new List <UserHistoryDto>(); var systemLogs = systemLogService.FindByAffectedUser(searchTerm, userK); foreach (var systemLog in systemLogs) { var user = systemLog.UserFK != null?userService.Read(systemLog.UserFK.Value) : null; foreach (var item in systemLog.SystemLogItems) { if (item.FieldName != "ModifiedAtUtc" && item.FieldName != "ModifiedByUserFK" && item.FieldName != "CreatedByUserFK" && item.FieldName != "CreatedAtUtc") { var userHistory = new UserHistoryDto(); userHistory.DateTime = systemLog.TimestampUtc.ToLocalTime(); userHistory.FieldName = item.FieldName; userHistory.PreChangeValue = item.PreChangeValue; userHistory.PostChangeValue = item.PostChangeValue; userHistory.ChangedBy = user != null ? (user.FirstName + " " + user.LastName) : "N/A"; userHistories.Add(userHistory); } } } return(ApplyPaging(options, userHistories.AsQueryable())); }
public static UserHistory ToUserHistory(this UserHistoryDto @this) => new UserHistory { Id = @this.UserId, Name = @this.Name, LocationHistory = @this.LocationHistory.Coordinates.Positions.Select(p => new Location { Latitude = p.Latitude, Longitude = p.Longitude }) };
public static string InserUserHistoryEventSql(UserHistoryDto userHistortyDto) { return($@"INSERT INTO USER_HISTORY ( USER_ID, EVENT_DATE, DESCRIPTION, USER_HISTORY_TYPE_ID ) VALUES ( {userHistortyDto.UserId}, '{userHistortyDto.EventDate.ToString("yyyy-MM-dd hh:mm:ss")}', '{userHistortyDto.Description}', {userHistortyDto.UserHistoryTypeId} )"); }
public HttpResponseMessage ExportUserHistoryToCsv(int userK) { var userHistories = new List <UserHistoryDto>(); var systemLogs = systemLogService.FindByAffectedUser(null, userK); foreach (var systemLog in systemLogs) { var user = systemLog.UserFK != null?userService.Read(systemLog.UserFK.Value) : null; foreach (var item in systemLog.SystemLogItems) { if (item.FieldName != "ModifiedAtUtc" && item.FieldName != "ModifiedByUserFK" && item.FieldName != "CreatedByUserFK" && item.FieldName != "CreatedAtUtc") { var userHistory = new UserHistoryDto(); userHistory.DateTime = systemLog.TimestampUtc.ToLocalTime(); userHistory.FieldName = item.FieldName; userHistory.PreChangeValue = item.PreChangeValue; userHistory.PostChangeValue = item.PostChangeValue; userHistory.ChangedBy = user != null ? (user.FirstName + " " + user.LastName) : "N/A"; userHistories.Add(userHistory); } } } var csv = new CsvExport(); foreach (var userHistory in userHistories) { csv.AddRow(); csv["Date Time"] = userHistory.DateTime.ToString("dd-MMM-yyyy hh:mm tt"); csv["Field Name"] = userHistory.FieldName; csv["Pre Change Value"] = userHistory.PreChangeValue; csv["Post Change Value"] = userHistory.PostChangeValue; csv["Changed By"] = userHistory.ChangedBy; } var result = new HttpResponseMessage(HttpStatusCode.OK) { Content = new ByteArrayContent(csv.ExportToBytes()) }; result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = "User_" + userK + "_Histories_" + DateTime.UtcNow.ToLocalTime().ToString("MMddyyyy_hhmm") + ".csv" }; return(result); }
public async Task <IActionResult> GetUserHistory(string userId) { if (userId != null) { var history = await _diag.GetUserHistoryByUserId(userId); List <UserHistoryDto> AllHistoryMapped = new List <UserHistoryDto>(); foreach (var item in history) { var historyMapped = new UserHistoryDto(); historyMapped.DrugName = item.Drug.DrugName; historyMapped.SymptomName = item.Symptom.SymptomName; historyMapped.TimeCreated = item.TimeCreated; historyMapped.BodyAreasName = item.BodyAreas.NameArea; historyMapped.RequestId = item.RequestId; AllHistoryMapped.Add(historyMapped); } return(Ok(AllHistoryMapped)); } return(BadRequest("Cheak Your Object")); }
public User Authorize(string login, string password) { UserHistoryDto historyItem = null; User user = null; try // TODO Introduce custom exception { if (string.IsNullOrWhiteSpace(login) || string.IsNullOrWhiteSpace(password)) { throw new Exception("Empty login atempt"); } var salt = _userDao.GetSaltForUser(login); if (string.IsNullOrWhiteSpace(salt)) { throw new Exception("Invalid user"); } var hash = _hashService.HashString(password, salt); var userDto = _userDao.Authorize(new UserCredential { Hash = hash.hash, Login = login }); if (userDto == null) { throw new Exception("Invalid user"); } historyItem = new UserHistoryDto { UserId = userDto.UserId, EventDate = DateTime.Now, Description = "User Authorized", UserHistoryTypeId = 1 }; user = User.FromDto(userDto); } catch (Exception e) { historyItem = new UserHistoryDto { UserId = 0, EventDate = DateTime.Now, Description = e.Message, UserHistoryTypeId = 2 }; user = null; } finally { _userDao.SaveUserHistoryEvent(historyItem); } return(user); }
public void SaveUserHistoryEvent(UserHistoryDto userHistoryDto) { NonResultQuerry(UserSql.InserUserHistoryEventSql(userHistoryDto)); }