Пример #1
0
        public IEnumerable <NewUsersIn30DaysServiceModel> GetNewUsersIn30Days()
        {
            var entity = _unitOfWork.AddRepository <NewUsersIn30Days>()
                         .GetRepository <NewUsersIn30Days>()
                         .FromSQL(new NewUsersIn30Days().GetQuery());

            var temp = _mapper.Map <List <NewUsersIn30DaysServiceModel> >(entity);

            var serviceModel = new List <NewUsersIn30DaysServiceModel>();

            int index = 0;

            for (int i = 0; i <= 29; i++)
            {
                if (temp.Any(x => x.Day == i))
                {
                    serviceModel.Add(new NewUsersIn30DaysServiceModel {
                        Day = i, UserCount = temp[index].UserCount
                    });
                    index++;
                }
                else
                {
                    serviceModel.Add(new NewUsersIn30DaysServiceModel {
                        Day = i, UserCount = 0
                    });
                }
            }


            return(serviceModel);
        }
Пример #2
0
 public int GetCurrencyId(string currency)
 {
     return(_unitOfWork.AddRepository <CurrencyEntityModel>()
            .GetRepository <CurrencyEntityModel>()
            .Get(x => x.Name == currency)
            .FirstOrDefault()
            .Id);
 }
        public int AddTransaction(FinancialTransactionServiceModel transaction)
        {
            var entity = _mapper.Map <TransactionEntityModel>(transaction);

            _dateService.SetDateCreatedNow(ref entity);

            _unitOfWork.AddRepository <TransactionEntityModel>()
            .GetRepository <TransactionEntityModel>()
            .AddItem(entity);

            return(entity.Id);
        }
Пример #4
0
        public FileDownloadServiceModel GetFileById(int fileId, bool includeFileData = false)
        {
            string include = includeFileData ? "File" : "";

            var file = _unitOfWork.AddRepository <FileDescriptorEntityModel>()
                       .GetRepository <FileDescriptorEntityModel>()
                       .Get(x => x.Id == fileId, null, include)
                       .FirstOrDefault();

            var serviceFile = _mapper.Map <FileDownloadServiceModel>(file);

            return(serviceFile);
        }
Пример #5
0
        public int CreateTicket(TicketServiceModel ticket)
        {
            var ticketRepo = _unitOfWork.AddRepository <TicketEntityModel>().GetRepository <TicketEntityModel>();

            var entity = _mapper.Map <TicketEntityModel>(ticket);

            _dateService.SetDateCreatedNow(ref entity);

            entity.TicketType   = null;
            entity.TicketStatus = null;

            ticketRepo.AddItem(entity);
            _unitOfWork.Save();

            return(entity.Id);
        }
Пример #6
0
        public int CreateWallet(WalletServiceModel wallet)
        {
            _unitOfWork.AddRepository <WalletEntityModel>();

            var walletEntity = _mapper.Map <WalletEntityModel>(wallet);

            walletEntity.RegistrantId = wallet.RegistrantId;

            _dateService.SetDateCreatedNow(ref walletEntity);

            _unitOfWork.GetRepository <WalletEntityModel>().AddItem(walletEntity);
            _unitOfWork.Save();

            return(walletEntity.Id);
        }
Пример #7
0
        public int CreateAccount(AccountServiceModel account)
        {
            _unitOfWork.AddRepository <AccountEntityModel>();

            var accountEntity = _mapper.Map <AccountEntityModel>(account);

            _dateService.SetDateCreatedNow(ref accountEntity);

            _unitOfWork.GetRepository <AccountEntityModel>().AddItem(accountEntity);
            _unitOfWork.Save();

            return(accountEntity.Id);
        }
Пример #8
0
        public int CreateRegistrant(RegistrantServiceModel registrant)
        {
            _unitOfWork.AddRepository <RegistrantEntityModel>();

            var registrantEntity = _mapper.Map <RegistrantEntityModel>(registrant);

            _dateService.SetDateCreatedNow(ref registrantEntity);

            _unitOfWork.GetRepository <RegistrantEntityModel>().AddItem(registrantEntity);
            _unitOfWork.Save();

            return(registrantEntity.Id);
        }
Пример #9
0
        public IEnumerable <CountryServiceModel> GetCountries()
        {
            _unitOfWork.AddRepository <CountryEntityModel>();

            var countriesRepoModel = _unitOfWork.GetRepository <CountryEntityModel>().Get().ToList();

            var countriesServiceModel = _mapper.Map <List <CountryServiceModel> >(countriesRepoModel);

            return(countriesServiceModel);
        }
Пример #10
0
        public bool DeleteUser(int id)
        {
            _unitOfWork.AddRepository <UserEntityModel>();

            var userRepo = _unitOfWork.GetRepository <UserEntityModel>();

            var userEntity = userRepo.Get(user => user.Id == id, null, "Registrant").FirstOrDefault();

            if (userEntity.Registrant != null)
            {
                return(false);
            }

            userRepo.Delete(id);
            _unitOfWork.Save();

            return(true);
        }
Пример #11
0
        public IEnumerable <AllWalletsWithSums> GetAllWalletsWithSums(string orderBy, AllWalletsWithSumsFiltersServiceModel filters)
        {
            var repo = _unitOfWork.AddRepository <AllWalletsWithSums>().GetRepository <AllWalletsWithSums>();
            var allWalletsWithSums = new List <AllWalletsWithSums>();
            var rawSql             = new AllWalletsWithSums().GetQuery();

            if (filters != null)
            {
                IEnumerable <AllWalletsWithSums> query = new List <AllWalletsWithSums>();

                if (filters.Countries.Any())
                {
                    query = repo.FromSQL(rawSql, x => filters.Countries.Any(y => filters.Countries.Contains(x.ClientCountry)));
                }

                if (!query.Any())
                {
                    query = repo.FromSQL(rawSql);
                }

                if (DateTime.TryParseExact(filters.RegisteredFrom, "MM/dd/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime dateFrom) &&
                    DateTime.TryParseExact(filters.RegisteredTo, "MM/dd/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime dateTo))
                {
                    query = query.Where(x => x.Date >= dateFrom && x.Date <= dateTo);
                }

                allWalletsWithSums = query.ToList();
            }
            else
            {
                allWalletsWithSums = repo.FromSQL(rawSql).ToList();
            }

            switch (orderBy)
            {
            case "Id":
                allWalletsWithSums = allWalletsWithSums.OrderBy(y => y.Id).ToList();
                break;

            case "Id_desc":
                allWalletsWithSums = allWalletsWithSums.OrderByDescending(y => y.Id).ToList();
                break;

            case "ClientName":
                allWalletsWithSums = allWalletsWithSums.OrderBy(y => y.ClientName).ToList();
                break;

            case "ClientName_desc":
                allWalletsWithSums = allWalletsWithSums.OrderByDescending(y => y.ClientName).ToList();
                break;

            case "ClientCountry":
                allWalletsWithSums = allWalletsWithSums.OrderBy(y => y.ClientCountry).ToList();
                break;

            case "ClientCountry_desc":
                allWalletsWithSums = allWalletsWithSums.OrderByDescending(y => y.ClientCountry).ToList();
                break;

            case "Balance":
                allWalletsWithSums = allWalletsWithSums.OrderBy(y => y.Balance).ToList();
                break;

            case "Balance_desc":
                allWalletsWithSums = allWalletsWithSums.OrderByDescending(y => y.Balance).ToList();
                break;

            case "Currency":
                allWalletsWithSums = allWalletsWithSums.OrderBy(y => y.Currency).ToList();
                break;

            case "Currency_desc":
                allWalletsWithSums = allWalletsWithSums.OrderByDescending(y => y.Currency).ToList();
                break;

            default:
                allWalletsWithSums = allWalletsWithSums.OrderBy(y => y.Id).ToList();
                break;
            }

            return(allWalletsWithSums);
        }