Example #1
0
        public ActionResult Create(ProgramType programtype)
        {
            if (ModelState.IsValid)
            {
                db.ProgramTypes.Add(programtype);
                try
                {
                    db.SaveChanges();
                }
                catch (Exception e)
                {
                    Session["FlashMessage"] = "Failed to create type." + e.Message;
                    List <SelectListItem> items = new List <SelectListItem>();
                    items.Add(new SelectListItem {
                        Text = "Application End Time", Value = "deadline", Selected = true
                    });
                    items.Add(new SelectListItem {
                        Text = "Program Date", Value = "program"
                    });

                    ViewBag.display_date = items;
                    return(View(programtype));
                }
                return(RedirectToAction("Index"));
            }

            return(View(programtype));
        }
Example #2
0
        public ActionResult Send(int id = 0)
        {
            Notification notification = db.Notifications.Find(id);

            db.Entry(notification).CurrentValues.SetValues(SendNotification(notification));
            db.SaveChanges();
            return(RedirectToAction("Index", new { notification_id = id }));
        }
        public ActionResult Create(StudentAdvisingRemark studentadvisingremark, string opener_id = null)
        {
            if (ModelState.IsValid)
            {
                db.StudentAdvisingRemarks.Add(studentadvisingremark);
                try
                {
                    studentadvisingremark.created     = DateTime.Now;
                    studentadvisingremark.created_by  = User.Identity.Name;
                    studentadvisingremark.modified    = DateTime.Now;
                    studentadvisingremark.modified_by = User.Identity.Name;
                    db.SaveChanges();
                    if (!String.IsNullOrEmpty(studentadvisingremark.filename) && !String.IsNullOrEmpty(studentadvisingremark.filepath))
                    {
                        var sourcePath     = Server.MapPath("~/App_Data/" + studentadvisingremark.filepath);
                        var sourceFilepath = Path.Combine(sourcePath, studentadvisingremark.filename);
                        var destPath       = Server.MapPath("~/App_Data/" + "Attachments/AdvisingRemark/" + studentadvisingremark.id);
                        var destFilepath   = Path.Combine(destPath, studentadvisingremark.filename);
                        try
                        {
                            Directory.CreateDirectory(destPath);
                        }
                        catch (Exception e)
                        {
                            Session["FlashMessage"] = "Failed to create directory." + e.Message;
                        }
                        try
                        {
                            System.IO.File.Move(sourceFilepath, destFilepath);
                            studentadvisingremark.filepath = "Attachments/AdvisingRemark/" + studentadvisingremark.id;
                            db.SaveChanges();
                        }
                        catch (Exception e)
                        {
                            Session["FlashMessage"] = "Failed to move file." + e.Message;
                        }
                    }

                    //clear temp files uploaded but not used
                    if (Directory.Exists(Server.MapPath("~/App_Data/Temp/AdvisingRemark/" + User.Identity.Name)))
                    {
                        var files = Directory.GetFiles(Server.MapPath("~/App_Data/Temp/AdvisingRemark/" + User.Identity.Name));
                        foreach (var file in files)
                        {
                            System.IO.File.Delete(file);
                        }
                    }
                }
                catch (Exception e)
                {
                    return(HttpNotFound("Failed to add remark.<br/><br/>" + e.Message));
                }
            }
            return(RedirectToAction("AdvisingRemark", "StudentProfile", new { student_id = studentadvisingremark.student_id, opener_id = opener_id }));
        }
        public ActionResult Create(AppointmentConcern appointmentconcern)
        {
            if (ModelState.IsValid)
            {
                db.AppointmentConcerns.Add(appointmentconcern);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(appointmentconcern));
        }
        public ActionResult Create(AppointmentVenue appointmentvenue)
        {
            if (ModelState.IsValid)
            {
                db.AppointmentVenues.Add(appointmentvenue);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(appointmentvenue));
        }
Example #6
0
        public ActionResult Create(StudentExperienceType studentexperiencetype)
        {
            if (ModelState.IsValid)
            {
                db.StudentExperienceTypes.Add(studentexperiencetype);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(studentexperiencetype));
        }
Example #7
0
        public ActionResult Create(NotificationStatus notificationstatus)
        {
            if (ModelState.IsValid)
            {
                db.NotificationStatus.Add(notificationstatus);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(notificationstatus));
        }
        public ActionResult Create(InterviewVenue interviewvenue)
        {
            if (ModelState.IsValid)
            {
                db.InterviewVenues.Add(interviewvenue);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(interviewvenue));
        }
Example #9
0
        public ActionResult Create(StudentParticularType studentparticulartype)
        {
            if (ModelState.IsValid)
            {
                db.StudentParticularTypes.Add(studentparticulartype);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(studentparticulartype));
        }
        public ActionResult Create(AppointmentHost appointmenthost)
        {
            if (ModelState.IsValid)
            {
                db.AppointmentHosts.Add(appointmenthost);
                db.SaveChanges();
                return(RedirectToAction("Edit", new { id = appointmenthost.id }));
            }

            return(View(appointmenthost));
        }
        public ActionResult Create(NotificationTemplate notificationtemplate)
        {
            if (ModelState.IsValid)
            {
                db.NotificationTemplates.Add(notificationtemplate);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.type_id = new SelectList(db.NotificationTypes, "id", "name", notificationtemplate.type_id);
            return(View(notificationtemplate));
        }
Example #12
0
 public ActionResult Create(StudentQualification studentqualification)
 {
     if (ModelState.IsValid)
     {
         db.StudentQualifications.Add(studentqualification);
         try
         {
             db.SaveChanges();
         }
         catch (Exception e)
         {
             return(HttpNotFound("Failed to add qualification.<br/><br/>" + e.Message));
         }
     }
     return(RedirectToAction("MyQualification", "StudentProfile", new { student_id = studentqualification.student_id }));
 }
Example #13
0
 public ActionResult Create(StudentActivity studentactivity, string opener_id = null)
 {
     if (ModelState.IsValid)
     {
         db.StudentActivities.Add(studentactivity);
         try
         {
             db.SaveChanges();
         }
         catch (Exception e)
         {
             return(HttpNotFound("Failed to add activity record.<br/><br/>" + e.Message));
         }
     }
     return(RedirectToAction("ActivityRecord", "StudentProfile", new { student_id = studentactivity.student_id, opener_id = opener_id }));
 }
Example #14
0
 public ActionResult Create(StudentExperience studentexperience)
 {
     if (ModelState.IsValid)
     {
         db.StudentExperiences.Add(studentexperience);
         try
         {
             db.SaveChanges();
         }
         catch (Exception e)
         {
             return(HttpNotFound("Failed to add experience.<br/><br/>" + e.Message));
         }
     }
     return(RedirectToAction("MyExperience", "StudentProfile", new { student_id = studentexperience.student_id }));
 }
Example #15
0
 public ActionResult Create(StudentParticular studentparticular)
 {
     if (ModelState.IsValid)
     {
         db.StudentParticulars.Add(studentparticular);
         try
         {
             db.SaveChanges();
         }
         catch (Exception e)
         {
             return(HttpNotFound("Failed to add particular.<br/><br/>" + e.Message));
         }
     }
     return(RedirectToAction("MyParticular", "StudentProfile", new { student_id = studentparticular.student_id }));
 }
        public ActionResult Create(ProgramStatus programstatus)
        {
            if (ModelState.IsValid)
            {
                db.ProgramStatus.Add(programstatus);
                try
                {
                    db.SaveChanges();
                }
                catch (Exception e)
                {
                    Session["FlashMessage"] = "Failed to create status." + e.Message;
                    return(View(programstatus));
                }
                return(RedirectToAction("Index"));
            }

            return(View(programstatus));
        }
        public ActionResult Create(ExchangeOption exchangeoption)
        {
            if (ModelState.IsValid)
            {
                db.ExchangeOptions.Add(exchangeoption);
                try
                {
                    db.SaveChanges();
                }
                catch (Exception e)
                {
                    Session["FlashMessage"] = "Failed to create exchange destination." + e.Message;
                    return(View(exchangeoption));
                }
                return(RedirectToAction("Index"));
            }

            return(View(exchangeoption));
        }
Example #18
0
 public ActionResult Create(InterviewComment interviewcomment)
 {
     if (ModelState.IsValid)
     {
         try
         {
             interviewcomment.created     = DateTime.Now;
             interviewcomment.created_by  = User.Identity.Name;
             interviewcomment.modified    = DateTime.Now;
             interviewcomment.modified_by = User.Identity.Name;
             db.InterviewComments.Add(interviewcomment);
             db.SaveChanges();
         }
         catch (Exception e)
         {
             return(HttpNotFound("Failed to add Interview Comment.<br/><br/>" + e.Message));
         }
     }
     return(RedirectToAction("Index", "InterviewComment", new { interview_id = interviewcomment.interview_id }));
 }
 public ActionResult Edit(NotificationType notificationtype)
 {
     if (ModelState.IsValid)
     {
         db.Entry(notificationtype).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.templateList = new SelectList(db.NotificationTemplates.Where(t => t.type_id == notificationtype.id), "id", "name");
     return(View(notificationtype));
 }
        public ActionResult Nominate(NominationViewModel ViewModel)
        {
            int        nominatedStatusId = db.NominationStatus.Where(s => s.name == "Nominated").FirstOrDefault().id;
            Nomination nomination        = ViewModel.nomination;

            nomination.status_id       = nominatedStatusId;
            db.Entry(nomination).State = EntityState.Modified;

            foreach (Application application in ViewModel.applications)
            {
                var original = db.Applications.Find(application.id);
                if (application.nominated != original.nominated)
                {
                    original.modified        = DateTime.Now;
                    original.modified_by     = User.Identity.Name;
                    original.nominated       = application.nominated;
                    db.Entry(original).State = EntityState.Modified;
                }
            }

            db.SaveChanges();
            return(RedirectToAction("Nominate", new { id = ViewModel.nomination.id }));
        }
        public ActionResult Create(AppointmentCreateMultipleViewModel ViewModel)
        {
            Appointment appointment = ViewModel.appointment;

            if (ModelState.IsValid)
            {
                if (ViewModel.concerns != null)
                {
                    foreach (var concernid in ViewModel.concerns)
                    {
                        var concern = db.AppointmentConcerns.Find(concernid);
                        if (concern != null)
                        {
                            appointment.AppointmentConcerns.Add(concern);
                        }
                    }
                }
                appointment.end_time = appointment.start_time.AddMinutes(ViewModel.duration);
                db.Appointments.Add(appointment);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            var status = db.AppointmentStatus.Where(s => s.name == "Opened").SingleOrDefault();

            ViewBag.statusList = new SelectList(db.AppointmentStatus, "id", "name", status.id);
            if (User.IsInRole("Admin") || User.IsInRole("Advising") || User.IsInRole("StudentDevelopment"))
            {
                ViewBag.hostList = new SelectList(db.AppointmentHosts, "id", "name");
            }
            else
            {
                ViewBag.hostList = new SelectList(db.AppointmentHosts.Where(h => h.SystemUsers.Any(u => u.UserName == User.Identity.Name)), "id", "name");
            }
            ViewBag.concernList = new SelectList(db.AppointmentConcerns.Where(c => c.program_id == null && !c.custom), "id", "name");
            ViewBag.venueList   = new SelectList(db.AppointmentVenues, "id", "name");
            return(View(appointment));
        }
        public Notification CreateNotification(String type, Application application)
        {
            NotificationType   notificationtype   = db.NotificationTypes.Where(t => t.name == type).SingleOrDefault();
            NotificationStatus notificationstatus = db.NotificationStatus.Where(s => s.name == "Pending").SingleOrDefault();

            if (type == "ApplicationSubmitted")
            {
                if (notificationtype.NotificationTemplate != null)
                {
                    string body    = "";
                    string subject = "";
                    body = notificationtype.NotificationTemplate.body;
                    body = body.Replace("[student id]", application.student_id);
                    body = body.Replace("[student name]", application.StudentProfile.name);
                    body = body.Replace("[application id]", application.id.ToString());
                    body = body.Replace("[program id]", application.program_id.ToString());
                    body = body.Replace("[program name]", application.Program.name);
                    body = body.Replace("[submit date]", String.Format("{0:yyyy-MM-dd HH:mm:ss}", application.submitted));

                    subject = notificationtype.NotificationTemplate.subject;
                    subject = subject.Replace("[student id]", application.student_id);
                    subject = subject.Replace("[student name]", application.StudentProfile.name);
                    subject = subject.Replace("[application id]", application.id.ToString());
                    subject = subject.Replace("[program id]", application.program_id.ToString());
                    subject = subject.Replace("[program name]", application.Program.name);
                    subject = subject.Replace("[submit date]", String.Format("{0:yyyy-MM-dd HH:mm:ss}", application.submitted));

                    Notification notification = new Notification
                    {
                        send_time      = DateTime.Now,
                        sender         = notificationtype.NotificationTemplate.sender,
                        subject        = subject,
                        body           = body,
                        status_id      = notificationstatus.id,
                        type_id        = notificationtype.id,
                        template_id    = notificationtype.NotificationTemplate.id,
                        application_id = application.id,
                        created        = DateTime.Now,
                        created_by     = WebSecurity.CurrentUserName,
                        modified       = DateTime.Now,
                        modified_by    = WebSecurity.CurrentUserName
                    };
                    //db.Notifications.Add(notification);
                    //db.SaveChanges();

                    notification.NotificationRecipients.Add(new NotificationRecipient
                    {
                        email          = application.StudentProfile.email,
                        recipient_type = "to",
                        student_id     = application.student_id
                    });

                    if (!String.IsNullOrEmpty(notificationtype.NotificationTemplate.cc))
                    {
                        List <NotificationRecipient> ccList = new List <NotificationRecipient>();
                        notificationtype.NotificationTemplate.cc.Split(',').ToList().ForEach(s => ccList.Add(new NotificationRecipient {
                            email = s.Trim(), recipient_type = "cc"
                        }));
                        notification.NotificationRecipients = notification.NotificationRecipients.Concat(ccList).ToList();
                    }

                    if (!String.IsNullOrEmpty(notificationtype.NotificationTemplate.bcc))
                    {
                        List <NotificationRecipient> bccList = new List <NotificationRecipient>();
                        notificationtype.NotificationTemplate.bcc.Split(',').ToList().ForEach(s => bccList.Add(new NotificationRecipient {
                            email = s.Trim(), recipient_type = "bcc"
                        }));
                        notification.NotificationRecipients = notification.NotificationRecipients.Concat(bccList).ToList();
                    }

                    db.Notifications.Add(notification);
                    try
                    {
                        db.SaveChanges();
                        return(notification);
                    }
                    catch (Exception e)
                    {
                        Session["FlashMessage"] += "<br/><br/>Failed to create notification record. <br/><br/>" + e.Message;
                    }
                }
                else
                {
                    Session["FlashMessage"] += "<br/><br/>Notification Template is not correctly configured";
                }
            }

            if (type == "ApplicationSavedReminder")
            {
                if (notificationtype.NotificationTemplate != null)
                {
                    string body    = "";
                    string subject = "";
                    body = notificationtype.NotificationTemplate.body;
                    body = body.Replace("[student id]", application.student_id);
                    body = body.Replace("[student name]", application.StudentProfile.name);
                    body = body.Replace("[application id]", application.id.ToString());
                    body = body.Replace("[program id]", application.program_id.ToString());
                    body = body.Replace("[program name]", application.Program.name);
                    body = body.Replace("[program deadline]", String.Format("{0:yyyy-MM-dd HH:mm}", application.Program.application_end_time));
                    body = body.Replace("[submit date]", String.Format("{0:yyyy-MM-dd HH:mm:ss}", application.submitted));

                    subject = notificationtype.NotificationTemplate.subject;
                    subject = subject.Replace("[student id]", application.student_id);
                    subject = subject.Replace("[student name]", application.StudentProfile.name);
                    subject = subject.Replace("[application id]", application.id.ToString());
                    subject = subject.Replace("[program id]", application.program_id.ToString());
                    subject = subject.Replace("[program name]", application.Program.name);
                    subject = subject.Replace("[program deadline]", String.Format("{0:yyyy-MM-dd HH:mm}", application.Program.application_end_time));
                    subject = subject.Replace("[submit date]", String.Format("{0:yyyy-MM-dd HH:mm:ss}", application.submitted));

                    Notification notification = new Notification
                    {
                        send_time      = DateTime.Now,
                        sender         = notificationtype.NotificationTemplate.sender,
                        subject        = subject,
                        body           = body,
                        status_id      = notificationstatus.id,
                        type_id        = notificationtype.id,
                        template_id    = notificationtype.NotificationTemplate.id,
                        application_id = application.id,
                        created        = DateTime.Now,
                        created_by     = WebSecurity.CurrentUserName,
                        modified       = DateTime.Now,
                        modified_by    = WebSecurity.CurrentUserName
                    };
                    //db.Notifications.Add(notification);
                    //db.SaveChanges();

                    notification.NotificationRecipients.Add(new NotificationRecipient
                    {
                        email          = application.StudentProfile.email,
                        recipient_type = "to",
                        student_id     = application.student_id
                    });

                    if (!String.IsNullOrEmpty(notificationtype.NotificationTemplate.cc))
                    {
                        List <NotificationRecipient> ccList = new List <NotificationRecipient>();
                        notificationtype.NotificationTemplate.cc.Split(',').ToList().ForEach(s => ccList.Add(new NotificationRecipient {
                            email = s.Trim(), recipient_type = "cc"
                        }));
                        notification.NotificationRecipients = notification.NotificationRecipients.Concat(ccList).ToList();
                    }

                    if (!String.IsNullOrEmpty(notificationtype.NotificationTemplate.bcc))
                    {
                        List <NotificationRecipient> bccList = new List <NotificationRecipient>();
                        notificationtype.NotificationTemplate.bcc.Split(',').ToList().ForEach(s => bccList.Add(new NotificationRecipient {
                            email = s.Trim(), recipient_type = "bcc"
                        }));
                        notification.NotificationRecipients = notification.NotificationRecipients.Concat(bccList).ToList();
                    }

                    db.Notifications.Add(notification);
                    try
                    {
                        db.SaveChanges();
                        return(notification);
                    }
                    catch (Exception e)
                    {
                        Session["FlashMessage"] += "<br/><br/>Failed to create notification record. <br/><br/>" + e.Message;
                    }
                }
                else
                {
                    Session["FlashMessage"] += "<br/><br/>Notification Template is not correctly configured";
                }
            }
            return(null);
        }
        public ActionResult CreateMultiple(InterviewCreateMultipleViewModel ViewModel)
        {
            Interview interview  = ViewModel.interview;
            var       openStatus = db.InterviewStatus.FirstOrDefault(s => s.default_status);

            if (openStatus == null)
            {
                Session["FlashMessage"] = "Default Status not found.";
                return(RedirectToAction("CreateMultiple"));
            }
            int             openedStatusId      = openStatus.id;
            List <bool>     availableDaysOfWeek = PrepareAvailableDaysOfWeek(ViewModel.config);
            List <Timeslot> timeslots           = new List <Timeslot>();
            DateTime        datecursor          = ViewModel.config.start_date.Date;

            //initialize skipped_dates to avoid null reference
            var skipped_dates = new List <DateTime>();

            if (ViewModel.skipped_dates != null)
            {
                skipped_dates = ViewModel.skipped_dates.ToList();
            }

            try
            {
                while (datecursor <= ViewModel.config.end_date.Date)
                {
                    if (availableDaysOfWeek[Convert.ToInt16(datecursor.DayOfWeek)] && !skipped_dates.Any(d => d.Date == datecursor.Date))
                    {
                        foreach (var session in ViewModel.sessions.Where(s => !s.excluded).ToList())
                        {
                            TimeSpan starttime = session.start_time.TimeOfDay;
                            TimeSpan duration  = new TimeSpan(0, ViewModel.interview.duration + ViewModel.interview.buffer, 0);
                            TimeSpan endtime   = starttime.Add(duration);

                            while (endtime <= session.end_time.TimeOfDay)
                            {
                                bool     overlapped   = false;
                                TimeSpan newstarttime = new TimeSpan();

                                foreach (var ex_session in ViewModel.sessions.Where(x => x.excluded))
                                {
                                    TimeSpan ex_starttime = ex_session.start_time.TimeOfDay;
                                    TimeSpan ex_endtime   = ex_session.end_time.TimeOfDay;
                                    if ((starttime >= ex_starttime && starttime < ex_endtime) ||
                                        (endtime > ex_starttime && endtime <= ex_endtime) ||
                                        (starttime <= ex_starttime && endtime >= ex_endtime))
                                    {
                                        overlapped   = true;
                                        newstarttime = ex_endtime > newstarttime ? ex_endtime : newstarttime;
                                        goto Action;
                                    }
                                }

                                foreach (var ex_session in db.Interviews.Where(i => i.venue_id == interview.venue_id))
                                {
                                    DateTime ex_starttime = ex_session.start_time;
                                    DateTime ex_endtime   = ex_session.end_time;
                                    if ((datecursor.Add(starttime) >= ex_starttime && datecursor.Add(starttime) < ex_endtime) ||
                                        (datecursor.Add(endtime) > ex_starttime && datecursor.Add(endtime) <= ex_endtime) ||
                                        (datecursor.Add(starttime) <= ex_starttime && datecursor.Add(endtime) >= ex_endtime))
                                    {
                                        overlapped   = true;
                                        newstarttime = ex_endtime.TimeOfDay > newstarttime ? ex_endtime.TimeOfDay : newstarttime;
                                        goto Action;
                                    }
                                }

Action:
                                if (!overlapped && endtime <= session.end_time.TimeOfDay)
                                {
                                    interview.start_time = datecursor.Add(starttime);
                                    interview.end_time   = datecursor.Add(endtime);
                                    interview.status_id  = openedStatusId;
                                    db.Interviews.Add(interview);
                                    db.SaveChanges();
                                    starttime = endtime;
                                }
                                else
                                {
                                    starttime = newstarttime;
                                }
                                endtime = starttime.Add(duration);
                            }
                        }
                    }
                    datecursor = datecursor.AddDays(1);
                }
                return(RedirectToAction("Index"));
            }
            catch (Exception e)
            {
                ViewBag.programList     = new SelectList(db.Programs.Where(p => p.require_interview), "id", "name");
                ViewBag.venueList       = new SelectList(db.InterviewVenues.Where(v => v.status), "id", "name");
                Session["FlashMessage"] = "Failed to create interview timeslots." + e.Message;
                return(View(ViewModel));
            }
        }