Ejemplo n.º 1
0
        public ActionResult CreateAndAddProducts([ModelBinder(typeof(OrderBinderCreate))]  OrderCreateViewModel ocvm, string[] DeliveryID)
        {
            if (ModelState.IsValid)
            {
                //aanmaken van quotation / customerdeliveryaddress en customer
                Order order = new Order();
                CustomerDeliveryAddress cda = new CustomerDeliveryAddress();
                Customer cus = new Customer();

                //ophalen van customerDeliveryAddressID vanuit de array
                // eventueel nog test inbouwen voor lengte van array (check dat ze niet meer als 1 veld selecteren)
                int DeliveryId = 1;
                if (DeliveryID.Length == 1)
                {
                    DeliveryId = Int32.Parse(DeliveryID.First());
                }
                else
                {
                    return RedirectToAction("Create");
                }

                // ophalen delivery info en van daaruit customer info
                cda = db.CustomerDeliveryAddresses.Find(DeliveryId);
                cus = db.Customers.Find(cda.CustomerId);

                // invullen van de klant info in de quotation
                DefaultOrderInfo(order);
                order.FirstName = cus.FirstName;
                order.LastName = cus.LastName;
                order.Box = cus.Address.Box;
                order.CellPhone = cus.CellPhone;
                order.CustomerId = cus.CustomerId;
                order.Email = cus.Email;
                order.PostalCodeNumber = cus.Address.PostalCodeNumber;
                order.StreetName = cus.Address.StreetName;
                order.StreetNumber = cus.Address.StreetNumber;
                order.Town = cus.Address.Town;
                order.Annotation = ocvm.order.Annotation;
                order.customerDeliveryAddress = db.CustomerDeliveryAddresses.Find(DeliveryId);

                //toevoegen en saven
                db.Orders.Add(order);
                db.SaveChanges();

                int id = order.OrderId;
                TempData["id"] = id;
                return RedirectToAction("AddProducts");

            }
            return View(ocvm);
        }
Ejemplo n.º 2
0
        public ActionResult Edit([ModelBinder(typeof(CustomerBinderEdit))] CustomerEditViewModel customer)
        {
            if (ModelState.IsValid)
            {
                Customer cus = new Customer();
                cus = db.Customers.Find(customer.customer.CustomerId);

                cus.FirstName = customer.customer.FirstName;
                cus.LastName = customer.customer.LastName;
                cus.CompanyName = customer.customer.CompanyName;
                cus.Phone = customer.customer.Phone;
                cus.CellPhone = customer.customer.CellPhone;
                cus.Email = customer.customer.CellPhone;
                cus.VATNumber = customer.customer.VATNumber;
                cus.AccountNumber = customer.customer.AccountNumber;
                cus.Annotation = customer.customer.Annotation;
                cus.Type = customer.customer.Type;
                cus.TAXLiability = customer.customer.TAXLiability;
                cus.ContactName = customer.customer.ContactName;
                cus.ContactEmail = customer.customer.ContactEmail;
                cus.ContactCellPhone = customer.customer.ContactCellPhone;
                cus.Address.StreetName = customer.customer.Address.StreetName;
                cus.Address.StreetNumber = customer.customer.Address.StreetNumber;
                cus.Address.Box = customer.customer.Address.Box;
                cus.Address.PostalCodeNumber = customer.customer.Address.PostalCodeNumber;
                cus.Address.Town = customer.customer.Address.Town;

                // testing
                //cus = customer.customer;
                //UpdateModel(cus, "Customer");
                //db.Entry(cus).State = EntityState.Modified;
                //db.Entry(cus.Address).State = EntityState.Modified;

                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(customer);
        }
Ejemplo n.º 3
0
        public ActionResult AddDeliveryAddress([ModelBinder(typeof(CustomerBinderAddNewDeliveryAddress))] CustomerAddDeliveryAddressViewModel cadavm, string[] AddressId, string returnUrl)
        {
            Customer cus = new Customer();
            Address add = new Address();
            CustomerDeliveryAddress cda = new CustomerDeliveryAddress();
            cus = db.Customers.Find(cadavm.deliveryAddress.CustomerId);

            if (AddressId != null)
            {
                if (AddressId.Length > 1)
                {
                    return RedirectToAction("AddDeliveryAddress");
                }

                if (AddressId.Length == 1)
                {
                    add = db.Addresses.Find(Int32.Parse(AddressId.First()));
                    cda.Box = add.Box;
                    cda.CustomerId = cadavm.customer.CustomerId;
                    cda.DeliveryAddressInfo = cadavm.deliveryAddress.DeliveryAddressInfo;
                    cda.PostalCodeNumber = add.PostalCodeNumber;
                    cda.StreetName = add.StreetName;
                    cda.StreetNumber = add.StreetNumber;
                    cda.Town = add.Town;
                    cus.CustomerDeliveryAddress.Add(cda);
                    db.SaveChanges();
                    return Redirect(returnUrl);
                }
            }

            cda = cadavm.deliveryAddress;
            cus.CustomerDeliveryAddress.Add(cda);
            db.SaveChanges();
            return Redirect(returnUrl);
        }
Ejemplo n.º 4
0
        public ActionResult Create([ModelBinder(typeof(CustomerBinderCreate))] CustomerCreateViewModel ccvm)
        {
            if (ModelState.IsValid)
            {
                // aanmaken lege opbjecten
                Customer cus = new Customer();
                CustomerDeliveryAddress cda = new CustomerDeliveryAddress();

                //opslaan van klant
                cus = ccvm.customer;
                db.Customers.Add(cus);
                db.SaveChanges();

                // vullen van delivery Address met default info
                cda.Box = cus.Address.Box;
                cda.PostalCodeNumber = cus.Address.PostalCodeNumber;
                cda.StreetName = cus.Address.StreetName;
                cda.StreetNumber = cus.Address.StreetNumber;
                cda.Town = cus.Address.Town;
                cda.CustomerId = cus.CustomerId;
                cda.DeliveryAddressInfo = "Standaard adres";
                db.CustomerDeliveryAddresses.Add(cda);
                db.SaveChanges();

                //redirect to index
                return RedirectToAction("Index");
            }
            return View(ccvm);
        }
Ejemplo n.º 5
0
        public ActionResult Create([ModelBinder(typeof(QuotationBinderCreate))]  QuotationCreateViewModel qcvm, string[] DeliveryID)
        {
            if (ModelState.IsValid)
            {
                //aanmaken van quotation / customerdeliveryaddress en customer
                Quotation quotation = new Quotation();
                CustomerDeliveryAddress cda = new CustomerDeliveryAddress();
                Customer cus = new Customer();

                //ophalen van customerDeliveryAddressID vanuit de array
                // eventueel nog test inbouwen voor lengte van array (check dat ze niet meer als 1 veld selecteren)
                int DeliveryId = 1;
                if (DeliveryID.Length == 1)
                {
                    DeliveryId = Int32.Parse(DeliveryID.First());
                }
                else
                {
                   return RedirectToAction("Create");
                }

                // ophalen delivery info en van daaruit customer info
                cda = db.CustomerDeliveryAddresses.Find(DeliveryId);
                cus = db.Customers.Find(cda.CustomerId);

                // invullen van de klant info in de quotation
                DefaultQuotationInfo(quotation);
                quotation.FirstName = cus.FirstName;
                quotation.LastName = cus.LastName;
                quotation.Box = cus.Address.Box;
                quotation.CellPhone = cus.CellPhone;
                quotation.CustomerId = cus.CustomerId;
                quotation.Email = cus.Email;
                quotation.PostalCodeNumber = cus.Address.PostalCodeNumber;
                quotation.StreetName = cus.Address.StreetName;
                quotation.StreetNumber = cus.Address.StreetNumber;
                quotation.Town = cus.Address.Town;
                quotation.Annotation = qcvm.quotation.Annotation;
                quotation.customerDeliveryAddress = db.CustomerDeliveryAddresses.Find(DeliveryId);

                //toevoegen en saven
                db.Quotations.Add(quotation);
                db.SaveChanges();

                return RedirectToAction("Index");
            }
            return View(qcvm);
        }