Пример #1
0
        public ActionResult RequestAppointment(General_Enquiry model, FormCollection fc)
        {
            // Check if there is already appointment for this client id
            General_Enquiry ge = db.General_Enquiry.DefaultIfEmpty(null).SingleOrDefault(x => x.Client_Id == model.Client_Id);

            if (ge != null)
                return RedirectToAction("LogOn", "Account");

            ViewBag.Branch = db.Branches.ToList();

            model.Appointment.AppDateTime = Utilities.formatDate(fc["Appointment.AppDateTime"], "dd/MM/yyyy");
            ModelState.Remove("Appointment.AppDateTime");

            try
            {
                if (ModelState.IsValid)
                {
                    model.Appointment.Branch_Id = model.Branch_Id;
                    model.Appointment.Confirmation = AppointmentController.APP_REQUEST_APPROVAL;
                    db.General_Enquiry.AddObject(model);
                    db.SaveChanges();
                    LogHelper.writeToSystemLog(new string[] { CookieHelper.Username }, (CookieHelper.Username + "Requested appointment "), LogHelper.LOG_OTHER, LogHelper.SECTION_CLIENT);

                    string messageBody = "<div>Your appointment is scheduled on: " + model.Appointment.AppDateTime.ToShortDateString() + " on " + model.Appointment.AppDateTime.ToShortTimeString() + "</div>";

                    messageBody += "<div><br/> <strong>This is your client ID for future reference: " + model.Client_Id + "</strong></div>";

                    EmailHelper.sendEmail(new MailAddress(model.Client.Email), "We have received your appointment request", messageBody);
                    return RedirectToAction("AppointmentSuccess", "Client", new { id = model.Appointment.Appointment_Id });
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine("{0} First exception caught.", e);
                Debug.WriteLine(e.InnerException);
                ModelState.AddModelError("", e);
            }

            Client c = db.Clients.Single(x => x.Client_Id == model.Client_Id);
            ViewBag.ClientName = c.GivenName + " " + c.LastName;

            return View(model);
        }
Пример #2
0
        public ActionResult RequestAppointment(int id)
        {
            // Check if there is already appointment for this client id
            General_Enquiry ge = db.General_Enquiry.DefaultIfEmpty(null).SingleOrDefault(x => x.Client_Id == id);

            if (ge != null)
                return RedirectToAction("LogOn", "Account");

            General_Enquiry model = new General_Enquiry();
            model.Client_Id = id;

            IEnumerable<Branch> branch = db.Branches.ToList();
            ViewBag.Branch = branch;

            Client c = db.Clients.Single(x => x.Client_Id == id);
            model.Branch_Id = c.Branch_Id;
            ViewBag.ClientName = c.GivenName + " " + c.LastName;

            return View(model);
        }