예제 #1
0
        public async Task <IHttpActionResult> PutGroup(Guid id, Group group)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != group.Id)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
예제 #2
0
        public async Task <IActionResult> Create([Bind("CustomerId,FirstName,LastName,Phone,Email,AddressId")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                _context.Add(customer);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AddressId"] = new SelectList(_context.GeneralAddress, "AddressId", "City", customer.AddressId);
            return(View(customer));
        }
예제 #3
0
        public async Task <IActionResult> Create([Bind("OrderId,CustomerId,OrderDate,DeliveryAddressId,StoreId,DiscountCode,PaymentId,OrderStatus")] Order order)
        {
            if (ModelState.IsValid)
            {
                _context.Add(order);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CustomerId"]        = new SelectList(_context.Customer, "CustomerId", "Email", order.CustomerId);
            ViewData["DeliveryAddressId"] = new SelectList(_context.DeliveryAddress, "DeliveryAddressId", "Email", order.DeliveryAddressId);
            ViewData["DiscountCode"]      = new SelectList(_context.Discount, "DiscountCode", "DiscountCode", order.DiscountCode);
            ViewData["PaymentId"]         = new SelectList(_context.Payment, "PaymentId", "PaymentId", order.PaymentId);
            ViewData["StoreId"]           = new SelectList(_context.Store, "StoreId", "City", order.StoreId);
            return(View(order));
        }
예제 #4
0
        public async Task <IActionResult> Create([Bind("ProductId,ProductName,BrandId,Description,ProductPrice,ProductImage,Origin,InStock,CategoryId,ProductDiscountPercent")] Product product, IFormFile ProductImage)
        {
            if (ModelState.IsValid)
            {
                if (ProductImage.Length > 0)
                {
                    var ms = new MemoryStream();
                    ProductImage.CopyTo(ms);
                    var bytes = ms.ToArray();
                    product.ProductImage = Convert.ToBase64String(bytes);
                }
                _context.Add(product);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BrandId"]    = new SelectList(_context.Brand, "BrandId", "BrandName", product.BrandId);
            ViewData["CategoryId"] = new SelectList(_context.Category, "CategoryId", "CategoryName", product.CategoryId);

            return(View(product));
        }
예제 #5
0
        public async Task <IActionResult> AddProduct(int id)
        {
            var customer = await _context.Customer.Where(e => e.Email.Equals(User.Identity.Name)).Select(e => e.CustomerId).FirstAsync();

            var ordering = await _context.Order.Where(i => i.CustomerId.Equals(customer) && i.OrderStatus.Equals("Cart")).FirstOrDefaultAsync();

            if (ordering != null)
            {
                var product = await _context.OrderProduct.Where(i => i.ProductId.Equals(id) && i.OrderId.Equals(ordering.OrderId)).FirstOrDefaultAsync();

                if (product != null)
                {
                    product.Quantity++;
                }
                else
                {
                    //object initialization
                    OrderProduct order_product = new OrderProduct();
                    order_product.OrderId   = ordering.OrderId;
                    order_product.ProductId = id;
                    order_product.Quantity  = 1;
                    _context.OrderProduct.Add(order_product);
                }
                await _context.SaveChangesAsync();
            }
            else
            {
                //object initialization simplified
                Order order = new Order
                {
                    OrderStatus = "Cart",
                    CustomerId  = customer
                };
                _context.Order.Add(order);
                _context.SaveChanges();

                var order_id = await _context.Order.Where(i => i.CustomerId.Equals(customer) && i.OrderStatus.Equals("Cart")).Select(e => e.OrderId).FirstAsync();

                OrderProduct order_product = new OrderProduct();
                order_product.OrderId   = order_id;
                order_product.ProductId = id;
                order_product.Quantity  = 1;
                _context.OrderProduct.Add(order_product);
                await _context.SaveChangesAsync();
            }

            return(RedirectToAction("Index", "Products"));
        }