Beispiel #1
0
        public async Task <IActionResult> Get(Guid id)
        {
            var result = await providerRepository.Find(x => x.Id == id);

            if (result == null)
            {
                return(NotFound());
            }

            return(Ok(mapper.Map <ProviderDto>(result)));
        }
Beispiel #2
0
        private async Task <ProviderDoc> FetchOrCreateProvider(ProviderCreatingDto newProvider)
        {
            var np       = AutoMapper.Mapper.Map <ProviderDoc>(newProvider);
            var provider = await _providerRepository.Find(np);

            if (provider == null)
            {
                await _providerRepository.AddProvider(np);

                provider = np;
            }
            return(provider);
        }
Beispiel #3
0
        public async Task <JsonResult> GetFilteredItems()
        {
            int    draw                = Convert.ToInt32(Request.Query["draw"]);
            int    start               = Convert.ToInt32(Request.Query["start"]);
            int    length              = Convert.ToInt32(Request.Query["length"]);
            int    sortColumnIdx       = Convert.ToInt32(Request.Query["order[0][column]"]);
            string sortColumnName      = Request.Query["columns[" + sortColumnIdx + "][name]"];
            string sortColumnDirection = Request.Query["order[0][dir]"];
            string searchValue         = Request.Query["search[value]"].FirstOrDefault()?.Trim();
            var    recordsFiltered     = await _providerRepository.Find(p => p.Name.Contains(searchValue));

            int recordsFilteredCount = recordsFiltered.Count();
            var recordsTotal         = await _providerRepository.GetAll();

            int recordsTotalCount = recordsTotal.Count();

            var columns = Request.Query["columns"].Count;

            ICollection <ProviderViewModel> filteredData = null;

            if (sortColumnDirection == "asc")
            {
                filteredData = _mapper.Map <ICollection <ProviderViewModel> >(await _providerRepository.GetAll())
                               .Where(p => p.Name.Contains(searchValue))
                               .OrderBy(x => x.GetType().GetProperty(sortColumnName).GetValue(x))
                               .Skip(start)
                               .Take(length)
                               .ToList();
            }

            else
            {
                filteredData = _mapper.Map <ICollection <ProviderViewModel> >(await _providerRepository.GetAll())
                               .Where(p => p.Name.Contains(searchValue))
                               .OrderByDescending(x => x.GetType().GetProperty(sortColumnName).GetValue(x))
                               .Skip(start)
                               .Take(length)
                               .ToList();
            }

            return(Json(new
            {
                data = filteredData,
                draw = Request.Query["draw"],
                recordsFiltered = recordsFilteredCount,
                recordsTotal = recordsTotalCount
            }));
        }
Beispiel #4
0
        private IEnumerable <CreditCard> FilterNewAccount(ProviderCreatingDto providerDto, IEnumerable <CreditCard> cards)
        {
            IEnumerable <CreditCard> newAccounts;
            var p        = AutoMapper.Mapper.Map <ProviderDoc>(providerDto);
            var provider = _providerRepository.Find(p);

            if (provider != null)
            {
                newAccounts = (from card in cards
                               where !IsAccountExists(card)
                               select card).ToList();
            }
            else
            {
                newAccounts = cards;
            }
            return(newAccounts);
        }
        private IEnumerable <BankAccount> FetchNewAccount(ProviderDoc provider, IEnumerable <BankAccount> accounts)
        {
            IEnumerable <BankAccount> newAccounts;

            var providerInRepo = _providerRepository.Find(provider);

            if (providerInRepo?.Result != null)
            {
                newAccounts = (from account in accounts
                               where !IsAccountExists(account)
                               select account).ToList();
            }
            else
            {
                newAccounts = accounts;
            }

            return(newAccounts);
        }
Beispiel #6
0
 public bool Exists(int id)
 {
     return(_providerRepository.Find(id) != null);
 }