public async Task <IHttpActionResult> AddItemToCart(int itemId)
        {
            var cart = await GetCurrentFullCart();

            if (cart == null)
            {
                return(NotFound());
            }

            var record = cart.Records.Find(r => r.SiteTemplate != null && r.SiteTemplate.Id == itemId);

            if (record == null)
            {
                record = new CartRecord()
                {
                    SiteTemplate = DB.SiteTemplates.Find(itemId),
                    ShoppingCart = cart,
                    Count        = 1,
                };
                DB.CartRecords.Add(record);
            }
            else
            {
                record.Count++;
            }
            await DB.SaveChangesAsync();

            return(Ok(TheModelFactory.Create(cart)));
        }
Пример #2
0
        public async Task <IHttpActionResult> PutCartRecord(int id, CartRecord cartRecord)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != cartRecord.CartRecordID)
            {
                return(BadRequest());
            }

            db.Entry(cartRecord).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CartRecordExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Пример #3
0
        public void AddToCart(SiteTemplate siteTemplate)
        {
            // Get the matching cart and album instances
            var cartItem = unitOfWork.CartRepository.Get().ToList <CartRecord>().SingleOrDefault(
                c => c.CartId == OrderCartId &&
                c.SiteTemplate.Id == siteTemplate.Id);

            if (cartItem == null)
            {
                // Create a new cart item if no cart item exists
                cartItem = new CartRecord
                {
                    SiteTemplate = siteTemplate,
                    CartId       = OrderCartId,
                    Count        = 1,
                    DateCreated  = DateTime.Now
                };
                unitOfWork.CartRepository.Insert(cartItem);
            }
            else
            {
                // If the item does exist in the cart,
                // then add one to the quantity
                cartItem.Count++;
            }
            // Save changes
            unitOfWork.Save();
        }
Пример #4
0
 public CartRecordReturnModel Create(CartRecord record)
 {
     return(new CartRecordReturnModel()
     {
         SiteTemplate = Create(record.SiteTemplate),
         Id = record.Id,
         Count = record.Count
     });
 }
Пример #5
0
        public async Task <IHttpActionResult> GetCartRecord(int id)
        {
            CartRecord cartRecord = await db.CartRecords.FindAsync(id);

            if (cartRecord == null)
            {
                return(NotFound());
            }

            return(Ok(cartRecord));
        }
Пример #6
0
        public async Task <IHttpActionResult> PostCartRecord(CartRecord cartRecord)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.CartRecords.Add(cartRecord);
            await db.SaveChangesAsync();

            return(CreatedAtRoute("DefaultApi", new { id = cartRecord.CartRecordID }, cartRecord));
        }
        private void Button_Clicked_3(object sender, EventArgs e)
        {
            var        button = sender as Button;
            CartRecord cart   = new CartRecord();

            if (cart == null)
            {
                button.IsVisible = !button.IsVisible;
            }
            Detail      = new NavigationPage(new Cart());
            IsPresented = false;
        }
Пример #8
0
        public async Task <IHttpActionResult> DeleteCartRecord(int id)
        {
            CartRecord cartRecord = await db.CartRecords.FindAsync(id);

            if (cartRecord == null)
            {
                return(NotFound());
            }

            db.CartRecords.Remove(cartRecord);
            await db.SaveChangesAsync();

            return(Ok(cartRecord));
        }
        private void Button_Clicked(object sender, EventArgs e)
        {
            CartRecord pd    = new CartRecord();
            int        qty   = Convert.ToInt32(Qty.Text);
            int        total = Convert.ToInt16(pPrice);

            pd.Name  = MyTitle.Text;
            pd.Price = MyPrice.Text;
            pd.Total = (qty * total).ToString();
            pd.Qty   = qty + "";
            pd.Image = pImage;
            CartQuery c = new CartQuery();

            c.InsertDetails(pd);
            Navigation.PushAsync(new Cart());
        }
Пример #10
0
        public void Add_btn_Clicked(object sender, EventArgs e)
        {
            CartRecord pd    = new CartRecord();
            int        qty   = Convert.ToInt16(Qty.Text);
            double     total = Convert.ToDouble(pprice);

            pd.Name  = Name.Text;
            pd.Price = Price.Text;
            pd.Total = (qty * total).ToString();
            pd.Qty   = qty + "";
            pd.Image = pimage;
            CartQuery c = new CartQuery();

            c.InsertDetails(pd);
            GC.Collect(1);
            Navigation.PushAsync(new Cart());
        }
Пример #11
0
        public async Task <IHttpActionResult> AddToCart(int GoodID, [FromBody] CartRequest cartRequest)
        {
            var usr = (User)HttpContext.Current.User;

            System.Diagnostics.Debug.WriteLine("Enter the function");
            int addNumber = 1;

            if (cartRequest != null && cartRequest.Number != null)
            {
                addNumber = cartRequest.Number ?? 1;
            }
            SaleEntity saleEntity = await db.SaleEntities.FindAsync(GoodID);

            if (saleEntity == null)
            {
                System.Diagnostics.Debug.WriteLine("Not found saleEntity");
                return(NotFound());
            }
            System.Diagnostics.Debug.WriteLine("GetCarts has:" + usr.NickName);
            CartRecord record;

            try
            {
                record = await db.CartRecords.FirstAsync(u => u.SaleEntityID == saleEntity.SaleEntityID);

                System.Diagnostics.Debug.WriteLine("Found Record.");
            } catch (InvalidOperationException _)
            {
                System.Diagnostics.Debug.WriteLine("Record not found, so create it");
                record = new CartRecord()
                {
                    RecordNum    = 0,
                    UserID       = usr.UserID,
                    SaleEntityID = GoodID
                };
                db.CartRecords.Add(record);
            }

            record.RecordNum += addNumber;
            await db.SaveChangesAsync();

            return(ResponseMessage(Request.CreateResponse(HttpStatusCode.NoContent)));
        }