コード例 #1
0
        public ActionResult UpdateCustomerBid(Auction.Model.Message.Auction auction)
        {
            LoginModelResponse customerinfo = (LoginModelResponse)Session["Customer"];

            if (customerinfo == null)
            {
                return(RedirectToActionPermanent("Index", "Login"));
            }

            AuctionResponse auctionResponse = new AuctionResponse();

            ViewBag.LoginSuccess = "True";
            auction.CustomerId   = customerinfo.CustomerId;
            if (!ModelState.IsValid)
            {
                TempData["Error"] = "Bid Price is required";
                return(RedirectToAction("MyBidDetail", new { auctionid = auction.AuctionId }));
            }
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(ConfigurationManager.AppSettings["WebApiBaseUrl"]);
                //HTTP POST
                var responseMessageTask = client.PostAsJsonAsync <Auction.Model.Message.Auction>("api/Auction/UpdateBid", auction);
                responseMessageTask.Wait();
                var responseMessage = responseMessageTask.Result;
                if (responseMessage.IsSuccessStatusCode)
                {
                    var responseContentTask = responseMessage.Content.ReadAsAsync <AuctionResponse>();
                    responseContentTask.Wait();
                    auctionResponse = responseContentTask.Result;
                    if (auctionResponse.Error == null)
                    {
                        return(RedirectToActionPermanent("GetMyBids", "Auction"));
                    }
                    TempData["Error"] = auctionResponse.Error.Message;
                    return(RedirectToAction("MyBidDetail", new { auctionid = auction.AuctionId }));
                }
                else
                {
                    TempData["Error"] = "Server error";
                    return(RedirectToAction("MyBidDetail", new { auctionid = auction.AuctionId }));
                }
            }
        }
コード例 #2
0
 public IHttpActionResult UpdateBid(Auction.Model.Message.Auction auction)
 {
     try
     {
         AuctionResponse auctionResponse = new AuctionResponse();
         if (!ModelState.IsValid)
         {
             auctionResponse.Error = new Error()
             {
                 Code = ErrorCodes.ModelStateInvalid, Message = "model state is not valid"
             };
             return(Ok(auctionResponse));
         }
         auctionResponse = CustomerAuction.UpdateCustomerBid(auction);
         return(Ok(auctionResponse));
     }
     catch (Exception ex)
     {
         return(Ok(ex.Message));
     }
 }
コード例 #3
0
        public ActionResult MyBidDetail(int auctionid)
        {
            LoginModelResponse customerinfo = (LoginModelResponse)Session["Customer"];

            if (customerinfo == null)
            {
                return(RedirectToActionPermanent("Index", "Login"));
            }
            Auction.Model.Message.Auction userAuction = new Auction.Model.Message.Auction();
            ViewBag.LoginSuccess = "True";
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(ConfigurationManager.AppSettings["WebApiBaseUrl"]);
                //HTTP GET
                var responseMessageTask = client.GetAsync("api/Auction/GetBid?auctionid=" + auctionid);
                responseMessageTask.Wait();
                var responseMessage = responseMessageTask.Result;
                if (responseMessage.IsSuccessStatusCode)
                {
                    var responseContentTask = responseMessage.Content.ReadAsAsync <Auction.Model.Message.Auction>();
                    responseContentTask.Wait();
                    userAuction     = responseContentTask.Result;
                    TempData["Bid"] = userAuction;

                    if (TempData["Error"] != null)
                    {
                        ModelState.AddModelError("", TempData["Error"].ToString());
                        TempData["Error"] = null;
                    }
                    return(View("CustomerBid", userAuction));
                }
                else //web api sent error response
                {
                    //log response status here..
                    return(View("MyBids", userAuction));
                }
            }
        }