Esempio n. 1
0
        public void Login()
        {
            SelectBrowser(_browserType);
            var loginForm = new LoginForm(Driver);

            loginForm.Open();
            _offeringsPage = loginForm.SignInAsExistingWpUser();
        }
Esempio n. 2
0
 public void ClearOfferings()
 {
     Offerings.Clear();
     Offerings.Add(new OfferingModel(204));
     for (int i = 0; i < 9; ++i)
     {
         Offerings.Add(new OfferingModel());
     }
 }
Esempio n. 3
0
 void Start()
 {
     offer = Offerings.getRandomOffer(Offerings.offeringList1);
     prompt.SetText(offer.Offering);
     ControlFactors.setPlayerCast(false);
 }
Esempio n. 4
0
        public async Task <IActionResult> AddDoc([FromBody] Basket newBasketItem)
        {
            // check if the model binds correctly
            if (ModelState.IsValid)
            {
                // get the users ID from the HttpContext
                var ID = GetID();

                // The ID should never be NULL because they wouldn't have been authorized but checking anyways
                if (ID == null)
                {
                    return(BadRequest(new BadRequestError("user_id not found.")));
                }

                var doc = await _bucket.GetAsync <Basket>(ID); // check to see if a document for the user exists or not

                if (!doc.Success)                              // if the user doesn't already have a basket document make a new one
                {
                    // check to see if the GUID is set or not
                    if (newBasketItem.Uid == null)
                    {
                        newBasketItem.Uid = Guid.NewGuid();
                    }
                    // update the total number of offerings count in the document
                    newBasketItem.total_items = newBasketItem.Offerings.Count();

                    newBasketItem.total_cost = newBasketItem.Offerings[0].Unit_retail * newBasketItem.Offerings[0].Quantity;
                    newBasketItem.Offerings[0].totalOfferingCost = newBasketItem.total_cost;
                    // attempt to insert the new document
                    var response = await _bucket.UpsertAsync(ID, newBasketItem);

                    // return a BadReuqest if this fails
                    if (!response.Success)
                    {
                        return(BadRequest(newBasketItem));
                    }
                    // otherwise return 200 OK
                    return(Ok(response.ToString()));
                }

                Basket userDoc = doc.Value;

                // find if the product offering already exists, if it does replace it with the new one

                if (userDoc.Offerings.Exists(i => i.Offering_key == newBasketItem.Offerings[0].Offering_key))
                {
                    Offerings userOffering = userDoc.Offerings.Find(i => i.Offering_key == newBasketItem.Offerings[0].Offering_key);

                    // get the index of duplicate item currently stored in the basket doc if it eists
                    var index = userDoc.Offerings.IndexOf(userOffering, 0);

                    // if there is a duplicate item add the quantities together
                    if (index != -1)
                    {
                        userDoc.total_cost += newBasketItem.Offerings[0].Unit_retail * newBasketItem.Offerings[0].Quantity;
                        userDoc.Offerings[index].Quantity         += newBasketItem.Offerings[0].Quantity;
                        userDoc.Offerings[index].totalOfferingCost = newBasketItem.Offerings[0].Unit_retail * userDoc.Offerings[index].Quantity;
                    }
                }
                else // if there isn't a duplicate item insert the new item being added at the beginning of the list
                {
                    userDoc.total_cost += newBasketItem.Offerings[0].Unit_retail * newBasketItem.Offerings[0].Quantity;
                    newBasketItem.Offerings[0].totalOfferingCost = newBasketItem.Offerings[0].Unit_retail * newBasketItem.Offerings[0].Quantity;
                    userDoc.Offerings = userDoc.Offerings.Prepend(newBasketItem.Offerings[0]).ToList();
                }

                // update the total count of the number of offerings stored in the document
                userDoc.total_items = userDoc.Offerings.Count();

                // attempt to insert the updated document into the Basket bucket
                var result = await _bucket.UpsertAsync(ID, userDoc);

                // if the upsert fails return a bad request
                if (!result.Success)
                {
                    return(BadRequest(newBasketItem));
                }

                // if document was successfully replaced return 200 OK
                return(Ok(newBasketItem));
            }

            return(Conflict());
        }