public HttpResponseMessage Delete(int id)
        {
            var authenticationIdentity = Thread.CurrentPrincipal.Identity as JWTAuthenticationIdentity;
            int userId = authenticationIdentity.UserId;

            IEnumerable <DBCart> crds = db.Carts.Where(c =>
                                                       c.UserId == userId &&
                                                       c.ProductId == id
                                                       );

            if (crds.Count() == 0)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound, $"Product with id {id} doesn't exist.", Configuration.Formatters.JsonFormatter));
            }

            DBCart cart = crds.First();

            if (cart == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound, $"Product with id {id} doesn't exist.", Configuration.Formatters.JsonFormatter));
            }

            db.Carts.Remove(cart);
            db.SaveChanges();

            return(Request.CreateResponse(HttpStatusCode.OK, cart, Configuration.Formatters.JsonFormatter));
        }
        internal Cart Map(DBCart dbCart)
        {
            DBProduct prod = db.Products.Find(dbCart.ProductId);

            if (prod == null)
            {
                return(null);
            }

            DBCategory c = db.Categories.Find(prod.CategoryId);

            if (dbCart == null)
            {
                return(null);
            }

            return(new Cart()
            {
                Product = new Product
                {
                    Id = prod.Id,
                    Name = prod.Name,
                    Price = prod.Price,
                    Category = new Category {
                        Id = c.Id, Name = c.Name
                    },
                    Image = prod.Image,
                    Description = prod.Description
                },
                Quantity = dbCart.Quantity
            });
        }
Beispiel #3
0
        public static bool DeleteByStore(Guid storeGuid, DateTime olderThan)
        {
            CartOffer.DeleteByStore(storeGuid, olderThan);
            CartOrderInfo.DeleteByStore(storeGuid, olderThan);

            return(DBCart.DeleteByStore(storeGuid, olderThan));
        }
Beispiel #4
0
 private void GetCart(Guid cartGuid)
 {
     using (IDataReader reader = DBCart.GetCart(cartGuid))
     {
         GetCart(reader);
     }
 }
Beispiel #5
0
        public static bool Delete(Guid cartGuid)
        {
            CartOffer.DeleteByCart(cartGuid);
            CartOrderInfo.Delete(cartGuid);

            return(DBCart.DeleteCart(cartGuid));
        }
Beispiel #6
0
 /// <summary>
 /// Gets a page of data from the ws_Cart table.
 /// </summary>
 /// <param name="pageNumber">The page number.</param>
 /// <param name="pageSize">Size of the page.</param>
 /// <param name="totalPages">total pages</param>
 public static IDataReader GetPage(
     Guid storeGuid,
     int pageNumber,
     int pageSize,
     out int totalPages)
 {
     return(DBCart.GetPage(
                storeGuid,
                pageNumber,
                pageSize,
                out totalPages));
 }
Beispiel #7
0
        public void LoadExistingUserCartIfExists()
        {
            if (this.userGuid == Guid.Empty)
            {
                return;
            }

            using (IDataReader reader = DBCart.GetByUser(userGuid, storeGuid))
            {
                GetCart(reader);
            }
        }
Beispiel #8
0
 private bool Update()
 {
     return(DBCart.UpdateCart(
                this.cartGuid,
                this.userGuid,
                this.subTotal,
                this.shippingTotal,
                this.taxTotal,
                this.orderTotal,
                this.lastModified,
                this.lastUserActivity,
                this.discount,
                this.discountCodesCsv,
                this.customData,
                this.clerkGuid));
 }
        public HttpResponseMessage Patch([FromBody] DBCart value)
        {
            var authenticationIdentity = Thread.CurrentPrincipal.Identity as JWTAuthenticationIdentity;
            int userId = authenticationIdentity.UserId;

            IEnumerable <DBCart> crds = db.Carts.Where(c =>
                                                       c.UserId == userId &&
                                                       c.ProductId == value.ProductId
                                                       );

            if (crds.Count() == 0)
            {
                return(Request.CreateResponse(HttpStatusCode.Forbidden, $"Product with id {value.ProductId} is not in the cart.", Configuration.Formatters.JsonFormatter));
            }

            DBCart cart = crds.First();

            cart.Quantity = value.Quantity;
            db.SaveChanges();

            return(Request.CreateResponse(HttpStatusCode.OK));
        }
        //get add delete buy
        // POST <controller>
        public HttpResponseMessage Add([FromBody] DBCart value)
        {
            var authenticationIdentity = Thread.CurrentPrincipal.Identity as JWTAuthenticationIdentity;
            int userId = authenticationIdentity.UserId;

            if (db.Carts.Any(c => c.UserId == userId && c.ProductId == value.ProductId))
            {
                return(Request.CreateResponse(HttpStatusCode.Forbidden, $"Product with id {value.ProductId} is already in the cart.", Configuration.Formatters.JsonFormatter));
            }

            DBCart toAdd = new DBCart
            {
                Id        = value.Id,
                UserId    = userId,
                ProductId = value.ProductId,
                Quantity  = value.Quantity
            };

            db.Carts.Add(toAdd);
            db.SaveChanges();

            return(Request.CreateResponse(HttpStatusCode.OK));
        }
Beispiel #11
0
        private bool Create()
        {
            this.cartGuid = this.newCartID;

            int rowsAffected = DBCart.AddCart(
                this.cartGuid,
                this.storeGuid,
                this.userGuid,
                this.subTotal,
                this.shippingTotal,
                this.taxTotal,
                this.orderTotal,
                this.created,
                this.createdFromIP,
                this.lastModified,
                this.lastUserActivity,
                this.discount,
                this.discountCodesCsv,
                this.customData,
                this.clerkGuid);

            return(rowsAffected > 0);
        }
Beispiel #12
0
        public bool HasShippingProducts()
        {
            int count = DBCart.GetItemCountByFulfillmentType(this.cartGuid, (byte)FulfillmentType.PhysicalShipment);

            return(count > 0);
        }
Beispiel #13
0
        public bool HasDownloadProducts()
        {
            int count = DBCart.GetItemCountByFulfillmentType(this.cartGuid, (byte)FulfillmentType.Download);

            return(count > 0);
        }