public AuctionInfoViewModel ConvertFromAuctionToAuctionModel(Auction auction)
        {
            if (auction != null)
            {
                AuctionInfoViewModel auctionModel = new AuctionInfoViewModel
                {
                    StartPrice   = auction.StartPrice,
                    BuyOutPrice  = auction.BuyOutPrice,
                    BidInterval  = auction.BidInterval,
                    Description  = auction.Description,
                    StartDate    = auction.StartDate,
                    EndDate      = auction.EndDate,
                    Category     = auction.Category,
                    UserName     = auction.UserName,
                    Id           = auction.Id,
                    UserLocation = auction.ZipCode + " - " + auction.Region
                };

                return(auctionModel);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 2
0
        public ActionResult ShowAuction(string auctionId)
        {
            AuctionInfoViewModel auctionInfoVm = auctionManagement.GetAuctionInfo(auctionId);

            ViewBag.auctionInfoVm = auctionInfoVm;
            return(View());
        }
        /// <summary>
        /// Shows the auction view,
        /// where ViewModel of AuctionModel is used as container for 4 different models.
        /// Shows all the models in one view.
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Auction(int id)
        {
            B_AuctionController bACtr = new B_AuctionController();

            ConvertViewModel converter = new ConvertViewModel();

            //Auction details from database.
            AuctionInfoViewModel auctionInfoModel = converter.ConvertFromAuctionToAuctionModel(bACtr.GetAuction(id));

            //If auction is not in database - For handling if users put in illegal auction id in url.
            if (auctionInfoModel == null)
            {
                return(View("NotFound"));
            }

            //Get Images info from database.
            List <PictureViewModel> sAPM = converter.ConvertFromImagesToShowAuctionPictureModels(bACtr.GetImages(id));

            //Get bids on the auction from database.
            List <BidViewModel> showBids = converter.ConvertFromBidsToShowBids(bACtr.GetBids(id));

            //Get highest bid from database - Create insert bids model
            InsertBidModel insertBidModel = new InsertBidModel();

            insertBidModel.CurrentHighestBid = bACtr.GetHighestBidOnAuction(id);
            insertBidModel.MinimumValidBid   = insertBidModel.CurrentHighestBid + auctionInfoModel.BidInterval;

            //Return the AuctionModel
            return(View(new AuctionViewModel()
            {
                AuctionInfoModel = auctionInfoModel, PictureViewModels = sAPM, ShowBids = showBids, InsertBidModel = insertBidModel
            }));
        }
        public List <AuctionInfoViewModel> ConvertFromAuctionsToAuctionModels(List <Auction> auctions)
        {
            List <AuctionInfoViewModel> auctionModels = new List <AuctionInfoViewModel>();

            foreach (Auction auction in auctions)
            {
                AuctionInfoViewModel auctionModel = ConvertFromAuctionToAuctionModel(auction);
                auctionModels.Add(auctionModel);
            }
            return(auctionModels);
        }
        public List <AuctionInfoViewModel> GetActiveAuctionsExceptMine(Guid organizationId)
        {
            var organization = _applicationDbContext.Organizations.SingleOrDefault(p => p.Id == organizationId);

            if (organization == null)
            {
                throw new Exception($"Организации с таким id {organizationId} не существует");
            }

            var auctions = _applicationDbContext.Auctions
                           .Where(p => p.OrganizationId != organizationId && p.Status == AuctionStatus.Active).ToList();

            if (auctions.Count == 0)
            {
                throw new Exception("Активных аукционов на данный момент в базе нет");
            }

            List <AuctionInfoViewModel> auctionModels = new List <AuctionInfoViewModel>();

            foreach (Auction item in auctions)
            {
                AuctionInfoViewModel model = new AuctionInfoViewModel()
                {
                    AuctionId          = item.Id.ToString(),
                    Status             = item.Status.ToString(),
                    AuctionType        = item.AuctionType.Name,
                    OrganizationName   = item.Organization.FullName,
                    ShippingAddress    = item.ShippingAddress,
                    ShippingConditions = item.ShippingConditions,
                    StartPrice         = item.StartPrice,
                    PriceStep          = item.PriceStep,
                    MinPrice           = item.MinPrice,
                    StartDate          = item.StartDate,
                    FinishDate         = item.FinishDate,
                    AuctionFiles       = item.AuctionFiles.ToList()
                };
                auctionModels.Add(model);
            }

            return(auctionModels);
        }
        public List <AuctionInfoViewModel> GetAllActiveAuctions()
        {
            var auctions = _applicationDbContext.Auctions.ToList();

            if (auctions.Count == 0)
            {
                throw new Exception("Активных аукционов на данный момент в базе нет");
            }

            List <AuctionInfoViewModel> auctionModels = new List <AuctionInfoViewModel>();

            foreach (Auction item in auctions)
            {
                AuctionInfoViewModel model = new AuctionInfoViewModel();
                model.AuctionId = item.Id.ToString();
                model.Status    = item.Status.ToString();

                var auctionType = _applicationDbContext.AuctionTypes.SingleOrDefault(p => p.Id == item.AuctionTypeId);
                model.AuctionType = auctionType.Name;

                var organization = _applicationDbContext.Organizations.SingleOrDefault(p => p.Id == item.OrganizationId);
                model.OrganizationName = organization.FullName;

                model.MinRatingForParticipant = item.MinRatingForParticipant.ToString();
                model.Description             = item.Description;
                model.ShippingAddress         = item.ShippingAddress;
                model.ShippingConditions      = item.ShippingConditions;
                model.StartPrice = item.StartPrice;
                model.PriceStep  = item.PriceStep;
                model.MinPrice   = item.MinPrice;
                model.StartDate  = item.StartDate;
                model.FinishDate = item.FinishDate;
                //model.AuctionFiles = item.AuctionFiles.ToList();

                auctionModels.Add(model);
            }

            return(auctionModels);
        }
        public AuctionInfoViewModel GetAuctionInfo(string auctionId)
        {
            var auction = _applicationDbContext.Auctions.Include("Organizations").SingleOrDefault(p => p.Id.ToString() == auctionId);

            if (auction == null)
            {
                throw new Exception($"Аукциона с таким id {auctionId} не существует");
            }

            var auctionFiles = _applicationDbContext.AuctionFiles.Where(p => p.AuctionId.ToString() == auctionId).ToList();
            //if (auctionFiles.Count == 0)
            //    throw new Exception($"У аукциона {auctionId} нет прикрепленных документов");


            var auctionType = _applicationDbContext.AuctionTypes.SingleOrDefault(p => p.Id == auction.AuctionTypeId);

            var organization = _applicationDbContext.Organizations.SingleOrDefault(p => p.Id == auction.OrganizationId);

            AuctionInfoViewModel model = new AuctionInfoViewModel()
            {
                AuctionId               = auctionId.ToString(),
                Status                  = auction.Status.ToString(),
                AuctionType             = auctionType.Name,
                OrganizationName        = organization.FullName,
                MinRatingForParticipant = auction.MinRatingForParticipant.ToString(),
                Description             = auction.Description,
                ShippingAddress         = auction.ShippingAddress,
                ShippingConditions      = auction.ShippingConditions,
                StartPrice              = auction.StartPrice,
                PriceStep               = auction.PriceStep,
                MinPrice                = auction.MinPrice,
                StartDate               = auction.StartDate,
                FinishDate              = auction.FinishDate,
                FinishDateAtActual      = auction.FinishDateAtActual,
                //AuctionFiles = auctionFiles
            };

            return(model);
        }