public RedirectToRouteResult Register(Customer customer)
        {
            if (ModelState.IsValid)
            {
                db.Customers.Add(customer);
                db.SaveChanges();
                return(RedirectToAction("Index", "Home"));
            }

            return(RedirectToAction("Index", "Register"));
        }
Beispiel #2
0
        private void ProcessOrder(ShoppingCartModel cart)
        {
            Customer customer;

            if (Session["UserId"] != null)
            {
                int id = Convert.ToInt32(Session["UserId"]);
                customer = db.Customers.Find(id);
                if (customer != null)
                {
                    customer.BillingAddress    = cart.BillingInfo.Address;
                    customer.BillingPostalCode = cart.BillingInfo.PostalCode;
                    db.Customers.AddOrUpdate(customer);
                    db.SaveChanges();

                    Order order = new Order
                    {
                        CustomerId         = customer.CustomerId,
                        OrderDate          = DateTime.Now,
                        IsDelivery         = cart.ShippingInfo.IsDelivery,
                        ShippingAddress    = cart.ShippingInfo.Address,
                        ShippingPostalCode = cart.ShippingInfo.PostalCode
                    };
                    db.Orders.Add(order);
                    db.SaveChanges();

                    foreach (var item in cart.Items)
                    {
                        OrderLine orderLine = new OrderLine
                        {
                            OrderId   = order.OrderId,
                            ProductId = item.Product.ProductId,
                            Quantity  = item.Quantity
                        };
                        db.OrderLines.Add(orderLine);
                    }
                }
                db.SaveChanges();
            }
        }
        public async Task <ActionResult> Create(Community community, HttpPostedFileBase image)
        {
            var bucketName = WebConfigurationManager.AppSettings["COMP306-DBTEST:BucketName"];

            _imageUploader = new ImageUploader(bucketName);
            if (ModelState.IsValid)
            {
                db.Communities.Add(community);
                db.SaveChanges();
                if (image != null)
                {
                    var imageUrl = await _imageUploader.UploadImage(image, community.Id);

                    community.ImageUrl = imageUrl;
                    db.Communities.AddOrUpdate(community);
                    db.SaveChanges();
                }

                return(RedirectToAction("Index"));
            }

            return(View(community));
        }