Ejemplo n.º 1
0
        public ActionResult Edit([Bind(Include = "ID, StartDate, EndDate, RepairStatus, Customer, Technician, HoursWorkedOn, Description, RepairOrder, CustomerId")] VMRepairOrderEdit vmRepairOrder)
        {
            if (ModelState.IsValid)
            {
                RepairOrder repairOrder = vmRepairOrder.RepairOrder;
                db.Entry(repairOrder).State = EntityState.Modified;
                db.SaveChanges();

                //Find the repairOrder in the database based on the ID.
                repairOrder = db.RepairOrders.Find(vmRepairOrder.RepairOrder.ID);


                //If CustomerId has a value. (Which means the list was changed?)
                //Find Customer in Customers and set it to be repairOrder's Customer?
                if (vmRepairOrder.CustomerId != null)
                {
                    //Load Customer first before altering. Otherwise Customer remains null.
                    db.Entry(repairOrder).Reference(c => c.Customer).Load();

                    //Find said Customer in the database and set it as the customer?
                    repairOrder.Customer = db.Customers.Find(vmRepairOrder.CustomerId);
                }
                if (vmRepairOrder.TechnicianId != null)
                {
                    db.Entry(repairOrder).Reference(c => c.Technician).Load();

                    repairOrder.Technician = db.Technicians.Find(vmRepairOrder.TechnicianId);
                }

                db.Entry(repairOrder).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(vmRepairOrder));
        }
Ejemplo n.º 2
0
        // GET: RepairOrders/Create
        public ActionResult Create()
        {
            VMRepairOrderEdit repairOrderVM = new VMRepairOrderEdit
            {
                Customers   = db.Customers.ToList(),
                Technicians = db.Technicians.ToList()
            };

            return(View(repairOrderVM));
        }
Ejemplo n.º 3
0
        // GET: RepairOrders/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            VMRepairOrderEdit vmRepairOrder = new VMRepairOrderEdit
            {
                RepairOrder = db.RepairOrders.Find(id),
                Technicians = db.Technicians.ToList(),
                Customers   = db.Customers.ToList(),
            };

            //Try to set it to the ID in RepairOrder.
            //So the dropdown list will display the name of the currently selected property.
            try {
                vmRepairOrder.CustomerId = vmRepairOrder.RepairOrder.Customer.ID;
            }
            catch {
                vmRepairOrder.CustomerId = 1;
            }
            try {
                vmRepairOrder.TechnicianId = vmRepairOrder.RepairOrder.Technician.ID;
            }
            catch {
                vmRepairOrder.TechnicianId = 1;
            }

            //RepairOrder repairOrder = db.RepairOrders.Find(id);
            if (vmRepairOrder == null)
            {
                return(HttpNotFound());
            }
            return(View(vmRepairOrder));
        }
Ejemplo n.º 4
0
        public ActionResult Create([Bind(Include = "ID,StartDate,EndDate,RepairStatus,Customer,Technician,HoursWorkedOn,Description")] RepairOrder repairOrder, VMRepairOrderEdit repairOrderVM)
        {
            if (ModelState.IsValid)
            {
                repairOrder.Customer   = db.Customers.Find(repairOrderVM.CustomerId);
                repairOrder.Technician = db.Technicians.Find(repairOrderVM.TechnicianId);
                db.RepairOrders.Add(repairOrder);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(repairOrderVM));
        }