Ejemplo n.º 1
0
        public int SaveMentorshipRequest(MentorScheduleModel msm)
        {
            Mentorship mship = new Mentorship();

            mship.active       = 1;
            mship.fk_mentorId  = msm._mentorId;
            mship.fk_studentId = msm.studentId;
            mship.fk_subject   = msm.subject;
            mship.status       = 1;//requested - 1,Accepted - 2,Rejected - 3
            mship.comments     = msm.comment;
            context.Mentorships.Add(mship);
            for (int i = 0; i <= 6; i++)
            {
                for (int j = 0; j < msm._schedule[i]._timeandRequest.Count; j++)
                {
                    MentorScheduleRequest msr = new MentorScheduleRequest();
                    msr.fk_day_Id     = msm._schedule[i].day;
                    msr.fk_mentor_Id  = msm._mentorId;
                    msr.fk_student_Id = msm.studentId;
                    msr.Mentorship    = mship;
                    msr.isRequested   = msm._schedule[i]._timeandRequest[j].isRequested;
                    msr.fk_time_id    = msm._schedule[i]._timeandRequest[j].timeId;
                    context.MentorScheduleRequests.Add(msr);
                }
            }
            try
            {
                return(context.SaveChanges());
            }
            catch (Exception e)
            {
                return(0);
            }
        }
Ejemplo n.º 2
0
        public void AcceptScheduleResponse(int mid, int stuid, int subid, int mshipid)
        {
            List <MentorScheduleRequest> msrList = (from r in context.MentorScheduleRequests
                                                    where r.fk_mentor_Id == mid & r.Mentorship.id == mshipid
                                                    select r).ToList();
            List <MentorSchedule> msList = (from r in context.MentorSchedules
                                            where r.fk_mentor_Id == mid
                                            select r).ToList();
            List <StudentSchedule> ssList = (from r in context.StudentSchedules
                                             where r.fk_student_Id == stuid
                                             select r).ToList();

            foreach (MentorScheduleRequest msr in msrList)
            {
                Mentorship mship = msr.Mentorship;
                mship.status = 2;//accepted
                if (msr.isRequested == 1)
                {
                    MentorSchedule ms = (from m in msList
                                         where m.fk_day_Id == msr.fk_day_Id & m.fk_time_id == msr.fk_time_id
                                         select m).FirstOrDefault();

                    /*if(ms.fk_mentorship_id != null){
                     *  throw new Exception();
                     * }*/
                    ms.fk_mentorship_id = msr.fk_mentorship_id;
                    StudentSchedule ss = (from m in ssList
                                          where m.fk_day_Id == msr.fk_day_Id & m.fk_time_id == msr.fk_time_id
                                          select m).FirstOrDefault();
                    ss.fk_mentorship_id = msr.fk_mentorship_id;
                }
            }
            context.SaveChanges();
        }
Ejemplo n.º 3
0
        private MentorshipVM GetMentorshipVM(Mentorship mentorship)
        {
            var dbTopic = TopicService.GetTopic(mentorship.TopicId);

            var rtnMentorship = new MentorshipVM(mentorship, new TopicVM(dbTopic));

            var dbLearner = this.mainContext.Users.Where(u => u.Id == mentorship.LearnerUserId).FirstOrDefault();

            if (dbLearner != null)
            {
                rtnMentorship.Learner = new UserVM(dbLearner);
            }

            if (rtnMentorship.HasMentor)
            {
                var dbMentor = this.mainContext.Users.Where(u => u.Id == mentorship.MentorUserId).FirstOrDefault();

                if (dbMentor != null)
                {
                    rtnMentorship.Mentor = new UserVM(dbMentor);
                }
                else
                {
                    rtnMentorship.MentorshipId = Guid.Empty;
                    rtnMentorship.HasMentor    = false;
                }
            }

            return(rtnMentorship);
        }
Ejemplo n.º 4
0
        public MentorScheduleModel FindthisMentorshipSchedule(int mshipID)
        {
            Mentorship mship = mr.GetMentorship(mshipID);

            MentorScheduleModel msm = new MentorScheduleModel();

            msm._mentorId    = mship.fk_mentorId;
            msm.subject      = mship.fk_subject;
            msm.subjectName  = mship.subject.name;
            msm.studentId    = mship.fk_studentId;
            msm.mentorShipID = mshipID;
            List <DaySchedule> schList = new List <DaySchedule>();

            List <MentorSchedule> msList = mr.GetMentorSchedule(mship.fk_mentorId);       //find all mentor schedule records from the mentorSchedule table

            for (int i = 1; i <= 7; i++)
            {
                DaySchedule ds = new DaySchedule();
                ds.day = i;
                List <TimeandRequest> timeList            = new List <TimeandRequest>();
                List <MentorSchedule> eachdayschedulelist = (from l in msList where l.fk_day_Id == i select l).ToList();
                foreach (MentorSchedule eachSchedule in eachdayschedulelist)
                {
                    TimeandRequest tnr = new TimeandRequest();
                    tnr.timeId      = eachSchedule.fk_time_id;
                    tnr.isRequested = eachSchedule.fk_mentorship_id == mshipID ? 1 : 0;
                    timeList.Add(tnr);
                }
                ds._timeandRequest = timeList;
                schList.Add(ds);
            }
            msm._schedule = schList;

            return(msm);
        }
Ejemplo n.º 5
0
        public ActionResult Edit([Bind(Include = "MentorshipID,ThesisTypeID,MentorshipTypeID,PersonID,Student,ThesisTitle,Remarks,Year,Semester")] MentorshipViewModel mentorshipViewModel)
        {
            if (ModelState.IsValid)
            {
                Mentorship model = db.Mentorships.Find(mentorshipViewModel.MentorshipID);

                model.ThesisTypeID     = mentorshipViewModel.ThesisTypeID;
                model.MentorshipTypeID = mentorshipViewModel.MentorshipTypeID;
                model.PersonID         = mentorshipViewModel.PersonID;
                model.Student          = mentorshipViewModel.Student;
                model.ThesisTitle      = mentorshipViewModel.ThesisTitle;
                model.Remarks          = mentorshipViewModel.Remarks;
                model.Year             = mentorshipViewModel.Year;
                model.Semester         = mentorshipViewModel.Semester;

                model.DateModified   = DateTime.Now;
                model.UserModifiedID = Guid.Parse(User.Identity.GetUserId());

                db.Entry(model).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            PopulateThesisTypesDropDownList(mentorshipViewModel.ThesisTypeID, mentorshipViewModel.MentorshipTypeID);
            PopulatePersonsDropDownList(mentorshipViewModel.PersonID);
            return(View(mentorshipViewModel));
        }
Ejemplo n.º 6
0
        public Response <Mentorship> Post([FromBody] Mentorship value)
        {
            var service = new Services.Relationships.MentorshipService(Context, CurrentUser);

            // service.SaveMentorship(value);

            return(new Response <Mentorship>(value));
        }
Ejemplo n.º 7
0
        public ActionResult DeleteConfirmed(Guid id)
        {
            Mentorship mentorship = db.Mentorships.Find(id);

            db.Mentorships.Remove(mentorship);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 8
0
        public void RejectScheduleResponse(int mid, int stuid, int subid, int mshipid)
        {
            List <MentorScheduleRequest> msrList = (from r in context.MentorScheduleRequests
                                                    where r.fk_mentor_Id == mid & r.Mentorship.id == mshipid
                                                    select r).ToList();

            foreach (MentorScheduleRequest msr in msrList)
            {
                Mentorship mship = msr.Mentorship;
                mship.status = 3;//rejected
            }
            context.SaveChanges();
        }
Ejemplo n.º 9
0
        // GET: Mentorships/Details/5
        public ActionResult Details(Guid?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Mentorship mentorship = db.Mentorships.Find(id);

            if (mentorship == null)
            {
                return(HttpNotFound());
            }
            return(View(mentorship));
        }
Ejemplo n.º 10
0
        public VideoConference GetVideoConference(int mshipID)
        {
            VideoConference res = new VideoConference();

            res.isMentor = true;
            Mentorship mship = mr.GetMentorship(mshipID);
            int        mid   = mship.fk_mentorId;
            int        sid   = mship.fk_studentId;

            res.mname   = mr.GetNameFromID(mid);
            res.sname   = mr.GetNameFromID(sid);
            res.mshipID = mshipID;

            return(res);
        }
Ejemplo n.º 11
0
        public ActionResult InsertMentors()
        {
            ViewBag.Message = "Insert Mentors";

            //string path = "c:/MACA/mentors.txt";
            string path = "";
            //string path = ""; // To prevent bad actions!
            StreamReader            srMentors        = new StreamReader(path);
            List <Mentorship>       lstMentors       = new List <Mentorship>();
            MentorshipsDbContext    dbMentors        = new MentorshipsDbContext();
            PersonsDbContext        dbPersons        = new PersonsDbContext();
            MentorshipTypeDbContext dbMentorshipType = new MentorshipTypeDbContext();
            ThesisTypeDbContext     dbThesisType     = new ThesisTypeDbContext();

            while (!srMentors.EndOfStream)
            {
                string[]   lineArr = srMentors.ReadLine().Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries);
                Mentorship mentor  = new Mentorship();
                mentor.MentorshipID = Guid.NewGuid();
                string personCode = lineArr[0].Trim();
                mentor.PersonID = dbPersons.Persons.Where(x => x.AISID == personCode).First().PersonID;
                int mentortype = int.Parse(lineArr[1].Trim());
                mentor.MentorshipTypeID = dbMentorshipType.MentorshipTypes.Where(x => x.AISCode == mentortype).First().MentorshipTypeID;
                mentor.Year             = lineArr[2].Trim();
                int thesistype = int.Parse(lineArr[3].Trim());
                mentor.ThesisTypeID = dbThesisType.ThesisTypes.Where(x => x.AISCode == thesistype).First().ThesisTypeID;
                mentor.Student      = lineArr[4].Trim() + " " + lineArr[5].Trim();
                mentor.ThesisTitle  = lineArr[6].Trim();
                lstMentors.Add(mentor);
            }
            srMentors.Close();

            // Insert Persons


            foreach (Mentorship mentor in lstMentors)
            {
                mentor.DateCreated    = DateTime.Now;
                mentor.DateModified   = DateTime.Now;
                mentor.UserCreatedID  = new Guid(User.Identity.GetUserId());
                mentor.UserModifiedID = mentor.UserCreatedID;

                dbMentors.Mentorships.Add(mentor);
                dbMentors.SaveChanges();
            }

            return(RedirectToAction("Administration"));
        }
Ejemplo n.º 12
0
        public void RegisterLearner(Guid UserId, Guid TopicId)
        {
            if (UserId == this.Actor.UserId || this.Actor.Roles.Contains("Admin"))
            {
                var dbMentorship = this.mainContext.Mentorships.Where(m => m.LearnerUserId == UserId && m.TopicId == TopicId && m.Active).FirstOrDefault();

                if (dbMentorship == null)
                {
                    var newMentorship = new Mentorship(UserId, TopicId);
                    this.mainContext.Mentorships.Add(newMentorship);
                }

                SetUserTopic(UserId, TopicId, TopicStatus.Novice);

                this.mainContext.SaveChanges();
            }
        }
Ejemplo n.º 13
0
        // GET: Mentorships/Edit/5
        public ActionResult Edit(Guid?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Mentorship mentorship = db.Mentorships.Find(id);

            if (mentorship == null)
            {
                return(HttpNotFound());
            }

            PopulateThesisTypesDropDownList(mentorship.ThesisTypeID, mentorship.MentorshipTypeID);
            PopulatePersonsDropDownList(mentorship.PersonID);
            return(View(mentorship));
        }
Ejemplo n.º 14
0
        public ActionResult WriteReview(int mshipID)
        {
            Mentorship mentorship = ch.GetMentorship(mshipID);

            UserImage img = mentorship.MentorProfile.User.UserImage;
            Review    rev = mentorship.Review;

            WriteReviewViewModel model = new WriteReviewViewModel
            {
                MentorshipId  = mshipID,
                ImageFilename = img != null ? img.imagePath : "",
                MentorName    = mentorship.MentorProfile.User.fname + " " + mentorship.MentorProfile.User.lname,
                Email         = mentorship.MentorProfile.User.UserID,
                Subject       = mentorship.subject.name,
                Rating        = rev == null ? -1 : (int)rev.rating,
                Comment       = rev == null ? "" : rev.comments
            };

            return(View(model));
        }
Ejemplo n.º 15
0
        public ActionResult Create([Bind(Include = "ThesisTypeID,MentorshipTypeID,PersonID,Student,ThesisTitle,Remarks,Year,Semester")] Mentorship mentorship)
        {
            if (ModelState.IsValid)
            {
                mentorship.MentorshipID = Guid.NewGuid();

                mentorship.DateCreated  = DateTime.Now;
                mentorship.DateModified = mentorship.DateCreated;

                mentorship.UserCreatedID  = Guid.Parse(User.Identity.GetUserId());
                mentorship.UserModifiedID = mentorship.UserCreatedID;

                db.Mentorships.Add(mentorship);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            PopulateThesisTypesDropDownList();
            PopulatePersonsDropDownList();
            return(View(mentorship));
        }
Ejemplo n.º 16
0
        public MentorScheduleModel FindthisScheduleRequest(int mshipID)
        {
            List <MentorScheduleRequest> reqList = mr.GetMentorScheduleRequests(mshipID);
            Mentorship          mship            = mr.GetMentorship(mshipID);
            MentorScheduleModel msm = new MentorScheduleModel();

            msm._mentorId    = mship.fk_mentorId;
            msm.subject      = mship.fk_subject;
            msm.subjectName  = mship.subject.name;
            msm.studentId    = mship.fk_studentId;
            msm.comment      = mship.comments;   //same mentorship id for all mentorschedulerequest records
            msm.name         = mr.GetNameFromID(mship.fk_studentId);
            msm.imgpath      = mr.GetStuImgPath(mship.fk_studentId);
            msm.mentorShipID = mshipID;
            List <DaySchedule>    schList           = new List <DaySchedule>();
            List <MentorSchedule> allMyBusySchedule = mr.GetMentorBusySchedule(mship.fk_mentorId);

            for (int i = 1; i <= 7; i++)
            {
                DaySchedule ds = new DaySchedule();
                ds.day = i;
                List <TimeandRequest>        timeList            = new List <TimeandRequest>();
                List <MentorScheduleRequest> eachdayschedulelist = (from l in reqList where l.fk_day_Id == i select l).ToList();
                foreach (MentorScheduleRequest eachSchedule in eachdayschedulelist)
                {
                    TimeandRequest tnr = new TimeandRequest();
                    tnr.timeId      = eachSchedule.fk_time_id;
                    tnr.isRequested = eachSchedule.isRequested;
                    tnr.isClashing  = (tnr.isRequested == 1) && ((from a in allMyBusySchedule where a.fk_day_Id == i && a.fk_time_id == tnr.timeId select a).Count() > 0);
                    timeList.Add(tnr);
                }
                ds._timeandRequest = timeList;
                schList.Add(ds);
            }
            msm._schedule = schList;

            return(msm);
        }