Пример #1
0
        private void Fixupemployee(employee previousValue)
        {
            if (IsDeserializing)
            {
                return;
            }

            if (previousValue != null && previousValue.appointments.Contains(this))
            {
                previousValue.appointments.Remove(this);
            }

            if (employee != null)
            {
                if (!employee.appointments.Contains(this))
                {
                    employee.appointments.Add(this);
                }

                employeeid = employee.employeeid;
            }
            if (ChangeTracker.ChangeTrackingEnabled)
            {
                if (ChangeTracker.OriginalValues.ContainsKey("employee")
                    && (ChangeTracker.OriginalValues["employee"] == employee))
                {
                    ChangeTracker.OriginalValues.Remove("employee");
                }
                else
                {
                    ChangeTracker.RecordOriginalValue("employee", previousValue);
                }
                if (employee != null && !employee.ChangeTracker.ChangeTrackingEnabled)
                {
                    employee.StartTracking();
                }
            }
        }
        public ActionResult Register(RegisterModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    Entities db = new Entities();
                    IEnumerable<faculty> faculty = db.faculties;
                    List<String> data = new List<string>();
                    foreach (faculty fac in faculty)
                    {
                        data.Add(fac.fname);
                    }
                    model.facultyList = data;

                    // Attempt to register the user
                    MembershipCreateStatus createStatus;
                    Membership.CreateUser(model.UserName, model.Password, model.Email, null, null, true, null, out createStatus);
                    employee employee_model = new employee() { employeeid = model.UserName, fname = model.fname, lname = model.lname, phonenum = model.phonenum, email = model.Email, faculty = model.faculty, role = model.position };
                    student student = db.students.SingleOrDefault(stud => stud.studentid ==  employee_model.employeeid);

                    if (student == null)
                    {
                        db.employees.AddObject(employee_model);
                        db.SaveChanges();

                        if (createStatus == MembershipCreateStatus.Success)
                        {
                            //Roles.
                            Roles.AddUserToRole(model.UserName, model.position);
                            FormsAuthentication.SetAuthCookie(model.UserName, false /* createPersistentCookie */);
                            return RedirectToAction("Index", "Home");
                        }
                        else
                        {
                            ModelState.AddModelError("", ErrorCodeToString(createStatus));
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("UserName", "Employee ID is already in ues.");
                    }
                }
            }
            catch (Exception ex)
            {
                return View(model);
            }
            // If we got this far, something failed, redisplay form
            return View(model);
        }
        /// <summary>
        /// sends an email to the creater of the appointment confirming that the the series appointments have been created. 
        /// </summary>
        /// <param name="employee"></param>
        /// <param name="appointment"></param>
        private void ConfirmationEmailSeries(employee employee, appointment appointment)
        {
            MailMessage mail = new MailMessage();
            SmtpClient SmtpServer = new SmtpClient(MAIL_SMTP);

            IEnumerable<appointment> appointments = db.appointments.Where(a => a.repeating == appointment.repeating).OrderBy(a => a.starttime);

            DateTime start = appointments.First().starttime;
            DateTime end = appointments.OrderByDescending(a => a.starttime).First().starttime;

            mail.From = new MailAddress(MAIL_ADDRESS);
            mail.To.Add(employee.email);
            mail.Subject = "Appointment Confirmation for " + employee.fname + " " + employee.lname;
            mail.Body = "You have successfully created an series of " + appointment.appointmenttype.Trim() + " appointments starting on " + start + " to " + end
                + " and the appointment will take place at " + appointment.cname + ".";
            mail.Body += "\n\nThis is an automated message please to do not respond to this email.";

            SmtpServer.Port = 587;
            SmtpServer.Credentials = new System.Net.NetworkCredential(MAIL_ADDRESS, MAIL_PASS);
            SmtpServer.EnableSsl = true;

            SmtpServer.Send(mail);
        }
        /// <summary>
        /// sends an email to the attendees informing that they have been invited to an series of appointments 
        /// </summary>
        /// <param name="emp"></param>
        /// <param name="appointment"></param>
        private void EmailAttendeesSeries(employee emp, appointment appointment)
        {
            MailMessage mail = new MailMessage();
            SmtpClient SmtpServer = new SmtpClient(MAIL_SMTP);

            IEnumerable<appointment> appointments = db.appointments.Where(a => a.repeating == appointment.repeating).OrderBy(a => a.starttime);

            DateTime start = appointments.First().starttime;
            DateTime end = appointments.OrderByDescending(a => a.starttime).First().starttime;

            employee chair = db.employees.Single(e => e.employeeid == appointment.employeeid);
            IEnumerable<Attendee> Attendees = db.Attendees.Where(attend => attend.appointmentid == appointment.appointmentid);
            String EmailTo = chair.email;

            foreach (Attendee Attendee in Attendees)
            {
                student student = db.students.SingleOrDefault(stud => stud.studentid == Attendee.attendee1);

                if (student != null)
                {
                    EmailTo += ", " + student.email;
                }
                else
                {
                    employee employee = db.employees.Single(e => e.employeeid == Attendee.attendee1);

                    EmailTo += ", " + employee.email;
                }
            }

            mail.From = new MailAddress(MAIL_ADDRESS);
            mail.To.Add(EmailTo);
            mail.Subject = "Appointment Invitation From " + emp.fname + " " + emp.lname;
            mail.Body = "You have been requested to attend an " + appointment.appointmenttype.Trim() + " appointment regarding " + appointment.subject + " starting on " + start + " to " + end
                + " and the appointments will take place at " + appointment.cname + ". The chair for the appointment will be " + chair.fname + " " + chair.lname + ", please contact him/her regarding any further details at "
                + chair.email + " or " + chair.phonenum + ".";
            if (appointment.description != null)
            {
                mail.Body += "\n\nDescription Included: \n" + appointment.description;
            }

            mail.Body += "\n\nThis is an automated message please to do not respond to this email.";

            SmtpServer.Port = 587;
            SmtpServer.Credentials = new System.Net.NetworkCredential(MAIL_ADDRESS, MAIL_PASS);
            SmtpServer.EnableSsl = true;

            SmtpServer.Send(mail);
        }
        /// <summary>
        /// Sends an email to the creator of the appointment confirming that the appointment has been created
        /// </summary>
        /// <param name="employee"></param>
        /// <param name="appointment"></param>
        private void ConfirmationEmail(employee employee, appointment appointment)
        {
            MailMessage mail = new MailMessage();
            SmtpClient SmtpServer = new SmtpClient(MAIL_SMTP);

            mail.From = new MailAddress(MAIL_ADDRESS);
            mail.To.Add(employee.email);
            mail.Subject = "Appointment Confirmation for " + employee.fname + " " + employee.lname;
            mail.Body = "You have successfully created an " + appointment.appointmenttype.Trim() + " appointment at " + appointment.starttime.ToString() + " to " + appointment.endtime.ToString()
                + " and the appointment will take place at " + appointment.cname + ".";
            mail.Body += "\n\nThis is an automated message please to do not respond to this email.";

            SmtpServer.Port = 587;
            SmtpServer.Credentials = new System.Net.NetworkCredential(MAIL_ADDRESS, MAIL_PASS);
            SmtpServer.EnableSsl = true;

            SmtpServer.Send(mail);
        }