protected void Page_Load(object sender, EventArgs e) { string ResponseValue = ""; string ResponseString = ""; List <IProductByStore> ProductByStore = null; try { UserProfile UserProfileObj = new UserProfile(); UserProfileObj.SetToken(CookieProxy.Instance().GetValue("t").ToString()); ProductByStore = new ProductByStoreBusinessLayerTemplate(UserProfileObj).Select(); if (null == ProductByStore) { ResponseValue = APIResponse.NOT_OK.ToString(); ResponseString = "NOT_AUTHENTICATED"; CookieProxy.Instance().SetValue("LoginMessage", "Not Authorized, please login with correct credentials".ToString(), DateTime.Now.AddDays(2)); } else { Logger.Instance().Log(Info.Instance(), new LogInfo(new AdminUserTemplate().FetchParticularProfile(UserProfileObj).GetEmail() + " fetched store list ")); ResponseValue = APIResponse.OK.ToString(); ResponseString = "SUCCESS"; } } catch (NullReferenceException nex) { CookieProxy.Instance().SetValue("LoginMessage", "Not Authorized, please login with correct credentials. If you believe this is an error, please check logs".ToString(), DateTime.Now.AddDays(2)); Logger.Instance().Log(Warn.Instance(), nex); ResponseValue = APIResponse.NOT_OK.ToString(); ResponseString = "NOT_AUTHENTICATED"; } catch (Exception ex) { Logger.Instance().Log(Warn.Instance(), ex); ResponseValue = APIResponse.NOT_OK.ToString(); ResponseString = "Unable to fetch the list of stores, please check logs"; } finally { var output = new { Code = ResponseValue, Response = ResponseString, ProductByStoreList = ProductByStore }; Response.Write(new JavaScriptSerializer().Serialize(output)); } }
protected void Page_Load(object sender, EventArgs e) { APIResponse ApiResponse = APIResponse.NOT_OK; int Quantity = 0; Cart CartObj = new Cart(); try { if (CookieProxy.Instance().HasKey("Cart")) { CartObj = new JavaScriptSerializer().Deserialize <Cart>(CookieProxy.Instance().GetValue("Cart").ToString()); foreach (CartItems Items in CartObj.CartItems) { IProductByStore PBSObj = new ProductByStore(); PBSObj.SetProductByStoreID(Items.ProductObj.pbsID); Products DBProductQty = new ProductByStoreBusinessLayerTemplate().Select(PBSObj); if (GetMaxQty < DBProductQty.Quantity) { Items.DBQuantity = GetMaxQty; } else { Items.DBQuantity = DBProductQty.Quantity; } if (Items.ProductObj.Quantity < 0) { CartObj.HasValidationErrors = true; Items.ProductObj.Quantity = -1; Items.HasQuantity = false; } else if (DBProductQty.Quantity < Items.ProductObj.Quantity && Items.ProductObj.Quantity <= 0) { CartObj.HasValidationErrors = true; Items.ProductObj.Quantity = -1; Items.HasQuantity = false; } else if (DBProductQty.Quantity < Items.ProductObj.Quantity) { CartObj.HasValidationErrors = true; Items.HasQuantity = false; } Quantity = CartObj.CartItems.Count; } } ApiResponse = APIResponse.OK; } catch (Exception ex) { Logger.Instance().Log(Warn.Instance(), ex); ApiResponse = APIResponse.NOT_OK; } finally { var Cart = new { Response = ApiResponse.ToString(), Quantity, Cart = new JavaScriptSerializer().Serialize(CartObj) }; Response.Write(new JavaScriptSerializer().Serialize(Cart)); } }
protected void Page_Load(object sender, EventArgs e) { APIResponse ResponseENUM = APIResponse.NOT_OK; string ResponseString = ""; try { Cart CartObj = null; if (CookieProxy.Instance().HasKey("Cart")) { int PBSId = int.Parse(Request.Form["pbsid"].ToString()); CartObj = new JavaScriptSerializer().Deserialize <Cart>(CookieProxy.Instance().GetValue("Cart").ToString()); int Iterator = 0; foreach (CartItems Cart in CartObj.CartItems) { if (Cart.ProductObj.pbsID == PBSId) { int Quantity = int.Parse(Request.Form["qty"].ToString()); IProductByStore PBSObj = new ProductByStore(); PBSObj.SetProductByStoreID(PBSId); Products DBProductQty = new ProductByStoreBusinessLayerTemplate().Select(PBSObj); if (Quantity <= DBProductQty.Quantity) { Cart.ProductObj.Quantity = Quantity; ResponseENUM = APIResponse.OK; ResponseString = "SUCCESS"; } else { Cart.ProductObj.Quantity = Quantity; ResponseENUM = APIResponse.NOT_OK; ResponseString = "CURRENT QUANTITY NOT AVAILABLE, PLEASE REFRESH THE PAGE TO SEE UPDATED QUANTITY"; } break; } Iterator += 1; } CookieProxy.Instance().SetValue("Cart", new JavaScriptSerializer().Serialize(CartObj), DateTime.Now.AddDays(5)); } else { ResponseENUM = APIResponse.NOT_OK; ResponseString = "AN ERROR OCCURED WHILE READING THE CART, PLEASE CLEAR YOUR COOKIES"; } } catch (Exception ex) { Logger.Instance().Log(Warn.Instance(), ex); ResponseENUM = APIResponse.NOT_OK; ResponseString = "AN ERROR OCCURED WHILE READING THE CART, PLEASE CLEAR YOUR COOKIES"; } finally { var ReturnObj = new { Response = ResponseENUM.ToString(), ResponseString }; Response.Write(new JavaScriptSerializer().Serialize(ReturnObj)); } }