public async Task LogLoginAttempt(string username, string userAgentString, string publicIp, LoginStatus status) { var clientInfo = Parser.GetDefault().Parse(userAgentString); var loginAttemptDto = new LoginAttemptDto { Username = username, Device = clientInfo.Device.Family, Os = clientInfo.OS.Family, Browser = clientInfo.UA.Family, PublicIp = publicIp, DateAndTime = DateTime.Now, Status = status }; try { loginAttemptDto.Location = _mapper.Map <LoginLocationDto>(await _ipStackClient.GetLocation(publicIp)); await _context.LoginAttempt.AddAsync(_mapper.Map <LoginAttemptEntity>(loginAttemptDto)); await _context.SaveChangesAsync(); } catch (Exception) { await _context.LoginAttempt.AddAsync(_mapper.Map <LoginAttemptEntity>(loginAttemptDto)); await _context.SaveChangesAsync(); } }
public async Task <ResultDto> UploadAccountImageAsync(int id, string name, byte[] data) { try { var accountEntity = await _context.Account.Include(a => a.Image).FirstAsync(a => a.Id.Equals(id)); _context.Attach(accountEntity); if (accountEntity.Image != null) { accountEntity.Image.Name = name; accountEntity.Image.Data = data; } else { accountEntity.Image = new AccountImageEntity { Data = data, Name = name }; } await _context.SaveChangesAsync(); return(GenerateResultDto("Image uploaded successfully", "Your image is now visible on your account tab.", ResultDtoStatus.Successful)); } catch { return(GenerateResultDto("Image not uploaded", "Something went wrong on my side, try again later", ResultDtoStatus.Unsuccessful)); } }
public async Task <TResponse> Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate <TResponse> next) { using (var transaction = _context.Database.BeginTransaction()) { var response = await next(); await _context.SaveChangesAsync(cancellationToken); transaction.Commit(); return(response); } }
protected async Task LogContentAdditionAsync(string title, int accountId, ContentType type, int foreignId, int systemId) { var account = await _context.Account.FirstAsync(a => a.Id.Equals(accountId)); if (account.AddedContent == null) { account.AddedContent = new List <AddedContentEntity>(); } _context.Attach(account); account.AddedContent.Add(new AddedContentEntity { ForeignId = foreignId, SystemId = systemId, Title = title, DateAdded = DateTime.Now, Status = ContentStatus.Queued, Account = account, Type = type }); await _context.SaveChangesAsync(); }