public ViewResult All() { var list = repository.GetAll().Where(x => x.Active); var to_update = new List <Auction>(); List <BankAccount> usersToPay = new List <BankAccount>(); List <float> moneyToPay = new List <float>(); foreach (var item in list) { item.Product = productRepository.GetById(item.ProductId); if (item.Date <= DateTime.Now && item.Active) { item.Active = false; if (item.ActualUser == null) { continue; } to_update.Add(item); //Money Transfer usersToPay.Add(bankAccountRepository.GetByUserId(item.User_Sale_ID).First()); moneyToPay.Add(item.Ammount * (float)item.ActualPrice); usersToPay.Add(bankAccountRepository.GetByTitular("Shoppify")); moneyToPay.Add((moneyToPay.Sum() * 2) / 100); var temp = bankAccountRepository.GetByUserId(item.ActualUser); if (temp.Count() == 0) { continue; } var userpay = bankAccountRepository.GetByUserId(item.ActualUser).First(); if (!Bank.Deposit(userpay, usersToPay, moneyToPay)) { var productname = productRepository.GetById(item.ProductId).Name; Notification notification = new Notification(NotificationType.BadAuctionSale, item.User_Sale_ID, productname); Notification notification1 = new Notification(NotificationType.BadAuctionBuy, item.ActualUser, productname); notificationRepository.AddEntity(notification); notificationRepository.AddEntity(notification1); } usersToPay.Clear(); moneyToPay.Clear(); } } foreach (var item in to_update) { repository.Update(item); } AllAuctionViewModel viewModel = new AllAuctionViewModel() { Auctions = list, FirstPage = 1, Page = 1, selectListCategory = selectListItemsCategory, selectListFilter = selectListItemsFilters }; return(View(viewModel)); }
public ViewResult All(AllAuctionViewModel viewModel) { var page = viewModel.Page; if (page <= 0) { page = 1; } if (page % 3 == 0) { viewModel.FirstPage = page - 2; } else { viewModel.FirstPage = page / 3 > 0 ? page / 3 * 3 + 1 : 1; } if (viewModel.FirstPage <= 0) { viewModel.FirstPage = 1; } var s = viewModel.Filter; var categ = viewModel.Category; int count = 0; string[] array = { "None", "Price Down", "Price Up", "Rating Down", "Rating Up", "Name Down", "Name Up" }; viewModel.selectListFilter = new List <SelectListItem>(); viewModel.selectListCategory = new List <SelectListItem>(); foreach (var item in Enum.GetNames(typeof(Filters))) { if (s.ToString() == item) { viewModel.selectListFilter.Add(new SelectListItem(array[count], item, true)); } else { viewModel.selectListFilter.Add(new SelectListItem(array[count], item)); } ++count; } foreach (var item in Enum.GetNames(typeof(Category))) { if (categ.ToString() == item) { viewModel.selectListCategory.Add(new SelectListItem(item, item, true)); } else { viewModel.selectListCategory.Add(new SelectListItem(item, item)); } } switch (s) { case Filters.None: viewModel.Auctions = repository.GetAll().Skip((page - 1) * 9).Where(x => x.Active & (categ == Category.All | categ == productRepository.GetById(x.ProductId).Category)).ToList(); break; case Filters.PriceDown: viewModel.Auctions = repository.GetAll().Skip((page - 1) * 9).Where(x => x.Active & (categ == Category.All | categ == productRepository.GetById(x.ProductId).Category)).OrderByDescending(x => x.ActualPrice).ToList(); break; case Filters.PriceUp: viewModel.Auctions = repository.GetAll().Skip((page - 1) * 9).Where(x => x.Active & (categ == Category.All | categ == productRepository.GetById(x.ProductId).Category)).OrderBy(x => x.ActualPrice).ToList(); break; case Filters.RatingDown: viewModel.Auctions = repository.GetAll().Skip((page - 1) * 9).Where(x => x.Active & (categ == Category.All | categ == productRepository.GetById(x.ProductId).Category)).OrderByDescending(x => productRepository.GetById(x.ProductId).Rating).ToList(); break; case Filters.RatingUp: viewModel.Auctions = repository.GetAll().Skip((page - 1) * 9).Where(x => x.Active & (categ == Category.All | categ == productRepository.GetById(x.ProductId).Category)).OrderBy(x => productRepository.GetById(x.ProductId).Rating).ToList(); break; case Filters.NameDown: viewModel.Auctions = repository.GetAll().Skip((page - 1) * 9).Where(x => x.Active & (categ == Category.All | categ == productRepository.GetById(x.ProductId).Category)).OrderByDescending(x => productRepository.GetById(x.ProductId).Name).ToList(); break; case Filters.NameUp: viewModel.Auctions = repository.GetAll().Skip((page - 1) * 9).Where(x => x.Active && (categ == Category.All | categ == productRepository.GetById(x.ProductId).Category)).OrderBy(x => productRepository.GetById(x.ProductId).Name).ToList(); break; default: break; } return(View(viewModel)); }