コード例 #1
0
        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));
        }
コード例 #2
0
        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
            });
        }
コード例 #3
0
ファイル: Cart.cs プロジェクト: anthrax3/mojoPortal-WebStore
        public static bool DeleteByStore(Guid storeGuid, DateTime olderThan)
        {
            CartOffer.DeleteByStore(storeGuid, olderThan);
            CartOrderInfo.DeleteByStore(storeGuid, olderThan);

            return(DBCart.DeleteByStore(storeGuid, olderThan));
        }
コード例 #4
0
ファイル: Cart.cs プロジェクト: anthrax3/mojoPortal-WebStore
 private void GetCart(Guid cartGuid)
 {
     using (IDataReader reader = DBCart.GetCart(cartGuid))
     {
         GetCart(reader);
     }
 }
コード例 #5
0
ファイル: Cart.cs プロジェクト: anthrax3/mojoPortal-WebStore
        public static bool Delete(Guid cartGuid)
        {
            CartOffer.DeleteByCart(cartGuid);
            CartOrderInfo.Delete(cartGuid);

            return(DBCart.DeleteCart(cartGuid));
        }
コード例 #6
0
ファイル: Cart.cs プロジェクト: anthrax3/mojoPortal-WebStore
 /// <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));
 }
コード例 #7
0
ファイル: Cart.cs プロジェクト: anthrax3/mojoPortal-WebStore
        public void LoadExistingUserCartIfExists()
        {
            if (this.userGuid == Guid.Empty)
            {
                return;
            }

            using (IDataReader reader = DBCart.GetByUser(userGuid, storeGuid))
            {
                GetCart(reader);
            }
        }
コード例 #8
0
ファイル: Cart.cs プロジェクト: anthrax3/mojoPortal-WebStore
 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));
 }
コード例 #9
0
        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));
        }
コード例 #10
0
        //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));
        }
コード例 #11
0
ファイル: Cart.cs プロジェクト: anthrax3/mojoPortal-WebStore
        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);
        }
コード例 #12
0
ファイル: Cart.cs プロジェクト: anthrax3/mojoPortal-WebStore
        public bool HasShippingProducts()
        {
            int count = DBCart.GetItemCountByFulfillmentType(this.cartGuid, (byte)FulfillmentType.PhysicalShipment);

            return(count > 0);
        }
コード例 #13
0
ファイル: Cart.cs プロジェクト: anthrax3/mojoPortal-WebStore
        public bool HasDownloadProducts()
        {
            int count = DBCart.GetItemCountByFulfillmentType(this.cartGuid, (byte)FulfillmentType.Download);

            return(count > 0);
        }