Example #1
0
        public ActionResult Create([Bind(Include = "ClientID,FirstName,LastName,Address,City,State,Zip,Email,Phone")] Client client)
        {
            if (ModelState.IsValid)
            {
                db.Clients.Add(client);
                db.SaveChanges();

                db.Database.ExecuteSqlCommand(
                    "UPDATE Instruments " +
                    "SET ClientID = " + client.ClientID +
                    "WHERE InstrumentID = " +
                    "(SELECT max(InstrumentID) " +
                    " FROM Instruments);");

                db.SaveChanges();

                int rID = db.Database.SqlQuery <int>(
                    "SELECT max(InstrumentID) " +
                    "FROM Instruments").FirstOrDefault();

                //return RedirectToAction("Index");
                return(RedirectToAction("Summary", new { cID = client.ClientID, rID }));
            }

            return(View(client));
        }
 public ActionResult Edit([Bind(Include = "ClientID,FirstName,LastName,Address,City,State,Zip,Email,Phone")] Client client)
 {
     if (ModelState.IsValid)
     {
         db.Entry(client).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(client));
 }
        public ActionResult Create([Bind(Include = "ClientID,FirstName,LastName,Address,City,State,Zipcode,EmailAddress,PhoneNumber")] Client client)
        {
            if (ModelState.IsValid)
            {
                db.Clients.Add(client);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(client));
        }
        public ActionResult Create([Bind(Include = "InstrumentID,Name,Type,ImageString,Price,ClientID")] Instrument instrument)
        {
            if (ModelState.IsValid)
            {
                db.Instruments.Add(instrument);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(instrument));
        }
        public ActionResult Create([Bind(Include = "MovieID,Title,Description")] Movie movie)
        {
            if (ModelState.IsValid)
            {
                db.Movies.Add(movie);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(movie);
        }
        public ActionResult Create([Bind(Include = "CustomerID,FirstName,LastName,Email")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                db.Customers.Add(customer);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(customer));
        }
Example #7
0
        public ActionResult Rent(ClientInstrument clientInstrument)
        {
            // Check if the model is valid
            if (ModelState.IsValid)
            {
                // It's valid
                // Add the client first
                var client = new Client()
                {
                    FirstName    = clientInstrument.Client.FirstName,
                    LastName     = clientInstrument.Client.LastName,
                    Address      = clientInstrument.Client.Address,
                    City         = clientInstrument.Client.City,
                    State        = clientInstrument.Client.State,
                    Zipcode      = clientInstrument.Client.Zipcode,
                    EmailAddress = clientInstrument.Client.EmailAddress,
                    PhoneNumber  = clientInstrument.Client.PhoneNumber
                };

                db.Clients.Add(client);
                db.SaveChanges();

                // Grab the last added clientID
                var clientID = db.Clients.OrderByDescending(x => x.ClientID).FirstOrDefault().ClientID;

                // Now add the instrument
                var instrument = new Instrument()
                {
                    Name     = clientInstrument.Instrument.Name,
                    Price    = clientInstrument.Instrument.Price,
                    New      = clientInstrument.Instrument.New,
                    Location = clientInstrument.Instrument.Location,
                    ClientID = clientID
                };

                db.Instruments.Add(instrument);
                db.SaveChanges();

                // Add the clientInstrument to the tempdata
                clientInstrument.Instrument = instrument;
                clientInstrument.Client     = client;

                TempData["clientInstrument"] = clientInstrument;

                return(RedirectToAction("Summary"));
            }
            else
            {
                // The model isn't valid so send everything back
                return(View("~/Views/ClientInstrument/Create.cshtml", clientInstrument));
            }
        }
        public ActionResult Create([Bind(Include = "RentalID,RentalDate,ReturnDate,CustomerID,MovieID")] Rental rental)
        {
            if (ModelState.IsValid)
            {
                db.Rentals.Add(rental);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CustomerID = new SelectList(db.Customers, "CustomerID", "FirstName", rental.CustomerID);
            ViewBag.MovieID    = new SelectList(db.Movies, "MovieID", "Title", rental.MovieID);
            return(View(rental));
        }
Example #9
0
        public static void Add(Owner owner)
        {
            var context = new RentalsContext();

            context.Owners.Add(owner);
            context.SaveChanges();
        }
Example #10
0
        public static void Add(PropertyType type)
        {
            var context = new RentalsContext();

            context.PropertyTypes.Add(type);
            context.SaveChanges();
        }
Example #11
0
        public static void Add(RentalProperty rental)
        {
            var context = new RentalsContext();

            context.RentalProperties.Add(rental);
            context.SaveChanges();
        }
Example #12
0
        public static void Update(Owner owner)
        {
            var context = new RentalsContext();
            var o       = context.Owners.Find(owner.Id);

            o.Name  = owner.Name;
            o.Phone = owner.Phone;
            context.SaveChanges();
        }
Example #13
0
        public ActionResult Create(ClientInstrument clientInstrument)
        {
            // Check if the model is valid
            if (ModelState.IsValid)
            {
                // It's valid
                // Add the client first
                var client = new Client()
                {
                    FirstName    = clientInstrument.Client.FirstName,
                    LastName     = clientInstrument.Client.LastName,
                    Address      = clientInstrument.Client.Address,
                    City         = clientInstrument.Client.City,
                    State        = clientInstrument.Client.State,
                    Zipcode      = clientInstrument.Client.Zipcode,
                    EmailAddress = clientInstrument.Client.EmailAddress,
                    PhoneNumber  = clientInstrument.Client.PhoneNumber
                };

                db.Clients.Add(client);
                db.SaveChanges();

                // Now add the instrument
                var instrument = new Instrument()
                {
                    Name     = clientInstrument.Instrument.Name,
                    Price    = clientInstrument.Instrument.Price,
                    New      = clientInstrument.Instrument.New,
                    Location = clientInstrument.Instrument.Location,
                    ClientID = (int)client.ClientID
                };

                db.Instruments.Add(instrument);
                db.SaveChanges();
                return(View("Summary", clientInstrument));
            }
            else
            {
                // The model isn't valid so send everything back
                return(View(clientInstrument));
            }
        }
        public ActionResult Create(int id, [Bind(Include = "ClientID,FirstName,LastName,Address,City,State,Zip,Email,Phone")] Client client)
        {
            if (ModelState.IsValid)
            {
                db.Clients.Add(client); //adds client to database
                db.SaveChanges();       // saves database

                //lookup instument in the database by ID
                Instrument instrument = db.Instruments.Find(id);
                // just in case things get crazy
                if (instrument == null)
                {
                    return(HttpNotFound());
                }
                instrument.ClientID = client.ClientID;
                //db.Entry(instrument).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Summary", new { ClientID = client.ClientID, InstrumentID = instrument.InstrumentID }));
            }

            return(View(client));
        }
Example #15
0
        public ActionResult NewTrumpet()
        {
            //get new pictures
            //set up instrument in database
            var entity = new Instrument {
                Description = "Trumpet", PicURL = "~/Content/Images/trumpet2.jpg", Price = 55, Type = "New"
            };

            db.Instruments.Add(entity);
            db.SaveChanges();

            //go to client method
            return(RedirectToAction("Create", "Clients"));
        }