public async Task <IActionResult> SaveQuestionOrder(List <OrderList> Orderlist)
        {
            var result = new ServiceResponse <ViolationQuestion>()
            {
                Success = true
            };

            try
            {
                if (Orderlist.Count > 0)
                {
                    foreach (var question in Orderlist)
                    {
                        var QuestionDetails = await _accountCtx.ViolationQuestions.SingleOrDefaultAsync(a => a.Id == question.questionID);

                        if (QuestionDetails != null)
                        {
                            //  CitationDetails.UpdateUserId = createdById;
                            QuestionDetails.UpdateUtc = DateTime.Now;
                            QuestionDetails.Order     = question.order;
                            _accountCtx.ViolationQuestions.Update(QuestionDetails);
                        }
                    }
                    await _accountCtx.SaveChangesAsync();
                }
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.Message = ex.Message;
            }


            return(Json(result));
        }
        public async Task <IActionResult> Register(RegistrationModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new IdentityUser {
                    UserName = model.UserLogin, Email = model.UserLogin
                };
                var result = await _userManager.CreateAsync(user, model.UserPassword);

                var userModel = new UsersModel {
                    UserId = user.Id, UserLogin = model.UserLogin, FirstName = model.FirstName, LastName = model.LastName, DateOfBirth = model.DateOfBirth, Gender = model.Gender.ToString(), DateOfCreation = DateTime.UtcNow
                };
                await _context.UsersModel.AddAsync(userModel);

                if (result.Succeeded)
                {
                    await _signInManager.SignInAsync(user, isPersistent : false);

                    await _context.SaveChangesAsync();

                    return(RedirectToAction("index", "home"));
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError("", error.Description);
                }
            }
            return(View(model));
        }
        public async Task <IActionResult> PutAccount(int id, Account account)
        {
            if (id != account.AccountNumber)
            {
                return(BadRequest());
            }

            _context.Entry(account).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AccountExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #4
0
        public async Task <IActionResult> PutAccount([FromRoute] string id, [FromBody] Account account)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != account.Id)
            {
                return(BadRequest());
            }

            _context.Entry(account).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AccountExists(id))
                {
                    return(NotFound(0));
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #5
0
        public async Task <IActionResult> PutTransaction(string id, Transaction transaction)
        {
            if (id != transaction.Id)
            {
                return(BadRequest());
            }

            _context.Entry(transaction).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TransactionExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #6
0
        public async Task <int> AddAsync(ProductClass productClass)
        {
            _context.ProductClass.Add(productClass);
            int result = await _context.SaveChangesAsync();

            return(result);
        }
Example #7
0
        public async Task <IActionResult> UserChat(string UserLogin)
        {
            var userValues = await _context.MessageModel.FirstOrDefaultAsync(user => user.UserFrom == User.Identity.Name && user.UserTo == UserLogin || (user.UserTo == User.Identity.Name && user.UserFrom == UserLogin));

            if (userValues == null)
            {
                _messageModel.UserTo       = UserLogin;
                _messageModel.UserFrom     = User.Identity.Name;
                _messageModel.MessageStore = string.Empty;
                _messageModel.MessageSend  = string.Empty;
            }
            else
            {
                if (userValues.UserFrom == User.Identity.Name)
                {
                    _messageModel.UserFrom     = User.Identity.Name;
                    _messageModel.UserTo       = UserLogin;
                    _messageModel.UserFromRead = true;
                    userValues.UserFromRead    = true;
                    await _context.SaveChangesAsync();
                }
                else
                {
                    _messageModel.UserFrom   = UserLogin;
                    _messageModel.UserTo     = User.Identity.Name;
                    _messageModel.UserToRead = true;
                    userValues.UserToRead    = true;
                    await _context.SaveChangesAsync();
                }
                _messageModel.MessageStore = userValues.MessageStore;
                _messageModel.MessageSend  = string.Empty;
            }
            return(View(_messageModel));
        }
        public async Task <int> AddAsync(NewsType newsType)
        {
            _context.NewsType.Add(newsType);
            int result = await _context.SaveChangesAsync();

            return(result);
        }
        public async Task <IActionResult> PutUser(int id, User user)
        {
            if (id != user.Userid)
            {
                return(BadRequest());
            }

            _context.Entry(user).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #10
0
        public async Task <ActionResult <IEnumerable <Account> > > GetAccounts()
        {
            if (_context.Accounts.Count <Account>() < 1)
            {
                _context.Accounts.Add(new Account()
                {
                    FirstName      = "Roy",
                    LastName       = "Williams",
                    DateOfBirth    = "12/01/1992",
                    Address        = "1234 Maple Ln",
                    City           = "Richmond",
                    State          = "VA",
                    ZipCode        = 23220,
                    Phone          = "555-555-5555",
                    Email          = "*****@*****.**",
                    Password       = "******",
                    CardName       = "Roy Williams",
                    CardNumber     = 1234567891011121,
                    ExpirationDate = "12/24",
                    CVV            = 345,
                    CardAddress    = "1234 Maple Ln",
                    CardCity       = "Richmond",
                    CardState      = "VA",
                    CardZipCode    = 23220,
                    CardPhone      = "555-555-5555"
                });

                await _context.SaveChangesAsync();
            }

            return(await _context.Accounts.ToListAsync());
        }
Example #11
0
        public async Task <IActionResult> Create([Bind("AccountNumber,CustomerName,Branch,JoiningDate")] Account account)
        {
            if (ModelState.IsValid)
            {
                _context.Add(account);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(account));
        }
Example #12
0
        public async Task <IActionResult> Create([Bind("UserId,Password,NicName,UserGroup,InActivity")] UserIdentity userIdentity)
        {
            if (ModelState.IsValid)
            {
                _context.Add(userIdentity);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(userIdentity));
        }
Example #13
0
        public async Task ClearNotification(string userFrom, string userTo)
        {
            var messageModel = await _context.MessageModel.FirstOrDefaultAsync(user => user.UserFrom == userFrom && user.UserTo == userTo || (user.UserTo == userFrom && user.UserFrom == userTo));

            if (messageModel != null)
            {
                messageModel.UserToRead   = true;
                messageModel.UserFromRead = true;
                await _context.SaveChangesAsync();
            }
        }
Example #14
0
        public async Task <IActionResult> Create([Bind("AccountId,AccountType,FirstName,LastName")] Account account)
        {
            if (ModelState.IsValid)
            {
                _context.Add(account);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(account));
        }
Example #15
0
        public async Task <IActionResult> Create([Bind("AccountNumber,AccountType,CustomerID,ModifyDate")] Account account)
        {
            if (ModelState.IsValid)
            {
                _context.Add(account);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CustomerID"] = new SelectList(_context.Set <Customer>(), "CustomerID", "CustomerName", account.CustomerID);
            return(View(account));
        }
Example #16
0
        public async void Test_GenericRepository_Update()
        {
            var options = new DbContextOptionsBuilder <AccountContext>()
                          .UseInMemoryDatabase(databaseName: "Test2G")
                          .Options;

            using (var ctx = new AccountContext(options))
            {
                var profiles   = new ProfileRepository(ctx);
                var payment    = new PaymentRepository(ctx);
                var newProfile = new ProfileModel()
                {
                    Id        = 0,
                    Email     = "*****@*****.**",
                    Name      = null,
                    Phone     = "1234567897",
                    Age       = "Adult",
                    AccountId = 1,
                    Account   = null
                };
                var updateProfile = new ProfileModel()
                {
                    Id        = 1,
                    Email     = "*****@*****.**",
                    Name      = null,
                    Phone     = "2222222222",
                    Age       = "Child",
                    AccountId = 1,
                    Account   = null
                };
                await profiles.Add(newProfile);

                await ctx.SaveChangesAsync();

                ctx.Entry <ProfileModel>(newProfile).State = EntityState.Detached;
                await profiles.Update(updateProfile);

                await ctx.SaveChangesAsync();

                var actual = await profiles.GetAll();

                var payments = await payment.GetAll();

                var payments2 = await payment.Find(payment => payment.AccountId == 1);

                var phone = actual.First().Phone;

                Assert.Equal("2222222222", phone);
                Assert.Empty(payments);
                Assert.Empty(payments2);
            }
        }
Example #17
0
        public async Task <IActionResult> Create([Bind("FirstName,LastName,Email,Password,ConfirmPassword")] Account account)
        {
            if (ModelState.IsValid)
            {
                account.TimeStamp = DateTime.Now;

                _context.Add(account);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(account));
        }
Example #18
0
        public async Task <bool> insertLoginInfo(LoginInfo loginInfo)
        {
            try
            {
                await _context.AddAsync(loginInfo);

                await _context.SaveChangesAsync();
            }
            catch (Exception e)
            {
                return(false);
            }
            return(true);
        }
Example #19
0
        public async Task <IActionResult> Create([Bind("Guid,UserName,Password,Role,Email,CreateTime,UpdateTime")]
                                                 Account account)
        {
            if (ModelState.IsValid)
            {
                account.Guid       = Guid.NewGuid();
                account.CreateTime = DateTime.Now;
                account.UpdateTime = DateTime.Now;
                account.Role       = UserRole.Ordinary;
                context.Add(account);
                await context.SaveChangesAsync();

                var partyMember =
                    new PartyMember(new SeriaNumber().Seria(pMContext.PartyMembers.Count() + 1, Key.PMPre))
                {
                    Guid       = Guid.NewGuid(),
                    CreateTime = DateTime.Now,
                    UpdateTime = DateTime.Now
                };
                pMContext.Add(partyMember);
                await pMContext.SaveChangesAsync();

                var accountPartyMember =
                    new AccountPartyMember(account.UserName, partyMember.PartyMemberID)
                {
                    Guid       = Guid.NewGuid(),
                    CreateTime = DateTime.Now,
                    UpdateTime = DateTime.Now
                };
                aPMContext.Add(accountPartyMember);
                await aPMContext.SaveChangesAsync();

                var partyCost =
                    new PartyCost(new SeriaNumber().Seria(pCContext.PartyCosts.Count() + 1, Key.PCPre),
                                  partyMember.PartyMemberID)
                {
                    Guid       = Guid.NewGuid(),
                    CreateTime = DateTime.Now,
                    UpdateTime = DateTime.Now,
                    State      = Verify.Unaudited
                };
                pCContext.Add(partyCost);
                await pCContext.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            return(View(account));
        }
Example #20
0
        public async void Test_GenericRepository_Find()
        {
            var options = new DbContextOptionsBuilder <AccountContext>()
                          .UseInMemoryDatabase(databaseName: "Test1G")
                          .Options;

            using (var ctx = new AccountContext(options))
            {
                var profiles   = new ProfileRepository(ctx);
                var newProfile = new ProfileModel()
                {
                    Id        = 10,
                    Email     = "*****@*****.**",
                    Name      = null,
                    Phone     = "1234567897",
                    Age       = "Adult",
                    AccountId = 1,
                    Account   = null
                };
                await profiles.Add(newProfile);

                await ctx.SaveChangesAsync();

                var actual = await profiles.Find(profile => profile.AccountId == 1);

                var phone = actual.First().Phone;

                Assert.Equal("1234567897", phone);
            }
        }
        public async Task <bool> AddOperationsHistory(AddTransaction message)
        {
            OperationHistoryEntity operationHistory1 = new OperationHistoryEntity();
            OperationHistoryEntity operationHistory2 = new OperationHistoryEntity();

            operationHistory1.AccountId = message.FromAccount;
            var b = await _context.Accounts.FirstOrDefaultAsync(b => b.AccountId == message.FromAccount).ConfigureAwait(false);

            operationHistory1.Balance           = b.Balance;
            operationHistory1.CreditOrDebit     = false;
            operationHistory1.Date              = DateTime.Now;
            operationHistory1.Id                = Guid.NewGuid();
            operationHistory1.TransactionAmount = message.Amount;
            operationHistory1.TransactionId     = message.TransactionId;

            operationHistory2.AccountId = message.ToAccount;
            var b2 = await _context.Accounts.FirstOrDefaultAsync(b => b.AccountId == message.ToAccount).ConfigureAwait(false);

            operationHistory2.Balance           = b2.Balance;
            operationHistory2.CreditOrDebit     = true;
            operationHistory2.Date              = DateTime.Now;
            operationHistory2.Id                = Guid.NewGuid();
            operationHistory2.TransactionAmount = message.Amount;
            operationHistory2.TransactionId     = message.TransactionId;

            await _context.OperationHistoryEntity.AddAsync(operationHistory1);

            await _context.OperationHistoryEntity.AddAsync(operationHistory2);

            await _context.SaveChangesAsync();

            return(true);
        }
        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);
            }
        }
Example #23
0
        public async Task <ResponseModel> Add(Banner banner)
        {
            _context.Banner.Add(banner);
            int i = await _context.SaveChangesAsync();

            if (i > 0)
            {
                return new ResponseModel {
                           code = 200, result = "广告图添加成功"
                }
            }
            ;
            return(new ResponseModel {
                code = 0, result = "广告图添加失败"
            });
        }
Example #24
0
        public async Task <ClientDTO> CreateClientAsync(CreateClientCommand command, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var client = new Client
            {
                Name   = command.Name,
                Age    = command.Age,
                Gender = command.Gender
            };

            _context.Clients.Add(client);
            await _context.SaveChangesAsync(cancellationToken);

            return(client.ToDTO());
        }
Example #25
0
        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));
        }
Example #26
0
        public async Task <int> AddNewAccountsAsync(IEnumerable <Account> accounts)
        {
            var existingAccounts = GetAllDbAccounts();

            var newAccounts = accounts
                              .Where(a => !existingAccounts.Any(ea => ea.Id == a.Id))
                              .ToList();

            await _accountContext.AddRangeAsync(newAccounts.Select(na => na.ToDataModel()));

            _logger.LogDebug($"Added {newAccounts.Count} new accounts");

            await _accountContext.SaveChangesAsync();

            return(newAccounts.Count);
        }
Example #27
0
        public async Task ExecuteAsync(CreateAccount cmd)
        {
            var validator        = new CreateAccountValidator(_context);
            var validationResult = validator.Validate(cmd);

            CommandHandlerException.ThrowIsNotValid("Ошибочные значения параметров", validationResult);

            var existsAccount = await _context.Accounts.Where(a => a.IP == cmd.IP)
                                .OrderByDescending(a => a.CreatedAt)
                                .FirstOrDefaultAsync();

            var currentDateTime = DateTime.Now;
            var allowedInterval = _config.Value.AllowedIntervalInSeconds;

            if (existsAccount != null && currentDateTime.Subtract(existsAccount.CreatedAt).Seconds < allowedInterval)
            {
                var ex = new CommandHandlerException(403, $"С одного IP разрешено регистрироваться не более одного раза в {allowedInterval} сек.");
                _loggerService.LogError(ex, ex.Message);
                throw ex;
            }

            var account = new Account(currentDateTime,
                                      cmd.IP,
                                      cmd.Email.ToLower(),
                                      _passwordService.GetSha256Hash(cmd.Password),
                                      cmd.Country,
                                      cmd.Province);

            _context.Accounts.Add(account);

            await _context.SaveChangesAsync();

            _domainEventDispatcher.Raise(new CreatedAccountEvent(account));
        }
Example #28
0
        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));
        }
Example #29
0
        public async Task HandleAsync(AddTransaction command)
        {
            var account = await _context.Accounts.SingleOrDefaultAsync(x => x.Id == command.AccountId);

            account.AddTransaction(command);
            await _context.SaveChangesAsync();
        }
Example #30
0
        public async Task HandleAsync(DeleteAccount command)
        {
            var account = await _context.Accounts.SingleOrDefaultAsync(x => x.Id == command.Id);

            _context.Accounts.Remove(account);
            await _context.SaveChangesAsync();
        }