public async Task <IActionResult> Index()
        {
            //Get a list of Accounts for a user
            var userAccount = await CommonContext.UserAccounts.Include(m => m.Account).ThenInclude(m => m.Partition).Where(m => m.UserId == User.GetLoggedInUserId().Value).ToListAsync();

            var citations = new List <Citation>();

            //CitationListModel model = new CitationListModel();


            //Loop through each AccountContext for this user and get a list of Citations
            foreach (var commonAccount in userAccount)
            {
                //Get the correct account database based on the partition that was chosen for the account.
                var accountCtx = ContextsUtility.CreateAccountContext(Cryptography.Decrypt(commonAccount.Account.Partition.ConnectionString));

                var citationsForAccount = accountCtx.Citations.Include(x => x.Account)
                                          .Include(x => x.Violation)
                                          .Include(x => x.AssignedTo)
                                          .Include(m => m.Attachments).ThenInclude(m => m.Attachment)
                                          .OrderByDescending(x => x.CreateUtc)
                                          .Where(m => m.AccountId == commonAccount.AccountId)
                                          .AsQueryable();

                citations.AddRange(citationsForAccount);
                // citations.AddRange(new CitationListModel { AccountId= citationsForAccount. });
            }

            CitationListViewModel model = new CitationListViewModel();

            model.CitationList = Mapper.Map <List <CitationListModel> >(citations);
            model.AccountList  = Mapper.Map <List <AccountUserList> >(userAccount);
            return(View(model));
        }
Example #2
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));
        }
        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);
        }
Example #4
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 #5
0
        private async Task <AccountContext> GetAccountContext(Guid accountId)
        {
            var accountDetail = await CommonContext.CommonAccounts.Include(m => m.Partition).SingleOrDefaultAsync(account => account.Id == accountId);

            var _accountCtx = ContextsUtility.CreateAccountContext(Cryptography.Decrypt(accountDetail.Partition.ConnectionString));

            return(_accountCtx);
        }
Example #6
0
        public async Task <IActionResult> Update([FromBody] CitationStatus status, long accountNum, long citationNumber)
        {
            var commonAccount = await CommonContext.CommonAccounts.AsNoTracking()
                                .Include(m => m.Partition)
                                .Where(m => m.Number == accountNum)
                                .SingleOrDefaultAsync();

            if (commonAccount == null)
            {
                _logger.Error($"CommonAccount is null.  Could not find accountNum:{accountNum}");

                return(ErrorResult(Common.Enums.ErrorCode.PreconditionFailed, "Invalid request"));
            }

            var accountCtx = ContextsUtility.CreateAccountContext(Cryptography.Decrypt(commonAccount.Partition.ConnectionString));

            if (accountCtx == null)
            {
                _logger.Error($"Could not load AccountCtx for accountNum:{accountNum}");

                return(ErrorResult(Common.Enums.ErrorCode.Server, "Cannot load account context."));
            }

            var citation = await accountCtx.Citations.ForAccount(commonAccount.Id).Where(m => m.CitationNumber == citationNumber).SingleOrDefaultAsync();

            if (citation == null)
            {
                _logger.Error($"Citation.Id:{citationNumber} cannot be found.");

                return(ErrorResult(Common.Enums.ErrorCode.PreconditionFailed, "Citation cannot be found for this account."));
            }


            //Only change status if it's different.
            if (status != citation.Status)
            {
                var oldStatus = citation.Status.ToString();

                citation.Status    = status;
                citation.UpdateUtc = DateTime.UtcNow;
                citation.Comments.Add(new CitationComment()
                {
                    AccountId = commonAccount.Id, CitationId = citation.Id, IsPublic = false, Comment = $"Exteral system status change from {oldStatus} to {status.ToString()}", CreateUserId = citation.CreateUserId, UpdateUserId = citation.CreateUserId
                });

                await accountCtx.SaveChangesAsync();

                accountCtx.Dispose();
            }

            return(Ok(new APIResponse <string>()
            {
                Message = "Status updated."
            }));
        }
        private async Task <Citation> GetCitation(Guid accountId, Guid citationId)
        {
            var accountDetail = await CommonContext.CommonAccounts.Include(m => m.Partition).SingleOrDefaultAsync(account => account.Id == accountId);

            _accountCtx = ContextsUtility.CreateAccountContext(Cryptography.Decrypt(accountDetail.Partition.ConnectionString));
            var citaion = await _accountCtx.Citations.ForAccount(accountId)
                          .Include(m => m.Attachments).ThenInclude(m => m.Attachment)
                          .Include(m => m.Payments)
                          .Where(m => m.Id == citationId).SingleOrDefaultAsync();

            return(citaion);
        }
Example #8
0
        public async Task <IActionResult> EditPayment(Guid id, Guid accountId)
        {
            var accountDetail = await CommonContext.CommonAccounts.Include(m => m.Partition).SingleOrDefaultAsync(account => account.Id == accountId);

            _accountCtx = ContextsUtility.CreateAccountContext(Cryptography.Decrypt(accountDetail.Partition.ConnectionString));

            var payment = await _accountCtx.CitationPayments.Where(m => m.Id == id).SingleAsync();

            var model = Mapper.Map <PaymentViewModel>(payment);

            return(View(model));
        }
        public async Task <IActionResult> Citations([FromBody] CitationModel model, Guid Id)
        {
            var response = new APIResponse <CitationModel>()
            {
                Success = true
            };

            try
            {
                var currentPageNum = model.Page;
                var offset         = (model.PageSize * currentPageNum) - model.PageSize;

                //Get a list of Accounts for a user
                var userAccount = await CommonContext.UserAccounts.Include(m => m.Account).ThenInclude(m => m.Partition).Where(m => m.UserId == Id).ToListAsync();

                var citations = new List <Citation>();

                //Loop through each AccountContext for this user and get a list of Citations
                foreach (var commonAccount in userAccount)
                {
                    //Get the correct account database based on the partition that was chosen for the account.
                    var accountCtx = ContextsUtility.CreateAccountContext(Cryptography.Decrypt(commonAccount.Account.Partition.ConnectionString));

                    var citationsForAccount = accountCtx.Citations.Include(x => x.Violation)
                                              .Include(x => x.AssignedTo)
                                              .Include(x => x.Comments).Include(m => m.CreateUser)
                                              .Include(x => x.Attachments).ThenInclude(m => m.Attachment)
                                              .OrderByDescending(x => x.CreateUtc)
                                              .Where(m => m.AccountId == commonAccount.AccountId).AsQueryable();

                    citations.AddRange(citationsForAccount);
                }


                var totalQueryCount = citations.Count();
                var results         = citations.Skip(offset).Take(model.PageSize).ToList();
                var data            = Mapper.Map <List <CitationListModel> >(results);
                model.CitationList = data;
                model.CurrentPage  = currentPageNum;
                model.ItemsPerPage = model.PageSize;
                model.TotalItems   = totalQueryCount;
                response.Data      = model;
                response.Success   = true;
                return(Ok(response));
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
                return(Ok(response));
            }
        }
Example #10
0
        public async Task <IActionResult> CreatePayment(Guid citationId, Guid accountId)
        {
            var accountDetail = await CommonContext.CommonAccounts.Include(m => m.Partition).SingleOrDefaultAsync(account => account.Id == accountId);

            _accountCtx = ContextsUtility.CreateAccountContext(Cryptography.Decrypt(accountDetail.Partition.ConnectionString));

            var citation = await GetCitation(accountId, citationId);

            var model = new PaymentViewModel {
                CitationId = citationId, AccountId = accountId, CitationFineAmount = citation.Balance.HasValue? citation.Balance.Value : 0f
            };

            return(View(model));
        }
        public async Task <IActionResult> Find(FindTicketViewModel model)
        {
            if (ModelState.IsValid)
            {
                var accountDetail = await CommonContext.CommonAccounts
                                    .Include(m => m.Partition)
                                    .Where(account => account.Number == model.AccountNumber)
                                    .SingleOrDefaultAsync();

                //Check if this account exists
                if (accountDetail == null)
                {
                    ModelState.AddModelError("AccountNumber", "Invalid Account Number");
                    return(View(model));
                }
                else
                {
                    var _accountCtx = ContextsUtility.CreateAccountContext(Cryptography.Decrypt(accountDetail.Partition.ConnectionString));

                    //Find violation
                    var license = model.LicensePlate.Trim();
                    var state   = model.State.Trim();

                    var citation = await _accountCtx.Citations.ForAccount(accountDetail.Id)
                                   .Where(m => m.CitationNumber == model.CitationNumber)
                                   .Where(m => m.LicenseState == state)
                                   .Where(m => m.LicensePlate == license)
                                   .OrderByDescending(m => m.CreateUtc)
                                   .FirstOrDefaultAsync();

                    if (citation == null)
                    {
                        ModelState.AddModelError("", "Cannot find Ticket.  Please call 555-555-5555 for assitance");
                    }
                    else
                    {
                        //Encrypt CitationID and Send user to Citation Page
                        var encryptedCitationId = _dataProtector.Protect($"{accountDetail.Id}&{citation.Id.ToString()}");
                        return(RedirectToAction("Citation", new { id = encryptedCitationId }));
                    }
                }
            }

            return(View(model));
        }
Example #12
0
        public async Task <IActionResult> UpdateDisableStatus(bool Disabled, Guid ViolationId, Guid AccountId)
        {
            var result = new ServiceResponse <Violation>();

            try
            {
                var accountDetail = await CommonContext.CommonAccounts.SingleOrDefaultAsync(account => account.Id == AccountId);

                var PartitionDetail = await CommonContext.Partitions.SingleOrDefaultAsync(partition => partition.Id == accountDetail.PartitionId);

                var _accountCtx = ContextsUtility.CreateAccountContext(Cryptography.Decrypt(accountDetail.Partition.ConnectionString));

                result = await _commonAccountSvc.UpdateDisableStatus(Disabled, ViolationId, _accountCtx);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(Json(result));
        }
        private async Task <AccountInfoViewModel> GetSampleAccountInfoViewModel(CommonAccount account, Guid?eventId)
        {
            var model = new AccountInfoViewModel()
            {
                Account = account
            };

            var _accountCtx = ContextsUtility.CreateAccountContext(Cryptography.Decrypt(account.Partition.ConnectionString));

            var events = _accountCtx.Events.ForAccount(account.Id).AsNoTracking();

            if (eventId.HasValue)
            {
                events = events.Where(m => m.Id == eventId.Value);
            }

            model.Events = Mapper.Map <List <AccountEvent> >(await events.OrderByDescending(m => m.CreateUtc).ToListAsync());

            return(model);
        }
Example #14
0
        /// <summary>
        /// Citation Detail
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>

        public async Task <IActionResult> Citation(Guid id, Guid accountId)
        {
            var accountDetail = await CommonContext.CommonAccounts.Include(m => m.Partition).SingleOrDefaultAsync(account => account.Id == accountId);

            _accountCtx = ContextsUtility.CreateAccountContext(Cryptography.Decrypt(accountDetail.Partition.ConnectionString));


            var citation = await GetCitation(accountId, id);

            if (citation != null)
            {
                var citationViewModel = Mapper.Map <CitationViolationListItem>(citation);

                ApplyVideoAndImageUrl(citation, citationViewModel, _fileSvc);

                return(View(citationViewModel));
            }

            return(RedirectToAction("Index"));
        }
        public async Task <IActionResult> Get(Guid Id)
        {
            var response = new APIResponse <UserProfileModel>()
            {
                Success = false
            };
            var user = await _commonUserSvc.GetUserProfile(Id);

            if (user != null)
            {
                var userResponse = Mapper.Map <UserProfileModel>(user);
                if (!string.IsNullOrWhiteSpace(user.ProfileImageKey))
                {
                    userResponse.ProfileImageUrl = AppSettings.AmazonS3Url + user.ProfileImageKey;
                }

                response.Data    = userResponse;
                response.Success = true;
            }


            //Get a list of Accounts for a user
            var accountsForaUser = await CommonContext.UserAccounts.Include(m => m.Account).ThenInclude(m => m.Partition).Where(m => m.UserId == Id).ToListAsync();

            var citations = new List <Citation>();

            //Loop through each AccountContext for this user and get a list of Citations
            foreach (var commonAccount in accountsForaUser)
            {
                //Get the correct account database based on the partition that was chosen for the account.
                var accountCtx = ContextsUtility.CreateAccountContext(Cryptography.Decrypt(commonAccount.Account.Partition.ConnectionString));

                var citationsForAccount = await accountCtx.Citations.Where(m => m.CreateUserId == Id).ToListAsync();

                citations.AddRange(citationsForAccount);
            }

            return(Ok(response));
        }
Example #16
0
        public async Task <IActionResult> Violations(Guid AccountId, AccViolationListViewModel model)
        {
            // var model = new ViolationListViewModel();

            var currentPageNum = model.Page;
            var offset         = (model.PageSize * currentPageNum) - model.PageSize;

            //get commom violation type
            var vioTypeId = await CommonContext.CommonAccountViolationTypes.AsNoTracking()
                            .Where(s => s.AccountId.Equals(model.AccountId)).Select(m => m.ViolationTypeId).ToListAsync();

            var accountDetail = await CommonContext.CommonAccounts.SingleOrDefaultAsync(account => account.Id == model.AccountId);

            var PartitionDetail = await CommonContext.Partitions.SingleOrDefaultAsync(partition => partition.Id == accountDetail.PartitionId);

            var CityDetail = await CommonContext.Cities.SingleOrDefaultAsync(city => city.Id == accountDetail.CityId);

            var _accountCtx = ContextsUtility.CreateAccountContext(Cryptography.Decrypt(accountDetail.Partition.ConnectionString));

            //get Violation that are disabled or that is related to passed accountid
            var violations = _accountCtx.Violations
                             .Include(m => m.Category)
                             .Include(m => m.Category.Type)
                             .ForAccount(model.AccountId)
                             .AsQueryable();

            //Filter the violation by the types that this account is associated with.
            violations = violations.Where(m => vioTypeId.Contains(m.Category.Type.CommonViolationTypeId));

            if (Convert.ToString(model.CategoryId) != "00000000-0000-0000-0000-000000000000")
            {
                violations = violations.Where(s => s.CategoryId.Equals(model.CategoryId));
            }
            if (Convert.ToString(model.TypeId) != "00000000-0000-0000-0000-000000000000")
            {
                violations = violations.Where(s => s.Category.TypeId.Equals(model.TypeId));
            }

            //sorting
            switch (model.SortOrder)
            {
            case "Type":
                if (model.SortDirection == "DESC")
                {
                    violations = violations.OrderByDescending(s => s.Category.Type.Name);
                }
                else
                {
                    violations = violations.OrderBy(s => s.Category.Type.Name);
                }
                break;

            case "Category":
                if (model.SortDirection == "DESC")
                {
                    violations = violations.OrderByDescending(s => s.Category.Name);
                }
                else
                {
                    violations = violations.OrderBy(s => s.Category.Name);
                }
                break;

            case "Disabled":
                if (model.SortDirection == "DESC")
                {
                    violations = violations.OrderByDescending(s => s.Disabled);
                }
                else
                {
                    violations = violations.OrderBy(s => s.Disabled);
                }
                break;

            default:
                if (model.SortDirection == "DESC")
                {
                    violations = violations.OrderByDescending(s => s.Name);
                }
                else
                {
                    violations = violations.OrderBy(s => s.Name);
                }
                break;
            }

            var totalQueryCount = await violations.CountAsync();

            model.Violation = Mapper.Map <List <AccViolationListItem> >(await violations.Skip(offset).Take(model.PageSize).ToListAsync());

            model.Paging.CurrentPage  = currentPageNum;
            model.Paging.ItemsPerPage = model.PageSize;
            model.Paging.TotalItems   = totalQueryCount;
            model.AccountId           = model.AccountId;
            model.CityName            = CityDetail.Name;

            //TODO: this should be cached and retrieved from a service
            var Types = await _accountCtx.ViolationTypes.Where(m => m.AccountId.Equals(model.AccountId) && vioTypeId.Contains(m.CommonViolationTypeId)).Select(m => new SelectListItem
            {
                Text  = m.Name,
                Value = m.Id.ToString(),
            })
                        .ToListAsync();

            model.Types.AddRange(Types);

            //TODO: this should be cached and retrieved from a service
            var Categories = await _accountCtx.ViolationCategorys.Include(m => m.Type).Where(m => m.AccountId.Equals(model.AccountId) && vioTypeId.Contains(m.Type.CommonViolationTypeId)).Select(m => new SelectListItem
            {
                Text  = m.Name + " (" + m.Type.Name + " )",
                Value = m.Id.ToString(),
            }).ToListAsync();

            model.Categories.AddRange(Categories);

            return(View(model));
        }
Example #17
0
        /// <summary>
        /// getting all citation list
        /// </summary>
        /// <param name="CreatedFrom"></param>
        /// <param name="Createdto"></param>
        /// <param name="StatusId"></param>
        /// <param name="AssignedToId"></param>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task <IActionResult> Index(AdminCitationListViewModel model)
        {
            var currentPageNum = model.Page;
            var offset         = (model.PageSize * currentPageNum) - model.PageSize;

            if (model.AccountId.HasValue)
            {
                var accountDetail = await CommonContext.CommonAccounts.Include(m => m.Partition).SingleOrDefaultAsync(account => account.Id == model.AccountId);

                _accountCtx = ContextsUtility.CreateAccountContext(Cryptography.Decrypt(accountDetail.Partition.ConnectionString));

                var citations = ApplyCitationFilter(model);

                #region sort
                switch (model.SortOrder)
                {
                case "Status":
                    if (model.SortDirection == "DESC")
                    {
                        citations = citations.OrderByDescending(s => s.Status);
                    }
                    else
                    {
                        citations = citations.OrderBy(s => s.Status);
                    }
                    break;

                case "Violation":
                    if (model.SortDirection == "DESC")
                    {
                        citations = citations.OrderByDescending(s => s.Violation.Name);
                    }
                    else
                    {
                        citations = citations.OrderBy(s => s.Violation.Name);
                    }
                    break;

                case "AssignedTo":
                    if (model.SortDirection == "DESC")
                    {
                        citations = citations.OrderByDescending(s => s.AssignedTo);
                    }
                    else
                    {
                        citations = citations.OrderBy(s => s.AssignedTo);
                    }
                    break;

                case "Created":
                    if (model.SortDirection == "DESC")
                    {
                        citations = citations.OrderByDescending(s => s.CreateUtc);
                    }
                    else
                    {
                        citations = citations.OrderBy(s => s.CreateUtc);
                    }
                    break;

                case "License":
                    if (model.SortDirection == "DESC")
                    {
                        citations = citations.OrderByDescending(s => s.LicensePlate);
                    }
                    else
                    {
                        citations = citations.OrderBy(s => s.LicensePlate);
                    }
                    break;

                case "Number":
                    if (model.SortDirection == "DESC")
                    {
                        citations = citations.OrderByDescending(s => s.CitationNumber);
                    }
                    else
                    {
                        citations = citations.OrderBy(s => s.CitationNumber);
                    }
                    break;

                default:
                    if (model.SortDirection == "DESC")
                    {
                        citations = citations.OrderByDescending(s => s.CreateUtc);
                    }
                    else
                    {
                        citations = citations.OrderBy(s => s.CreateUtc);
                    }
                    break;
                }
                #endregion

                var totalQueryCount = await citations.CountAsync();

                model.CitationsListItem = Mapper.Map <List <CitationsListItem> >(await citations.Skip(offset).Take(model.PageSize).ToListAsync());

                foreach (var m in model.CitationsListItem)
                {
                    m.CreatedHumanizerDate = m.Created.Humanize();
                }

                model.Paging.CurrentPage  = currentPageNum;
                model.Paging.ItemsPerPage = model.PageSize;
                model.Paging.TotalItems   = totalQueryCount;
            }

            #region dropdown lists

            //Accounts List
            //TODO: this should be cached and retrieved from a service
            var accounts = await CommonContext.CommonAccounts.Select(m => new SelectListItem
            {
                Text  = m.Name,
                Value = m.Id.ToString(),
            })
                           .ToListAsync();

            model.Accounts = accounts;

            #endregion


            return(View(model));
        }