コード例 #1
0
 public ActionResult AddCustomer([Bind(Include = "Firstname, Lastname, Mail, PhoneNumber, Budget")] Customer customer)
 {
     if (ModelState.IsValid)
     {
         db.Customers.Add(customer);
         db.SaveChanges();
         return(RedirectToAction("ListCustomers"));
     }
     return(View());
 }
コード例 #2
0
 public ActionResult AddBroker([Bind(Include = "Firstname, Lastname, Mail, PhoneNumber")] Broker broker)
 {
     if (ModelState.IsValid)
     {
         db.Brokers.Add(broker);
         db.SaveChanges();
         return(RedirectToAction("ListBrokers"));
     }
     return(View());
 }
コード例 #3
0
        public ActionResult AddAppointment([Bind(Include = "AppointmentID, DateHour, BrokerID, CustomerID, Subject")] Appointment appointment)
        {
            var queryResult = db.Appointments.SingleOrDefault(a => (a.BrokerID == appointment.BrokerID && a.DateHour == appointment.DateHour) || (a.CustomerID == appointment.CustomerID && a.DateHour == appointment.DateHour));

            if (queryResult != null)
            {
                ModelState.AddModelError("DateHour", "le rendez vous est déjà pris");
            }
            if (ModelState.IsValid)
            {
                db.Appointments.Add(appointment);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.BrokerID   = new SelectList(db.Brokers, "BrokerID", "FullName");
            ViewBag.CustomerID = new SelectList(db.Customers, "CustomerID", "FullName");

            return(View());
        }