public async Task <SaveCheckinLogsResponse> CreateAsync() { try { var CheckinLogs = new CheckinLogsModels(); // Get User ID var Request = _accessor.HttpContext.Request; string Token = Request.Headers["Authorization"]; var jwtArr = Token.Split('.'); var PayLoad = JsonConvert.DeserializeObject <Dictionary <string, object> >(Base64UrlEncoder.Decode(jwtArr[1])); var user = await _CheckinLogsRepository.FindUserID(PayLoad["nameid"].ToString()); CheckinLogs.user_id = user.user_id; // Get Client IP WebClient webClient = new WebClient(); var user_ip = webClient.DownloadString("https://api.ipify.org"); bool in_company = user_ip.Contains(this._config["IP"]); if (in_company) { int index = user_ip.IndexOf(this._config["IP"]); if (index == 0) { CheckinLogs.ip = user_ip; } } if (CheckinLogs.ip == null) { return(new SaveCheckinLogsResponse("IP is invalid")); } await _CheckinLogsRepository.CreateAsync(CheckinLogs); return(new SaveCheckinLogsResponse(CheckinLogs)); } catch (Exception ex) { // Do some logging stuff return(new SaveCheckinLogsResponse($"An error occurred when saving the category: {ex.Message}")); } }
/// <summary> /// Creates a success response. /// </summary> /// <param name="CheckinLogs">Saved Actions.</param> /// <returns>Response.</returns> public SaveCheckinLogsResponse(CheckinLogsModels CheckinLogs) : this(true, string.Empty, CheckinLogs) { }
private SaveCheckinLogsResponse(bool success, string message, CheckinLogsModels CheckinLogs) : base(success, message) { _CheckinLogs = CheckinLogs; }
public async Task CreateAsync(CheckinLogsModels CheckinLogs) { await _context.checkin_logs.AddAsync(CheckinLogs); await _context.SaveChangesAsync(); }