Ejemplo n.º 1
0
 public HttpResponseMessage PutDecreaseCartItembyProidAndUserid(int proID, int userID, int state)
 {
     try
     {
         using (STUDY_SHOPEntities dbContext = new STUDY_SHOPEntities())
         {
             var entity = dbContext.CartItems.FirstOrDefault(e => e.Cart.UserId == userID && e.ProId == proID && e.Cart.IsPaid == state);
             if (entity == null)
             {
                 return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Không thể tim thấy cartitem với id = " + proID.ToString()));
             }
             else
             {
                 if (entity.Quantity > 1)
                 {
                     entity.Quantity = entity.Quantity - 1;
                     dbContext.SaveChanges();
                     return(Request.CreateResponse(HttpStatusCode.OK, entity));
                 }
                 else
                 {
                     return(Request.CreateResponse(HttpStatusCode.Conflict, entity));
                 }
             }
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.ToString()));
     }
 }
Ejemplo n.º 2
0
 public IEnumerable <testAPIDataAccess.returnListCartOfUser_Result> getListCartOfUser(int userID, int isPaid)
 {
     using (STUDY_SHOPEntities entity = new STUDY_SHOPEntities())
     {
         return(entity.returnListCartOfUser(userID, isPaid).ToList());
     }
 }
Ejemplo n.º 3
0
 public HttpResponseMessage Put(int id, [FromBody] Product product)
 {
     try
     {
         using (STUDY_SHOPEntities dbContext = new STUDY_SHOPEntities())
         {
             var entity = dbContext.Products.FirstOrDefault(e => e.Id == id);
             if (entity == null)
             {
                 return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Không thể tim thấy product với id = " + id.ToString()));
             }
             else
             {
                 entity.Name        = product.Name;
                 entity.Price       = product.Price;
                 entity.Discount    = product.Discount;
                 entity.CateId      = product.CateId;
                 entity.Description = product.Description;
                 entity.Information = product.Information;
                 entity.Image       = product.Image;
                 dbContext.SaveChanges();
                 return(Request.CreateResponse(HttpStatusCode.OK, entity));
             }
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.ToString()));
     }
 }
Ejemplo n.º 4
0
 public List <CartItem> getCartitemByCart(int cartID)
 {
     using (STUDY_SHOPEntities entity = new STUDY_SHOPEntities())
     {
         return(entity.CartItems.Where(x => x.Cart.Id == cartID).ToList());
     }
 }
Ejemplo n.º 5
0
 public IEnumerable <User> getAllUser()
 {
     using (STUDY_SHOPEntities entity = new STUDY_SHOPEntities())
     {
         return(entity.Users.ToList());
     }
 }
Ejemplo n.º 6
0
 public List <Cart> getAllProductOfUserCartAndisPaid(int userID2, int ispaid)
 {
     using (STUDY_SHOPEntities entity = new STUDY_SHOPEntities())
     {
         return(entity.Carts.Where(x => x.UserId == userID2 && x.IsPaid == ispaid).ToList());
     }
 }
Ejemplo n.º 7
0
        public IEnumerable <Product> get8ProductByIdCategoryAndPage(int idCategory, int page)
        {
            STUDY_SHOPEntities db        = new STUDY_SHOPEntities();
            List <Product>     Listprore = db.Products.Where(x => x.Category.CateId == idCategory).OrderByDescending(x => x.Id).ToList();
            List <Product>     Listkqre  = new List <Product>();
            int i = 0;

            foreach (Product k in Listprore)
            {
                if ((page - 1) * 8 <= i && page * 8 > i)
                {
                    Product p = new Product();
                    p.Id          = k.Id;
                    p.Name        = k.Name;
                    p.Price       = k.Price;
                    p.Discount    = k.Discount;
                    p.CateId      = k.CateId;
                    p.Description = k.Description;
                    p.Information = k.Information;
                    p.Image       = k.Image;
                    Listkqre.Add(p);
                }
                i++;
            }
            return(Listkqre.ToList());
        }
Ejemplo n.º 8
0
 public IEnumerable <Cart> getAllProductUserCartd(int userID3)
 {
     using (STUDY_SHOPEntities entity = new STUDY_SHOPEntities())
     {
         return(entity.Carts.Where(x => x.UserId == userID3).ToList());
     }
 }
Ejemplo n.º 9
0
 public int getAmountOfProductUserCart(int userID)
 {
     using (STUDY_SHOPEntities entity = new STUDY_SHOPEntities())
     {
         return(entity.Carts.Where(x => x.UserId == userID).Count());
     }
 }
Ejemplo n.º 10
0
 public IEnumerable <Cart> getCartByCartID(int cartID)
 {
     using (STUDY_SHOPEntities entity = new STUDY_SHOPEntities())
     {
         return(entity.Carts.Where(x => x.Id == cartID).ToList());
     }
 }
Ejemplo n.º 11
0
 public int getSoluongOfProductUserCartAndIsPaid(int userID1, int isPaid)
 {
     using (STUDY_SHOPEntities entity = new STUDY_SHOPEntities())
     {
         return(entity.Carts.Where(x => x.UserId == userID1 && x.IsPaid == isPaid).Count());
     }
 }
Ejemplo n.º 12
0
 public IEnumerable <Cart> getAllCart()
 {
     using (STUDY_SHOPEntities entity = new STUDY_SHOPEntities())
     {
         return(entity.Carts.ToList());
     }
 }
Ejemplo n.º 13
0
        public IEnumerable <Product> getNewestProduct(int amount)
        {
            STUDY_SHOPEntities db        = new STUDY_SHOPEntities();
            List <Product>     Listprore = db.Products.OrderByDescending(x => x.Id).ToList();
            List <Product>     Listkqre  = new List <Product>();
            int i = 0;

            foreach (Product k in Listprore)
            {
                Product p = new Product();
                p.Id          = k.Id;
                p.Name        = k.Name;
                p.Price       = k.Price;
                p.Discount    = k.Discount;
                p.CateId      = k.CateId;
                p.Description = k.Description;
                p.Information = k.Information;
                p.Image       = k.Image;
                Listkqre.Add(p);
                i++;
                if (i == amount)
                {
                    return(Listkqre.ToList());
                }
            }
            return(Listkqre.ToList());
        }
Ejemplo n.º 14
0
 public IEnumerable <testAPIDataAccess.returnAllProducts_Result> getAllProduct()
 {
     using (STUDY_SHOPEntities entity = new STUDY_SHOPEntities())
     {
         return(entity.returnAllProducts().ToList());
     }
 }
Ejemplo n.º 15
0
 public void Post([FromBody] Product product)
 {
     using (STUDY_SHOPEntities dbContext = new STUDY_SHOPEntities())
     {
         dbContext.Products.Add(product);
         dbContext.SaveChanges();
     }
 }
Ejemplo n.º 16
0
 public void Post([FromBody] User user)
 {
     using (STUDY_SHOPEntities dbContext = new STUDY_SHOPEntities())
     {
         dbContext.Users.Add(user);
         dbContext.SaveChanges();
     }
 }
Ejemplo n.º 17
0
 public void Post([FromBody] CartItem cartItem)
 {
     using (STUDY_SHOPEntities dbContext = new STUDY_SHOPEntities())
     {
         dbContext.CartItems.Add(cartItem);
         dbContext.SaveChanges();
     }
 }
Ejemplo n.º 18
0
        public int getAmountProductByIdCategory(int idTypeCategory)
        {
            STUDY_SHOPEntities db        = new STUDY_SHOPEntities();
            List <Product>     Listprore = db.Products.Where(x => x.CateId == idTypeCategory).ToList();
            List <Product>     Listkqre  = new List <Product>();
            int temp = 0;

            foreach (Product k in Listprore)
            {
                temp++;
            }
            return(temp);
        }
Ejemplo n.º 19
0
 public IHttpActionResult getProductById(int id)
 {
     using (STUDY_SHOPEntities dbContext = new STUDY_SHOPEntities())
     {
         var entity = dbContext.Products.FirstOrDefault(e => e.Id == id);
         if (entity != null)
         {
             return(Ok(entity));
         }
         else
         {
             return(NotFound());
         }
     }
 }
Ejemplo n.º 20
0
        public IEnumerable <Category> getAllCategory()
        {
            STUDY_SHOPEntities db        = new STUDY_SHOPEntities();
            List <Category>    Listprore = db.Categories.Where(x => x.CateId != 0).ToList();
            List <Category>    Listkqre  = new List <Category>();

            foreach (Category k in Listprore)
            {
                Category c = new Category();
                c.CateId    = k.CateId;
                c.CateImage = k.CateImage;
                c.CateName  = k.CateName;
                Listkqre.Add(c);
            }
            return(Listkqre.ToList());
        }
Ejemplo n.º 21
0
        public IEnumerable <Product> getAllProductByIdCategory(int idType)
        {
            STUDY_SHOPEntities db        = new STUDY_SHOPEntities();
            List <Product>     Listprore = db.Products.Where(x => x.CateId == idType).ToList();
            List <Product>     Listkqre  = new List <Product>();

            foreach (Product k in Listprore)
            {
                Product p = new Product();
                p.Id          = k.Id;
                p.Name        = k.Name;
                p.Price       = k.Price;
                p.Discount    = k.Discount;
                p.CateId      = k.CateId;
                p.Description = k.Description;
                p.Information = k.Information;
                p.Image       = k.Image;
                Listkqre.Add(p);
            }
            return(Listkqre.ToList());
        }
Ejemplo n.º 22
0
 public HttpResponseMessage getUserByEmail(String email)
 {
     try
     {
         using (STUDY_SHOPEntities dbContext = new STUDY_SHOPEntities())
         {
             var entity = dbContext.Users.FirstOrDefault(e => e.Email == email);
             if (entity == null)
             {
                 return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Không thể tim thấy user với email = " + email.ToString()));
             }
             else
             {
                 return(Request.CreateResponse(HttpStatusCode.OK, entity));
             }
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.ToString()));
     }
 }
Ejemplo n.º 23
0
 public int getAmountOfPageCategory(int idCategory)
 {
     using (STUDY_SHOPEntities entity = new STUDY_SHOPEntities())
     {
         int temp = entity.Products.Where(x => x.Category.CateId == idCategory).Count();
         if (temp == 0)
         {
             return(0);
         }
         if (temp < 9)
         {
             return(1);
         }
         else if (temp % 8 == 0)
         {
             return(temp / 8);
         }
         else
         {
             return(temp / 8 + 1);
         }
     }
 }
Ejemplo n.º 24
0
 public HttpResponseMessage DeleteByCartitemID(int idCartitem)
 {
     try
     {
         using (STUDY_SHOPEntities dbContext = new STUDY_SHOPEntities())
         {
             var entity = dbContext.CartItems.FirstOrDefault(e => e.CartId == idCartitem);
             if (entity == null)
             {
                 return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Không thể tim thấy cartitem với id = " + idCartitem.ToString()));
             }
             else
             {
                 dbContext.CartItems.Remove(entity);
                 dbContext.SaveChanges();
                 return(Request.CreateResponse(HttpStatusCode.OK, "Xóa thành công!"));
             }
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.ToString()));
     }
 }
Ejemplo n.º 25
0
 public HttpResponseMessage PutIncreaseCartItem(int idCartItem)
 {
     try
     {
         using (STUDY_SHOPEntities dbContext = new STUDY_SHOPEntities())
         {
             var entity = dbContext.CartItems.FirstOrDefault(e => e.Id == idCartItem);
             if (entity == null)
             {
                 return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Không thể tim thấy cartitem với id = " + idCartItem.ToString()));
             }
             else
             {
                 entity.Quantity = entity.Quantity + 1;
                 dbContext.SaveChanges();
                 return(Request.CreateResponse(HttpStatusCode.OK, entity));
             }
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.ToString()));
     }
 }