Пример #1
0
        public IActionResult Keranjang()
        {
            if (HttpContext.Session.GetString(SessionKeyID) != null && HttpContext.Session.GetString(SessionKeyID) != "")
            {
                List <ViewResultCartModel> OutPutData = new List <ViewResultCartModel>();
                ViewCartInputModel         filter     = new ViewCartInputModel();
                filter.UserID = Guid.Parse(HttpContext.Session.GetString(SessionKeyID));
                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri(BaseAPI + "Site/");
                    var responseTask = client.PostAsJsonAsync <ViewCartInputModel>("ViewCart", filter);
                    responseTask.Wait();

                    var result = responseTask.Result;
                    if (result.IsSuccessStatusCode)
                    {
                        var content = result.Content.ReadAsStringAsync();
                        ViewArrayCartResponse resutl = Newtonsoft.Json.JsonConvert.DeserializeObject <ViewArrayCartResponse>(content.Result);
                        OutPutData = resutl.Data;
                    }
                    else                     //web api sent error response
                    {
                        //log response status here..
                        ModelState.AddModelError(string.Empty, "Terjadi kesalahan server. Hubungi admin.");
                    }
                }
                return(View(OutPutData));
            }
            else
            {
                TempData["CustomError"] = "Mohon masuk sebelum mengakses halaman ini.";
                return(RedirectToAction("Index", "Home"));
            }
        }
Пример #2
0
        public IActionResult Keranjang()
        {
            if (HttpContext.Session.GetString(SessionKeyID) != null && HttpContext.Session.GetString(SessionKeyID) != "")
            {
                List <ViewResultCartModel> OutPutData = new List <ViewResultCartModel>();
                ViewCartInputModel         filter     = new ViewCartInputModel();
                filter.UserID = Guid.Parse(HttpContext.Session.GetString(SessionKeyID));
                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri(BaseAPI + "Site/");
                    var responseTask = client.PostAsJsonAsync <ViewCartInputModel>("ViewCart", filter);
                    responseTask.Wait();

                    var result = responseTask.Result;
                    if (result.IsSuccessStatusCode)
                    {
                        var content = result.Content.ReadAsStringAsync();
                        ViewArrayCartResponse resutl = Newtonsoft.Json.JsonConvert.DeserializeObject <ViewArrayCartResponse>(content.Result);
                        OutPutData = resutl.Data;
                    }
                    else                     //web api sent error response
                    {
                        //log response status here..
                        ModelState.AddModelError(string.Empty, "Server error. Please contact administrator.");
                    }
                }
                return(View(OutPutData));
            }
            else
            {
                TempData["CustomError"] = "Please login before using the web.";
                if (HttpContext.Session.GetString(Loginfrom) == "ADM/SPV")
                {
                    return(RedirectToAction("AdminLogon", "Login"));
                }
                else if (HttpContext.Session.GetString(Loginfrom) == "MDO")
                {
                    return(RedirectToAction("OwnerLogon", "Login"));
                }
                else
                {
                    return(RedirectToAction("BuyerLogon", "Login"));
                }
                //return RedirectToAction("Logon", "Login");
            }
        }
Пример #3
0
        public ActionResult <ViewArrayCartResponse> ViewCart([FromBody] ViewCartInputModel data)
        {
            ViewArrayCartResponse res = new ViewArrayCartResponse();

            try
            {
                BookBL bl = new BookBL(DbContext);
                res = bl.ViewCart(data);

                res.Message  = "Success";
                res.Response = true;

                return(Ok(res));
            }
            catch (Exception ex)
            {
                res.Message  = ex.Message;
                res.Response = false;

                return(BadRequest(res));
            }
        }
Пример #4
0
        public IActionResult AddToBooked()
        {
            if (HttpContext.Session.GetString(SessionKeyID) != null && HttpContext.Session.GetString(SessionKeyID) != "")
            {
                List <ViewResultCartModel> OutPutData = new List <ViewResultCartModel>();
                ViewCartInputModel         filter     = new ViewCartInputModel();
                filter.UserID = Guid.Parse(HttpContext.Session.GetString(SessionKeyID));
                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri(BaseAPI + "Site/");
                    var responseTask = client.PostAsJsonAsync <ViewCartInputModel>("ViewCart", filter);
                    responseTask.Wait();

                    var result = responseTask.Result;
                    if (result.IsSuccessStatusCode)
                    {
                        var content = result.Content.ReadAsStringAsync();
                        ViewArrayCartResponse resutl = Newtonsoft.Json.JsonConvert.DeserializeObject <ViewArrayCartResponse>(content.Result);
                        OutPutData = resutl.Data;
                        AddToBookListInputModel bookData = new AddToBookListInputModel();
                        bookData.isFromCart = true;
                        bookData.Data       = new List <AddBookInputModel>();
                        foreach (var book in OutPutData)
                        {
                            AddBookInputModel Data = new AddBookInputModel();
                            Data.SitePriceID  = book.Site.Detail.Item.Price.PriceID;
                            Data.SiteID       = book.Site.Detail.Item.SiteID;
                            Data.SiteItemID   = book.Site.Detail.Item.SiteItemID;
                            Data.UserID       = book.UserID;
                            Data.StartDate    = book.StartDate;
                            Data.EndDate      = book.EndDate;
                            Data.Qty          = book.Qty;
                            Data.Price        = book.Price;
                            Data.TotalPerItem = book.TotalHargaPerItem;
                            Data.CartID       = book.CartID;
                            bookData.Data.Add(Data);
                        }

                        using (var clientBook = new HttpClient())
                        {
                            clientBook.BaseAddress = new Uri(BaseAPI + "Site/");
                            var responseTaskbook = clientBook.PostAsJsonAsync <AddToBookListInputModel>("AddToBooked", bookData);
                            responseTaskbook.Wait();

                            var resultbook = responseTaskbook.Result;
                            if (resultbook.IsSuccessStatusCode)
                            {
                                return(RedirectToAction("Index", "Booking"));
                            }
                            else                             //web api sent error response
                            {
                                //log response status here..
                                ModelState.AddModelError(string.Empty, "Server error. Please contact administrator.");
                                return(RedirectToAction("Keranjang", "Wish"));
                            }
                        }
                    }
                    else                     //web api sent error response
                    {
                        //log response status here..
                        ModelState.AddModelError(string.Empty, "Server error. Please contact administrator.");
                        return(RedirectToAction("Keranjang", "Wish"));
                    }
                }
            }
            else
            {
                TempData["CustomError"] = "Please login before using the web.";
                if (HttpContext.Session.GetString(Loginfrom) == "ADM/SPV")
                {
                    return(RedirectToAction("AdminLogon", "Login"));
                }
                else if (HttpContext.Session.GetString(Loginfrom) == "MDO")
                {
                    return(RedirectToAction("OwnerLogon", "Login"));
                }
                else
                {
                    return(RedirectToAction("BuyerLogon", "Login"));
                }
                //return RedirectToAction("Logon", "Login");
            }
        }