コード例 #1
0
        public ActionResult <AddToCartResponseModel> AddToCart([FromBody] AddBookInputModel data)
        {
            AddToCartResponseModel res = new AddToCartResponseModel();

            try
            {
                BookBL bl   = new BookBL(DbContext);
                var    temp = bl.SaveCart(data);


                res.data = temp;

                if (temp.BookID == Guid.Empty)
                {
                    res.Message  = "Item ini sudah ada di list keranjang / list order";
                    res.Response = false;
                }
                else
                {
                    res.Message  = "Item berhasil ditambahkan di keranjang";
                    res.Response = true;
                }



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

                return(BadRequest(res));
            }
        }
コード例 #2
0
        public IActionResult AddToBooked()
        {
            AddBookOutputModel OutPutData = new AddBookOutputModel();
            AddBookInputModel  filter     = new AddBookInputModel();

            filter.UserID       = Guid.Parse(HttpContext.Session.GetString(SessionKeyID));
            filter.SiteID       = Guid.Parse("");
            filter.SiteItemID   = Guid.Parse("");
            filter.SitePriceID  = Guid.Parse("");
            filter.Qty          = 1;
            filter.Price        = double.Parse("");
            filter.TotalPerItem = double.Parse("");
            //filter.StartDate =
            //filter.EndDate =
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(BaseAPI + "Site/");
                var responseTask = client.PostAsJsonAsync <AddBookInputModel>("AddToBooked", filter);
                responseTask.Wait();

                var result = responseTask.Result;
                if (result.IsSuccessStatusCode)
                {
                    var content = result.Content.ReadAsStringAsync();
                    AddBookResponseModel resutl = Newtonsoft.Json.JsonConvert.DeserializeObject <AddBookResponseModel>(content.Result);
                    OutPutData = resutl.data;
                }
                else                 //web api sent error response
                {
                    //log response status here..
                    ModelState.AddModelError(string.Empty, "Terjadi kesalahan. Mohon hubungi admin.");
                }
            }
            return(Json(OutPutData));
        }
コード例 #3
0
        public IActionResult AddtoCart(AddtoCartSite info)
        {
            AddBookInputModel data = new AddBookInputModel();

            System.TimeSpan   diffResult = info.EndDate - info.StartDate;
            BaseResponseModel resutl     = new BaseResponseModel();

            //temp user
            data.UserID = Guid.Parse(HttpContext.Session.GetString(SessionKeyID));
            //  data.UserID = Guid.Parse("8E8C7738-5076-4E04-A1FB-DAD4A7C2AC21");
            //end temp user
            data.SiteID       = info.SiteID;
            data.SiteItemID   = info.SiteItemID;
            data.SitePriceID  = info.SitePriceID;
            data.StartDate    = info.StartDate;
            data.EndDate      = info.EndDate;
            data.Price        = info.Price;
            data.TotalPerItem = info.Price * diffResult.Days;
            data.Qty          = diffResult.Days;

            CheckDateAvailableInputModel checkDate = new CheckDateAvailableInputModel();

            checkDate.SiteID     = info.SiteID;
            checkDate.SiteItemID = info.SiteItemID;
            checkDate.StartDate  = info.StartDate;
            checkDate.EndDate    = info.EndDate;


            using (var clientCheck = new HttpClient())
            {
                clientCheck.BaseAddress = new Uri(BaseAPI + "Site/");
                //HTTP POST
                var postTaskCheck = clientCheck.PostAsJsonAsync <CheckDateAvailableInputModel>("CheckAvailableSite", checkDate);
                postTaskCheck.Wait();

                var resultCheck = postTaskCheck.Result;
                if (resultCheck.IsSuccessStatusCode)
                {
                    var contentcheck = resultCheck.Content.ReadAsStringAsync();
                    CheckDateAvailableResponseModel resutlcheck = Newtonsoft.Json.JsonConvert.DeserializeObject <CheckDateAvailableResponseModel>(contentcheck.Result);
                    if (resutlcheck.data.CanBook == true)
                    {
                        using (var client = new HttpClient())
                        {
                            client.BaseAddress = new Uri(BaseAPI + "Site/");
                            //HTTP POST
                            var postTask = client.PostAsJsonAsync <AddBookInputModel>("AddToCart", data);
                            postTask.Wait();

                            var result = postTask.Result;
                            if (result.IsSuccessStatusCode)
                            {
                                resutl.Response = true;
                                resutl.Message  = "Add To Cart Successfully.";
                            }
                            else
                            {
                                resutl.Response = false;
                                resutl.Message  = "Fail to add data. Please contact administrator.";
                            }
                        }
                    }
                    else
                    {
                        resutl.Response = false;
                        resutl.Message  = "Fail to add data, date not available. Please contact administrator.";
                    }
                }
                else
                {
                    resutl.Response = false;
                    resutl.Message  = "Fail to add data. Please contact administrator.";
                }
            }


            //ForDetail site = new ForDetail();
            //using (var client = new HttpClient())
            //{

            //}

            return(Ok(resutl));
        }
コード例 #4
0
        public ActionResult AddtoBook(string siteID, string sitePriceID, string siteItemID, string price, string durasi, string totalprice, string startDate, string endDate)
        {
            AddBookOutputModel OutPutData = new AddBookOutputModel();

            if (HttpContext.Session.GetString(SessionKeyID) != null && HttpContext.Session.GetString(SessionKeyID) != "")
            {
                AddToBookListInputModel bookData = new AddToBookListInputModel();
                bookData.isFromCart = false;
                bookData.Data       = new List <AddBookInputModel>();

                AddBookInputModel Data = new AddBookInputModel();
                Data.SitePriceID  = Guid.Parse(sitePriceID);
                Data.SiteID       = Guid.Parse(siteID);
                Data.SiteItemID   = Guid.Parse(siteItemID);
                Data.UserID       = Guid.Parse(HttpContext.Session.GetString(SessionKeyID));
                Data.StartDate    = DateTime.Parse(startDate);
                Data.EndDate      = DateTime.Parse(endDate);
                Data.Qty          = int.Parse(durasi);
                Data.Price        = double.Parse(price);
                Data.TotalPerItem = double.Parse(totalprice);
                Data.CartID       = Guid.Empty;
                bookData.Data.Add(Data);
                JsonConvert.SerializeObject(bookData);

                CheckDateAvailableInputModel checkDate = new CheckDateAvailableInputModel();
                checkDate.SiteID     = Guid.Parse(siteID);
                checkDate.SiteItemID = Guid.Parse(siteItemID);
                checkDate.StartDate  = DateTime.Parse(startDate);
                checkDate.EndDate    = DateTime.Parse(endDate);
                using (var clientCheck = new HttpClient())
                {
                    clientCheck.BaseAddress = new Uri(BaseAPI + "Site/");
                    //HTTP POST
                    var postTaskCheck = clientCheck.PostAsJsonAsync <CheckDateAvailableInputModel>("CheckAvailableSite", checkDate);
                    postTaskCheck.Wait();

                    var resultCheck = postTaskCheck.Result;
                    if (resultCheck.IsSuccessStatusCode)
                    {
                        var contentcheck = resultCheck.Content.ReadAsStringAsync();
                        CheckDateAvailableResponseModel resutlcheck = Newtonsoft.Json.JsonConvert.DeserializeObject <CheckDateAvailableResponseModel>(contentcheck.Result);
                        if (resutlcheck.data.CanBook == true)
                        {
                            using (var client = new HttpClient())
                            {
                                client.BaseAddress = new Uri(BaseAPI + "Site/");
                                //HTTP POST
                                var postTask = client.PostAsJsonAsync <AddToBookListInputModel>("AddToBooked", bookData);
                                postTask.Wait();

                                var result = postTask.Result;
                                if (result.IsSuccessStatusCode)
                                {
                                    return(RedirectToAction("Index", "Booking"));
                                    //var content = result.Content.ReadAsStringAsync();
                                    //AddBookResponseModel resutl = Newtonsoft.Json.JsonConvert.DeserializeObject<AddBookResponseModel>(content.Result);
                                    //OutPutData = resutl.data;
                                }
                                else
                                {
                                    TempData["CustomError"] = "Fail to add data. Please contact administrator.";
                                }
                            }
                        }
                        else
                        {
                            TempData["CustomError"] = "Fail to add data, date not available. Please contact administrator.";
                        }
                    }
                    else
                    {
                        TempData["CustomError"] = "Fail to add data. Please contact administrator.";
                    }
                }
                return(Json(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");
            }
        }
コード例 #5
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");
            }
        }