public ActionResult InsertBidDetail(InsertBidModel insertBid, int id)
        {
            bool successful;

            if (ModelState.IsValid)
            {
                B_AuctionController bACtr = new B_AuctionController();

                ConvertViewModel converter = new ConvertViewModel();

                successful = bACtr.InsertBid(converter.ConvertFromBidInsertModelToBid(insertBid, User.Identity.Name, id));

                //For messages to the user.
                if (successful)
                {
                    TempData["Referer"] = "InsertSuccessful";
                }
                else
                {
                    TempData["Referer"] = "InsertFailed";
                }
            }

            return(RedirectToAction("Auction", new { id }));
        }
        /// <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 Bid ConvertFromBidInsertModelToBid(InsertBidModel iBM, string userName, int auctionId)
        {
            Bid bid = new Bid
            {
                Auction_Id = auctionId,
                Amount     = iBM.Amount,
                UserName   = userName
            };

            return(bid);
        }
 public ActionResult InsertBid(InsertBidModel insertBidModel, int id)
 {
     insertBidModel.AuctionId = id;
     return(View("InsertBid", insertBidModel));
 }