public async void Test_Repository_SelectAsync_ById(int id) { using (var ctx = new AccountContext(options)) { var accounts = new Repository <AccountModel>(ctx); var actual = await accounts.SelectAsync(e => e.EntityId == id); Assert.NotNull(actual); } using (var ctx = new AccountContext(options)) { var profiles = new Repository <ProfileModel>(ctx); var actual = await profiles.SelectAsync(e => e.EntityId == id); Assert.NotNull(actual); } using (var ctx = new AccountContext(options)) { var addresses = new Repository <AddressModel>(ctx); var actual = await addresses.SelectAsync(e => e.EntityId == id); Assert.NotNull(actual); } }
public async void Test_Repository_DeleteAsync() { using (var ctx = new AccountContext(options)) { var profiles = new Repository <ProfileModel>(ctx); var profile = await ctx.Profiles.FirstAsync(); await profiles.DeleteAsync(profile.EntityId); Assert.Equal(EntityState.Deleted, ctx.Entry(profile).State); } using (var ctx = new AccountContext(options)) { var addresses = new Repository <AddressModel>(ctx); var address = await ctx.Addresses.FirstAsync(); await addresses.DeleteAsync(address.EntityId); Assert.Equal(EntityState.Deleted, ctx.Entry(address).State); } using (var ctx = new AccountContext(options)) { var accounts = new Repository <AccountModel>(ctx); var account = await ctx.Accounts.FirstAsync(); await accounts.DeleteAsync(account.EntityId); Assert.Equal(EntityState.Deleted, ctx.Entry(account).State); } }
public ActionResult Index(int bankId) { AccountContext accountContext = new AccountContext(); List <Account> accounts = accountContext.Accounts.Where(ac => ac.BankId == bankId).ToList(); return(View(accounts)); }
public async Task <ActionResult> Signup([FromForm] Account account) { AccountContext accountContext = HttpContext.RequestServices.GetService(typeof(dotNet期末项目.Models.AccountContext)) as AccountContext; //如果该用户名已被注册 if (await accountContext.SelectOne(account.Username) != null) { return(BadRequest("用户名已存在")); } /* * 【说明】此处用 await 执行 addAccount 函数时,不会同步执行后面的 if(result) 语句,而是说执行该请求的线程能同时执行其他的而请求。 */ bool result = await accountContext.AddAcount(account); if (result) { //创建默认头像 string source = Path.Combine(_hostingEnvironment.WebRootPath, "img", "avator.jpg"); string dest = Path.Combine(_hostingEnvironment.WebRootPath, "avator", account.Username + ".jpg"); System.IO.File.Copy(source, dest, true); return(Ok("成功注册账号")); } return(StatusCode(500, "数据库错误")); }
public ActionResult Index() { AccountContext accountContext = new AccountContext(); List <Customer> customers = accountContext.Customers.ToList(); return(View(customers)); }
public HomeController(LogContext context, IAmazonSageMakerRuntime SageMakerClient, AccountContext accountContext) { _context = context; _SageMakerClient = SageMakerClient; _accountContext = accountContext; ipStackClient = new IpStackClient(Environment.GetEnvironmentVariable("IPSTACK_API_KEY")); }
public ActionResult Index() { AccountContext accountContext = new AccountContext(); List <Employee> employees = accountContext.Employees.ToList(); return(View(employees)); }
public void Enter(SyncSession session, GateEnterRequest request) { if (_gate.Id != request.Gate) { NetworkUtils.DropBadAction(); } if (!_relay.Session.Contains(new RGSSessionContainsRequest { Account = request.Account, Key = request.SessionKey }).Result) { NetworkUtils.DropBadAction(); } { using AccountContext context = _accountFactory.CreateDbContext(); AccountModel model = context.Accounts.AsNoTracking().First(c => c.Id == request.Account); session.Account = new(model); session.Characters = GetCharacters(model, request.Gate); session.Background = model.CharacterBackground; session.Permission = HandlerPermission.Authorized; } session.SendAsync(new GateEnterResponse() { AccountId = request.Account, Result = GateEnterResult.Success }); session.SendAsync(new SWorldCurrentDataResponse()); }
public void Enter(Session session, GateEnterRequest request) { if (_gate.Id != request.Gate) { NetworkUtils.DropSession(); } if (!_relayClient.Session.Validate(new() { Account = request.Account, Key = request.SessionKey }).Result) { NetworkUtils.DropSession(); } { using AccountContext context = _accountFactory.CreateDbContext(); AccountModel model = context.Accounts.AsNoTracking().First(c => c.Id == request.Account); session.Account = new(model); session.Characters = GetCharacters(model, request.Gate); session.Background = model.CharacterBackground; } session.SendAsync(new GateEnterResponse() { AccountId = request.Account, Result = GateEnterResult.Success }); session.SendAsync(new ServiceCurrentDataResponse()); }
public AttachmentController(CommonContext commonContext, RedisCache cache, IOptions <AppSettings> appSettings, AccountContext accountCtx, FileService _fileService) : base(commonContext, cache, appSettings) { _accountCtx = accountCtx; fileService = _fileService; _appSettings = appSettings.Value; }
public CitizensController(CommonContext commonContext, IServiceProvider serviceProvider, RedisCache redisCache, IOptions <AppSettings> appSettings, AccountContext accountCtx) : base(commonContext, serviceProvider, redisCache, appSettings) { _commonContext = commonContext; _appSettings = appSettings.Value; _accountCtx = accountCtx; }
public async Task <User> ResetPassword(int id, string newPassword) { using (var db = new AccountContext()) { if (!UserExists(id)) { return(null); } var user = await db.Users.FindAsync(id); user.Password = getHashedPassword(newPassword); db.Entry(user).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserExists(user.UserId)) { return(null); } else { throw; } } return(user); } }
public async Task <User> Put(User user) { using (var db = new AccountContext()) { db.Entry(user).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserExists(user.UserId)) { return(null); } else { throw; } } return(user); } }
public async void Test_Repository_SelectAsync_ById() { await _connection.OpenAsync(); try { using (var ctx = new AccountContext(_options)) { await ctx.Database.EnsureCreatedAsync(); } using (var ctx = new AccountContext(_options)) { var lodgings = new Repository <AccountModel>(ctx); var actual = await lodgings.SelectAsync(1); Assert.Null(actual); } using (var ctx = new AccountContext(_options)) { var profiles = new Repository <ProfileModel>(ctx); var actual = await profiles.SelectAsync(1); Assert.Null(actual); } } finally { await _connection.CloseAsync(); } }
public ActionResult Details(int id) { AccountContext accountContext = new AccountContext(); Employee employee = accountContext.Employees.Single(emp => emp.EmployeeID == id); return(View(employee)); }
public IEnumerable <User> GetList() { using (var db = new AccountContext()) { return(db.Users.ToList()); } }
public async Task <IActionResult> CreatePayment(PaymentViewModel model) { ValidateCreatePayment(model); if (ModelState.IsValid) { var accountDetail = await CommonContext.CommonAccounts.Include(m => m.Partition).SingleOrDefaultAsync(account => account.Id == model.AccountId); _accountCtx = ContextsUtility.CreateAccountContext(Cryptography.Decrypt(accountDetail.Partition.ConnectionString)); var citation = await GetCitation(model.AccountId, model.CitationId); var citationPayment = Mapper.Map <CitationPayment>(model); citationPayment.AccountId = accountDetail.Id; citationPayment.CreateUtc = DateTime.UtcNow; citationPayment.UpdateUtc = DateTime.UtcNow; citationPayment.CreateUserId = citation.CreateUserId; citationPayment.UpdateUserId = citation.CreateUserId; citation.Payments.Add(citationPayment); //Calcualte the new balance. citation.Balance = citation.Payments.Select(m => m.ChargeAmount).Sum(); await _accountCtx.SaveChangesAsync(); return(RedirectToAction("Citation", new { id = model.CitationId, accountId = model.AccountId })); } return(View(model)); }
public async void Test_UnitOfWork_CommitAsync() { await _connection.OpenAsync(); try { using (var ctx = new AccountContext(_options)) { await ctx.Database.EnsureCreatedAsync(); } using (var ctx = new AccountContext(_options)) { var unitOfWork = new UnitOfWork(ctx); await unitOfWork.Complete(); Assert.NotNull(unitOfWork.AccountRepository); Assert.NotNull(unitOfWork.ProfileRepository); Assert.NotNull(unitOfWork.PaymentRepository); } } finally { await _connection.CloseAsync(); } }
public async Task <IActionResult> EditPayment(PaymentViewModel model) { if (ModelState.IsValid) { var accountDetail = await CommonContext.CommonAccounts.Include(m => m.Partition).SingleOrDefaultAsync(account => account.Id == model.AccountId); _accountCtx = ContextsUtility.CreateAccountContext(Cryptography.Decrypt(accountDetail.Partition.ConnectionString)); var payment = await _accountCtx.CitationPayments.Include(m => m.Citation).ThenInclude(m => m.Payments).Where(m => m.Id == model.Id).SingleAsync(); payment.ChargeAmount = model.ChargeAmount; payment.CitationFineAmount = model.CitationFineAmount; payment.ProcessingFee = model.ProcessingFee; payment.Status = model.Status; payment.ChargeId = model.ChargeId; payment.Citation.Balance = payment.Citation.Payments.Select(m => m.ChargeAmount).Sum(); await _accountCtx.SaveChangesAsync(); return(RedirectToAction("Citation", new { id = model.CitationId, accountId = model.AccountId })); } return(View(model)); }
public AccountContext GetAccountContext(long?accountNumber) { var accountCtx = new AccountContext(new DbContextOptions <AccountContext>()); if (accountNumber != null) { //TODO: We have to be able to cache this info somehow. var commonAccount = _commonContext.CommonAccounts .Include(ca => ca.Partition) .Where(ca => ca.Number == accountNumber) .AsNoTracking() .SingleOrDefault(); if (commonAccount != null) { // Dispose the one we created at the top of this method. accountCtx.Dispose(); // Create a new context using the partition's connection string. accountCtx = ContextsUtility.CreateAccountContext(Cryptography.Decrypt(commonAccount.Partition.ConnectionString)); } } return(accountCtx); }
SearchResultResponse IAccountRepository.GetAccounts(AccountListType type, AccountContext context, ISearchRepository searchRepository) { var searchService = new SearchService(searchRepository); var searchFilter = new SearchFilter() { SearchType = SearchType.Account, IncludedTemplateList = new List <string>() { "{C575A4FF-AB06-46C1-B78C-70C65DC6374C}" } }; var fieldList = new Dictionary <string, string>(); switch (context) { case AccountContext.Event: fieldList.Add("Events", ""); searchFilter.FieldValueList = fieldList; return(searchService.GetSearchResults(searchFilter)); case AccountContext.UserGroup: fieldList.Add("Groups", ""); searchFilter.FieldValueList = fieldList; return(searchService.GetSearchResults(searchFilter)); case AccountContext.Account: return(searchService.GetSearchResults(searchFilter)); } return(new SearchResultResponse()); }
public override string[] GetRolesForUser(string username) { string[] roles = new string[] { }; using (var db = new AccountContext()) { try { // Получаем пользователя var user = (from u in db.Users from l in db.Logins where l.UserLogin == username && u.Login == l select u).FirstOrDefault(); //User user = (from u in db.Users // where u.Login == username // select u).FirstOrDefault(); if (user != null) { // получаем роль Role userRole = db.Roles.Find(user.RoleId); if (userRole != null) { roles = new string[] { userRole.Name }; } } } catch { roles = new string[] { }; } } return(roles); }
public void TestMaakAccountAan() { AccountContext context = new AccountContext(); Registreren registereer = new Registreren { Email = "*****@*****.**", Wachtwoord = "wachtwoord", Gebruikersnaam = "unittest" }; try { context.Insert(registereer); } catch (DuplicateNameException) { } Account account = new Account { Email = "*****@*****.**", Wachtwoord = "wachtwoord", }; Account accountOphalen = context.Select(account); Assert.IsNotNull(accountOphalen); }
public ActionResult Details(int Id) { AccountContext accountContext = new AccountContext(); Account account = accountContext.Accounts.Single(acc => acc.CardNumber == Id); return(View(account)); }
public UnitOfWork(AccountContext context) { _context = context; Account = new Repository <AccountModel>(context); Profile = new Repository <ProfileModel>(context); }
public AccountService(AccountContext _accountContext) { if (this._accountContext == null) { this._accountContext = _accountContext; } }
public TasksController(LogContext logContext, AccountContext accountContext, IAmazonSimpleEmailService SESClient, IAmazonSimpleNotificationService SNSClient) { _logContext = logContext; _accountContext = accountContext; _SESClient = SESClient; _SNSClient = SNSClient; }
public async void Test_Repository_Update(string email, string city) { using (var ctx = new AccountContext(options)) { var profiles = new Repository <ProfileModel>(ctx); var profile = await ctx.Profiles.FirstAsync(); profile.Email = email; profiles.Update(profile); var result = ctx.Profiles.Find(profile.EntityId); Assert.Equal(profile.Email, result.Email); Assert.Equal(EntityState.Modified, ctx.Entry(result).State); } using (var ctx = new AccountContext(options)) { var addresses = new Repository <AddressModel>(ctx); var address = await ctx.Addresses.FirstAsync(); address.City = city; addresses.Update(address); var result = ctx.Addresses.Find(address.EntityId); Assert.Equal(address.City, result.City); Assert.Equal(EntityState.Modified, ctx.Entry(result).State); } }
/// <summary> /// Increment customer sequence value /// </summary> /// <param name="customerIdentifier"></param> /// <returns>next sequence value by customer identifier</returns> /// <remarks> /// What is not covered, resetting back to null when the sequence number reaches /// 999. To reset, in the else check if IncrementAlphaNumericValue returns "999" if /// so then set sequenceValue as done in the if e.g. /// sequenceValue = $"{customerSequence?.SequencePreFix}0001"; /// That's it. /// </remarks> public static string GetCustomerNextSequenceValue(int customerIdentifier) { using (var context = new AccountContext()) { Customers result = context.Customers .Include(customer => customer.CustomerSequence) .FirstOrDefault(customer => customer.CustomerIdentifier == customerIdentifier); CustomerSequence customerSequence = result?.CustomerSequence.FirstOrDefault(); var sequenceValue = ""; if (string.IsNullOrWhiteSpace(customerSequence?.CurrentSequenceValue)) { sequenceValue = $"{customerSequence?.SequencePreFix}0001"; } else { sequenceValue = StringHelpers.IncrementAlphaNumericValue($"{customerSequence.CurrentSequenceValue}"); } // ReSharper disable once PossibleNullReferenceException customerSequence.CurrentSequenceValue = sequenceValue; context.SaveChanges(); return(sequenceValue); } }
public async Task <User> Get(int id) { using (var db = new AccountContext()) { return(await db.Users.FindAsync(id)); } }
/// <summary> /// Initializes a new instance of the <see cref="CurrentUserContext"/> class. /// </summary> /// <param name="agencyContext">The agency context.</param> /// <param name="locationContext">The location context.</param> /// <param name="staffContext">The staff context.</param> /// <param name="accountContext">The account context.</param> public CurrentUserContext( AgencyContext agencyContext, LocationContext locationContext, StaffContext staffContext, AccountContext accountContext ) { Agency = agencyContext; Location = locationContext; Staff = staffContext; Account = accountContext; }
public MyAccountController(AccountContext context) { Assert.NotNull(context); _context = context; }