// GET: TutorSchedules/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            TutorSchedule tutorSchedule = _db.TutorSchedules.Find(id);

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

            using (var context = new SenecaContext())
            {
                var sqlString = "SELECT Tutor_Id FROM TutorSchedule WHERE Id = " + tutorSchedule.Id;
                var tutorId   = context.Database.SqlQuery <string>(sqlString).FirstOrDefault();
                tutorSchedule.Tutor = _db.Users.Find(tutorId);

                sqlString = "SELECT Student_Id FROM TutorSchedule WHERE Id = " + tutorSchedule.Id;
                var studentId = context.Database.SqlQuery <int>(sqlString).FirstOrDefault();
                tutorSchedule.Student = _db.Students.Find(studentId);
            }

            tutorSchedule.DayName   = GetDayOfWeekName(tutorSchedule.DayOfWeekIndex);
            tutorSchedule.TimeOfDay = ConvertToHhmm(tutorSchedule.MinutesPastMidnight);
            return(View(tutorSchedule));
        }
        public async Task <IActionResult> PutTutorSchedule([FromRoute] Guid id, [FromBody] TutorSchedule tutorSchedule)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != tutorSchedule.Id)
            {
                return(BadRequest());
            }

            _context.Entry(tutorSchedule).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TutorScheduleExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        // GET: TutorSchedules
        public ActionResult Index()
        {
            var model = new List <TutorSchedule>();

            foreach (var tutorSchedule in _db.TutorSchedules.ToList())
            {
                using (var context = new SenecaContext())
                {
                    var sqlString = "SELECT Tutor_Id FROM TutorSchedule WHERE Id = " + tutorSchedule.Id;
                    var tutorId   = context.Database.SqlQuery <string>(sqlString).FirstOrDefault();
                    var tutor     = _db.Users.Find(tutorId);

                    sqlString = "SELECT Student_Id FROM TutorSchedule WHERE Id = " + tutorSchedule.Id;
                    var studentId = context.Database.SqlQuery <int>(sqlString).FirstOrDefault();
                    var student   = _db.Students.Find(studentId);

                    TutorSchedule viewModel = new TutorSchedule()
                    {
                        Id        = tutorSchedule.Id,
                        Tutor     = tutor,
                        Student   = student,
                        DayName   = GetDayOfWeekName(tutorSchedule.DayOfWeekIndex),
                        TimeOfDay = ConvertToHhmm(tutorSchedule.MinutesPastMidnight)
                    };
                    model.Add(viewModel);
                }
            }
            return(View(model));
        }
Пример #4
0
        public ActionResult DeleteConfirmed(int id)
        {
            TutorSchedule tutorSchedule = _db.TutorSchedules.Find(id);

            using (var context = new SenecaContext())
            {
                var sqlString = "SELECT Tutor_Id FROM TutorSchedule WHERE Id = " + id;
                var tutorId   = context.Database.SqlQuery <string>(sqlString).FirstOrDefault();
                if (tutorSchedule != null)
                {
                    tutorSchedule.Tutor     = _db.Users.Find(tutorId);
                    tutorSchedule.DayName   = GetDayOfWeekName(tutorSchedule.MinutesPastMidnight);
                    tutorSchedule.TimeOfDay = ConvertToHhmm(tutorSchedule.MinutesPastMidnight);

                    sqlString = "SELECT Student_Id FROM TutorSchedule WHERE Id = " + tutorSchedule.Id;
                    var     studentId = context.Database.SqlQuery <int>(sqlString).FirstOrDefault();
                    Student student   = _db.Students.Find(studentId);
                    tutorSchedule.Student = student;
                }
            }

            if (tutorSchedule?.Student != null)
            {
                string msgText = "On " + DateTime.Now.ToShortDateString() + " "
                                 + tutorSchedule.Tutor.FullName + " deleted "
                                 + tutorSchedule.Student.FirstName + " "
                                 + tutorSchedule.DayName + " " + tutorSchedule.TimeOfDay;
                Task <ActionResult> unused = new AccountController().EmailSheduleChange(tutorSchedule.Tutor, msgText);
            }

            _db.TutorSchedules.Remove(tutorSchedule ?? throw new InvalidOperationException());
            _db.SaveChanges();

            return(RedirectToAction("Index"));
        }
Пример #5
0
        public ActionResult DeleteConfirmed(int id)
        {
            TutorSchedule tutorSchedule = db.TutorSchedules.Find(id);

            db.TutorSchedules.Remove(tutorSchedule);
            db.SaveChanges();
            return(RedirectToAction("UpdateSchedule"));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            TutorSchedule tutorSchedule = _db.TutorSchedules.Find(id);

            _db.TutorSchedules.Remove(tutorSchedule ?? throw new InvalidOperationException());
            _db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Пример #7
0
 public ActionResult Edit([Bind(Include = "ID,Description,StartTime,EndTime,ThemeColor,IsFullDay,TutorID")] TutorSchedule tutorSchedule)
 {
     if (ModelState.IsValid)
     {
         db.Entry(tutorSchedule).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("UpdateSchedule"));
     }
     ViewBag.TutorID = new SelectList(db.Tutors, "ID", "FirstName", tutorSchedule.TutorID);
     return(View(tutorSchedule));
 }
        public async Task <IActionResult> PostTutorSchedule([FromBody] TutorSchedule tutorSchedule)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.TutorSchedules.Add(tutorSchedule);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetTutorSchedule", new { id = tutorSchedule.Id }, tutorSchedule));
        }
Пример #9
0
        public ActionResult Create([Bind(Include = "Student,DayName,TimeOfDay")]
                                   TutorScheduleViewModel tutorSchedule)
        {
            tutorSchedule.ErrorMessage = null;
            if (tutorSchedule.Student.Id == 0)
            {
                tutorSchedule.ErrorMessage = "Student Required!";
            }

            if (tutorSchedule.ErrorMessage != null || ModelState.IsValid != true) // build drop-down lists:
            {
                tutorSchedule.Students = _db.Students.OrderBy(s => s.FirstName).ToList();
                List <string> daysList = new List <string>
                {
                    "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"
                };
                tutorSchedule.DaysList = daysList;
                List <string> timesList = new List <string>
                {
                    "10:00", "10:15", "10:30", "10:45", "11:00", "11:15", "11:30", "11:45",
                    "1:00", "1:15", "1:30", "1:45", "2:00", "2:15", "2:30", "2:45",
                    "3:00", "3:15", "3:30", "3:45", "4:00", "4:15", "4:30", "4:45",
                    "5:00", "5:15", "5:30", "TBD"
                };
                tutorSchedule.TimesList = timesList;
                return(View(tutorSchedule));
            }

            // if ErrorMessage = null AND ModelState.IsValid:
            string          userId           = User.Identity.GetUserId();
            ApplicationUser user             = (from u in _db.Users where u.Id == userId select u).Single();
            Student         student          = _db.Students.Find(tutorSchedule.Student.Id);
            TutorSchedule   newTutorSchedule = new TutorSchedule()
            {
                Tutor               = user,
                Student             = student,
                DayOfWeekIndex      = GetDayOfWeekIndex(tutorSchedule.DayName),
                DayName             = tutorSchedule.DayName,
                MinutesPastMidnight = ConvertToMinutesPastMidnight(tutorSchedule.TimeOfDay),
                TimeOfDay           = tutorSchedule.TimeOfDay
            };

            _db.TutorSchedules.Add(newTutorSchedule);
            _db.SaveChanges();
            string msgText = "On " + DateTime.Now.ToShortDateString() + " "
                             + newTutorSchedule.Tutor.FullName + " added "
                             + newTutorSchedule.Student.FirstName + " "
                             + newTutorSchedule.DayName + " " + newTutorSchedule.TimeOfDay;
            Task <ActionResult> unused = new AccountController().EmailSheduleChange(user, msgText);

            return(RedirectToAction("Index"));
        }
        public ActionResult Delete(string Id)
        {
            TutorSchedule tutorScheduleToDelete = context.Find(Id);

            if (tutorScheduleToDelete == null)
            {
                return(HttpNotFound());
            }
            else
            {
                return(View(tutorScheduleToDelete));
            }
        }
Пример #11
0
        // GET: Admin/TutorSchedules/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TutorSchedule tutorSchedule = db.TutorSchedules.Find(id);

            if (tutorSchedule == null)
            {
                return(HttpNotFound());
            }
            return(View(tutorSchedule));
        }
        public ActionResult Create(TutorSchedule tutorSchedule)
        {
            if (!ModelState.IsValid)
            {
                return(View(tutorSchedule));
            }
            else
            {
                context.Insert(tutorSchedule);
                context.Commit();

                return(RedirectToAction("Index"));
            }
        }
        public ActionResult ConfirmDelete(string Id)
        {
            TutorSchedule tutorScheduleToDelete = context.Find(Id);

            if (tutorScheduleToDelete == null)
            {
                return(HttpNotFound());
            }
            else
            {
                context.Delete(Id);
                context.Commit();
                return(RedirectToAction("Index"));
            }
        }
Пример #14
0
        public async Task <TutorSchedule> TutorScheduleApi(string ReffId)
        {
            using (var client = new HttpClient())
            {
                var formContent = new FormUrlEncodedContent(new[]
                {
                    new KeyValuePair <string, string>("ReffId", ReffId)
                });

                var request = await client.PostAsync(baseurl + "api/tutorschedules", formContent);

                var content = await request.Content.ReadAsStringAsync();

                TutorSchedule response = JsonConvert.DeserializeObject <TutorSchedule>(content);
                return(response);
            }
        }
        // GET: Tutor/TutorSchedules/Edit/5
        public ActionResult Edit(int?id)
        {
            var userID = User.Identity.GetUserId();

            ViewBag.CurrentTutorID = db.BTTUsers.Where(m => m.ASPNetIdentityID.Equals(userID)).FirstOrDefault().ID;

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TutorSchedule tutorSchedule = db.TutorSchedules.Find(id);

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

            return(View(tutorSchedule));
        }
Пример #16
0
        public ActionResult Index()
        {
            var                    userId    = User.Identity.GetUserId();
            ApplicationUser        user      = (from u in _db.Users where u.Id == userId select u).Single();
            TutorScheduleViewModel viewModel = new TutorScheduleViewModel {
                Tutor = user
            };

            viewModel.Tutor.TutorSchedules = new List <TutorSchedule>();

            foreach (var tutorSchedule in _db.TutorSchedules.ToList())
            {
                using (var context = new SenecaContext())
                {
                    var sqlString = "SELECT Tutor_Id FROM TutorSchedule WHERE Id = " + tutorSchedule.Id;
                    var tutorId   = context.Database.SqlQuery <string>(sqlString).FirstOrDefault();
                    var tutor     = _db.Users.Find(tutorId);
                    if (tutor.Id != userId)
                    {
                        continue;
                    }

                    sqlString = "SELECT Student_Id FROM TutorSchedule WHERE Id = " + tutorSchedule.Id;
                    var studentId = context.Database.SqlQuery <int>(sqlString).FirstOrDefault();
                    var student   = _db.Students.Find(studentId);

                    TutorSchedule ts = new TutorSchedule
                    {
                        Id                  = tutorSchedule.Id,
                        Tutor               = tutor,
                        Student             = student,
                        MinutesPastMidnight = tutorSchedule.MinutesPastMidnight,
                        DayName             = GetDayOfWeekName(tutorSchedule.DayOfWeekIndex),
                        DayOfWeekIndex      = tutorSchedule.DayOfWeekIndex,
                        TimeOfDay           = ConvertToHhmm(tutorSchedule.MinutesPastMidnight)
                    };
                    viewModel.Tutor.TutorSchedules.Add(ts);
                }
            }
            return(View(viewModel));
        }
        public ActionResult Edit(TutorSchedule tutorSchedule, string Id)
        {
            TutorSchedule tutorScheduleToEdit = context.Find(Id);

            if (tutorSchedule == null)
            {
                return(HttpNotFound());
            }
            else
            {
                if (!ModelState.IsValid)
                {
                    return(View(tutorSchedule));
                }

                tutorScheduleToEdit.day  = tutorSchedule.day;
                tutorScheduleToEdit.time = tutorSchedule.time;

                context.Commit();
                return(RedirectToAction("Index"));
            }
        }
        public ActionResult Create([Bind(Include = "ID,Description,StartTime,EndTime,ThemeColor,IsFullDay,TutorID")] TutorSchedule tutorSchedule, DateTime?Date)
        {
            if (Date == null)
            {
                Date = (DateTime.Now).AddDays(1);
            }

            var date      = Date?.ToString("yyyy-MM-dd");
            var startTime = tutorSchedule.StartTime.ToString("HH:mm:ss tt");
            var endTime   = tutorSchedule.EndTime.ToString("HH:mm:ss tt");

            tutorSchedule.StartTime = Convert.ToDateTime(date + " " + startTime);
            tutorSchedule.EndTime   = Convert.ToDateTime(date + " " + endTime);

            if (ModelState.IsValid)
            {
                Dictionary <int, string> tutorColor = new Dictionary <int, string>()
                {
                    { 1, "#ff6e68" },
                    { 2, "#68aeff" },
                    { 3, "#68ffba" }
                };
                var userID         = User.Identity.GetUserId();
                var currentUserID  = db.BTTUsers.Where(m => m.ASPNetIdentityID.Equals(userID)).FirstOrDefault().ID;
                var tutors         = db.Tutors.Select(m => m.ID).ToList();
                var findTutorIndex = (tutors.FindIndex(x => x == currentUserID)) + 1;
                var setTutorColor  = tutorColor[findTutorIndex];

                tutorSchedule.ThemeColor = setTutorColor;
                db.TutorSchedules.Add(tutorSchedule);
                db.SaveChanges();
                return(RedirectToAction("UpdateSchedule"));
            }

            return(View(tutorSchedule));
        }
        public ActionResult Create([Bind(Include = "Tutor,Student,DayName,TimeOfDay")]
                                   TutorScheduleViewModel tutorSchedule)
        {
            tutorSchedule.ErrorMessage = null;
            if (tutorSchedule.Tutor.Id == null)
            {
                tutorSchedule.ErrorMessage = "Tutor Required!";
            }

            if (tutorSchedule.Student.Id == 0)
            {
                tutorSchedule.ErrorMessage = "Student Required!";
            }

            if (tutorSchedule.ErrorMessage != null || ModelState.IsValid != true) // rebuild drop-down lists:
            {
                var tutorRoleId = (from r in _db.Roles where (r.Name == "Tutor") select r.Id).Single();
                var listTutors  = new List <ApplicationUser>();
                var users       = _db.Users.ToList();
                foreach (var user in users)
                {
                    foreach (var role in user.Roles)
                    {
                        if (role.RoleId == tutorRoleId)
                        {
                            listTutors.Add(user);
                        }
                    }
                }

                tutorSchedule.Tutors   = listTutors;
                tutorSchedule.Students = _db.Students.OrderBy(s => s.FirstName).ToList();
                List <string> daysList = new List <string>
                {
                    "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"
                };
                tutorSchedule.DaysList = daysList;
                List <string> timesList = new List <string>
                {
                    "10:00", "10:15", "10:30", "10:45", "11:00", "11:15", "11:30", "11:45",
                    "1:00", "1:15", "1:30", "1:45", "2:00", "2:15", "2:30", "2:45",
                    "3:00", "3:15", "3:30", "3:45", "4:00", "4:15", "4:30", "4:45",
                    "5:00", "5:15", "5:30", "TBD"
                };
                tutorSchedule.TimesList = timesList;
                return(View(tutorSchedule));
            }

            // if ErrorMessage = null AND ModelState.IsValid:
            ApplicationUser tutor            = _db.Users.Find(tutorSchedule.Tutor.Id);
            Student         student          = _db.Students.Find(tutorSchedule.Student.Id);
            TutorSchedule   newTutorSchedule = new TutorSchedule()
            {
                Tutor               = tutor,
                Student             = student,
                DayOfWeekIndex      = GetDayOfWeekIndex(tutorSchedule.DayName),
                MinutesPastMidnight = ConvertToMinutesPastMidnight(tutorSchedule.TimeOfDay)
            };

            _db.TutorSchedules.Add(newTutorSchedule);
            _db.SaveChanges();

            return(RedirectToAction("Index"));
        }
        public ActionResult Create()
        {
            TutorSchedule tutorSchedule = new TutorSchedule();

            return(View(tutorSchedule));
        }