Example #1
0
        public async Task <ActionResult <UserCartDetailDTO> > GetCartDetailById(int id)
        {
            var memberCart = await _context.Members.SingleAsync(m => m.ID == id);

            await _context.Entry(memberCart)
            .Collection(m => m.CartDetails)
            .Query()
            .Where(m => m.MemberID == id)
            .Include(m => m.Variant)
            .ThenInclude(m => m.Product)
            .ThenInclude(m => m.ProductImages)
            .LoadAsync();

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

            return(new UserCartDetailDTO
            {
                MemberID = memberCart.ID,
                CartDetails = memberCart.CartDetails,
                TotalPrice = memberCart.CartDetails.Sum(cd => cd.Quantity * cd.Variant.Product.Price)
            });
        }
        public async Task <IActionResult> UpdateCart(int id, CartDetail cartDetail)
        {
            if (id != cartDetail.MemberID)
            {
                return(BadRequest());
            }

            _context.Entry(cartDetail).State = EntityState.Modified;

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

            _context.Entry(cartDetail)
            .Reference(cd => cd.Variant)
            .Query()
            .Include(cd => cd.Product)
            .Load();

            return(Ok(new { cartDetail = cartDetail, totalPrice = CalculateCart(cartDetail) }));
        }
Example #3
0
        public async Task <ActionResult <Order> > GetOrderDetailById(int id)
        {
            var order = await _context.Orders.SingleAsync(o => o.ID == id);

            await _context.Entry(order)
            .Collection(o => o.OrderDetails)
            .Query()
            .Where(o => o.OrderID == id)
            .Include(m => m.Variant)
            .ThenInclude(m => m.Product)
            .ThenInclude(m => m.ProductImages)
            .LoadAsync();

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

            return(new Order
            {
                ID = order.ID,
                PaymentID = order.PaymentID,
                OrderDetails = order.OrderDetails,
                Country = order.Country,
                State = order.State,
                PostCode = order.PostCode,
                StatusDesc = order.StatusDesc,
                TotalPrice = order.OrderDetails.Sum(cd => cd.Quantity * cd.Variant.Product.Price)
            });
        }
Example #4
0
        public async Task <IActionResult> PutCategory(int id, Category category)
        {
            if (id != category.ID)
            {
                return(BadRequest());
            }

            _context.Entry(category).State = EntityState.Modified;

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

            return(NoContent());
        }
Example #5
0
        public async Task <IActionResult> PutMessage(int id, Message message)
        {
            if (id != message.MemberID)
            {
                return(BadRequest());
            }

            _context.Entry(message).State = EntityState.Modified;

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

            return(NoContent());
        }
Example #6
0
        public async Task <IActionResult> PutOrderProduct(int id, OrderProduct orderProduct)
        {
            /*
             * if (id != orderProduct.OrderId)
             * {
             *  return BadRequest();
             * }
             */

            _context.Entry(orderProduct).State = EntityState.Modified;

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

            return(NoContent());
        }
Example #7
0
 public ActionResult Edit([Bind(Include = "ID,Name,Location,Services")] Shop shop)
 {
     if (ModelState.IsValid)
     {
         db.Entry(shop).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(shop));
 }
 public ActionResult Edit([Bind(Include = "StoreId,NameStore,AddressStore,PhoneStore")] Store store)
 {
     if (ModelState.IsValid)
     {
         db.Entry(store).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(store));
 }
Example #9
0
 public ActionResult Edit([Bind(Include = "ProductTypeId,NameProductType,AboutProductType")] ProductType productType)
 {
     if (ModelState.IsValid)
     {
         db.Entry(productType).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(productType));
 }
Example #10
0
 public ActionResult Edit([Bind(Include = "UserId,UserName,FullName,Password,Salt,Avatar,isAdmin,Allowed,PhoneNumber,Email,Checked")] Account account)
 {
     if (ModelState.IsValid)
     {
         db.Entry(account).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(account));
 }
 public ActionResult Edit([Bind(Include = "SupplierId,NameSupplier,PhoneSupplier,GoodsSupplier")] Supplier supplier)
 {
     if (ModelState.IsValid)
     {
         db.Entry(supplier).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(supplier));
 }
Example #12
0
 public ActionResult Edit([Bind(Include = "BusinessId,BusinessName")] Business business)
 {
     if (ModelState.IsValid)
     {
         db.Entry(business).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(business));
 }
Example #13
0
 public ActionResult Edit([Bind(Include = "ProductId,NameProduct,ProductTypeId,SizeProduct,PriceProduct,PicProduct,SupplierId")] Product product)
 {
     if (ModelState.IsValid)
     {
         db.Entry(product).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.SupplierId    = new SelectList(db.suppliers, "SupplierId", "NameSupplier", product.SupplierId);
     ViewBag.ProductTypeId = new SelectList(db.typesshoes, "ProductTypeId", "NameProductType", product.ProductTypeId);
     return(View(product));
 }
Example #14
0
        public async Task <ActionResult <Order> > GetAdminOrderDetails(int id)
        {
            var order = await _context.Orders.SingleAsync(o => o.ID == id);

            await _context.Entry(order)
            .Reference(o => o.Member)
            .LoadAsync();

            await _context.Entry(order)
            .Collection(o => o.OrderDetails)
            .Query()
            .Include(o => o.Variant)
            .ThenInclude(o => o.Product)
            .ThenInclude(o => o.ProductImages)
            .LoadAsync();

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

            return(order);
        }
Example #15
0
 public ActionResult Edit([Bind(Include = "AccountId,NameAccount,EmailAccount,PasswordAccount,isAdminAccount")] Account account)
 {
     if (Session["Admin"] == null)
     {
         return(RedirectToAction("Index", "Home"));
     }
     if (ModelState.IsValid)
     {
         db.Entry(account).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(account));
 }
Example #16
0
 public ActionResult Edit([Bind(Include = "PermissionId,PermissionName,Description,BusinessId")] Permission permission)
 {
     if (ModelState.IsValid)
     {
         db.Entry(permission).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index", new
         {
             id = Session["namePermission"],
         }));
     }
     ViewBag.BusinessId = new SelectList(db.Businesses, "BusinessId", "BusinessName", permission.BusinessId);
     return(View(permission));
 }
Example #17
0
        public async Task <ActionResult <Product> > GetProductDetails(int id)
        {
            var product = await _context.Products.SingleAsync(p => p.ID == id);

            await _context.Entry(product)
            .Collection(p => p.Variants)
            .LoadAsync();

            await _context.Entry(product)
            .Collection(p => p.ProductImages)
            .LoadAsync();

            await _context.Entry(product)
            .Collection(p => p.MemberWishlists)
            .Query()
            .Include(p => p.Member)
            .LoadAsync();

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

            return(new Product
            {
                ID = product.ID,
                CreatedAt = product.CreatedAt,
                Description = product.Description,
                MemberWishlists = product.MemberWishlists,
                Messages = product.Messages,
                Price = product.Price,
                ProductImages = product.ProductImages,
                ProductName = product.ProductName,
                Variants = product.Variants
            });
        }
Example #18
0
        public async Task <IActionResult> PutUser(int id, User user)
        {
            user.Id = id;

            _context.Entry(user).State = EntityState.Modified;

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

            return(NoContent());
        }
Example #19
0
        public async Task <IActionResult> PutProduct(int id, Product product)
        {
            product.Id = id;

            _context.Entry(product).State = EntityState.Modified;

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

            return(NoContent());
        }
Example #20
0
 public virtual void Update(T entity)
 {
     dbSet.Attach(entity);
     dataContext.Entry(entity).State = EntityState.Modified;
 }
 public void UpdateProduct(Product product)
 {
     _context.Entry(product).State = EntityState.Modified;
 }