Beispiel #1
0
        public ActionResult Create([Bind(Include = "Tutor,Student")] AssociateTutor associateTutor)
        {
            if (ModelState.IsValid)
            {
                ApplicationUser user              = _db.Users.Find(associateTutor.Tutor.Id);
                Student         student           = _db.Students.Find(associateTutor.Student.Id);
                AssociateTutor  newAssociateTutor = new AssociateTutor
                {
                    Tutor   = user,
                    Student = student
                };
                _db.AssociateTutors.Add(newAssociateTutor);
                try
                {
                    _db.SaveChanges();
                }
                catch (Exception ex)
                {
                    Exception x = ex;
                }

                return(RedirectToAction("Index"));
            }
            else
            {
                return(RedirectToAction("Create", "AssociateTutors"));
            }
        }
        public ActionResult Create([Bind(Include = "Id,name")] Location location)
        {
            if (ModelState.IsValid)
            {
                db.Locations.Add(location);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(location));
        }
        public ActionResult Create([Bind(Include = "Id,UserName,FirstName,LastName,DateTime,Status")] Login login)
        {
            if (ModelState.IsValid)
            {
                _db.Login.Add(login);
                _db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(login));
        }
Beispiel #4
0
        public ActionResult Create([Bind(Include = "Id,Name,Address,MainPhone,Fax,Email,ContactName,ContactEmail,ContactPhone,BoxWeight,ProviderNote")] HfedProvider hfedProvider)
        {
            if (ModelState.IsValid)
            {
                db.HfedProviders.Add(hfedProvider);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(hfedProvider));
        }
Beispiel #5
0
        public ActionResult Create([Bind(Include = "Id,Name")] TipsCategory tipsCategory)
        {
            if (ModelState.IsValid)
            {
                _db.TipsCategories.Add(tipsCategory);
                _db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(tipsCategory));
        }
        public ActionResult Create([Bind(Include = "Id,Name")] DocumentType documentType)
        {
            if (ModelState.IsValid)
            {
                _db.DocumentTypes.Add(documentType);
                _db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(documentType));
        }
        public ActionResult Create([Bind(Include = "Id,Name,Address,Location,MainPhone,LocationNote")] HfedLocation hfedLocation)
        {
            if (ModelState.IsValid)
            {
                db.HfedLocations.Add(hfedLocation);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(hfedLocation));
        }
        public ActionResult Create([Bind(Include = "Id,firstName,lastName,title,workPhone,cellPhone,eMail")] Staff staff)
        {
            if (ModelState.IsValid)
            {
                _db.StaffMembers.Add(staff);
                _db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(staff));
        }
        public ActionResult Create([Bind(Include = "Id,firstName,lastName,address1,cityStateZip,homePhone,cellPhone,eMail")] Volunteer volunteer)
        {
            if (ModelState.IsValid)
            {
                db.Volunteers.Add(volunteer);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(volunteer));
        }
        public ActionResult Create([Bind(Include = "Id,name")] School school)
        {
            if (ModelState.IsValid)
            {
                _db.Schools.Add(school);
                _db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(school));
        }
Beispiel #11
0
        public void TestSaveStudentTutorNote()
        {
            using (SenecaContext db = new SenecaContext())
            {
                Debug.WriteLine(db.Database.Connection.ConnectionString);
                db.Database.Log = Console.Write;
                Student         student = (from s in db.Students where s.FirstName == "Jayden" select s).Single();
                ApplicationUser user    = (from u in db.Users where u.UserName == "p" select u).Single();

                TutorNote note = db.TutorNotes.Create();
                note.Date            = DateTime.Now;
                note.SessionNote     = "xxx";
                note.Student         = student;
                note.ApplicationUser = user;

                db.TutorNotes.Add(note);

                db.SaveChanges();

                TutorNote foundNote = (from n in db.TutorNotes where n.SessionNote == "xxx" select n).SingleOrDefault();
                Assert.IsNotNull(foundNote);
                Assert.AreEqual(student, foundNote.Student);
                Assert.AreEqual(user, foundNote.ApplicationUser);
                Assert.IsTrue(student.TutorNotes.Contains(foundNote));
            }
        }
Beispiel #12
0
        public ActionResult Edit([Bind(Include = "Id,UserName,Active,FirstName,LastName,Title,PhoneNumber,Email")] ApplicationUser user)
        {
            if (ModelState.IsValid)
            {
                ApplicationUser saveUser = (from u in _db.Users.Where(u => u.Id == user.Id) select u).Single();
                saveUser.UserName    = user.UserName;
                saveUser.FirstName   = user.FirstName;
                saveUser.LastName    = user.LastName;
                saveUser.Title       = user.Title;
                saveUser.PhoneNumber = user.PhoneNumber;
                saveUser.Email       = user.Email;

                _db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(user));
        }
Beispiel #13
0
 public void TestNullPrimaryTutor()
 {
     using (SenecaContext db = new SenecaContext())
     {
         var student = db.Students.Find(6);
         student.PrimaryTutor = null;
         db.SaveChanges();
     }
 }
        public ActionResult Edit([Bind(Include = "Id,User,Student,Date,SessionNote")] AddEditTutorNoteViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                var tutorNote = _db.TutorNotes.Find(viewModel.Id);
                if (tutorNote != null)
                {
                    tutorNote.Date            = viewModel.Date;
                    tutorNote.SessionNote     = viewModel.SessionNote;
                    tutorNote.Student         = (from s in _db.Students where s.Id == viewModel.Student.Id select s).Single();
                    tutorNote.ApplicationUser = (from u in _db.Users where u.Id == viewModel.User.Id select u).Single();
                }

                _db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(viewModel));
        }
Beispiel #15
0
        public ActionResult Create([Bind(Include = "DocumentDate,Comments,Student,DocumentType,DocumentLink,PostedFile")] AddEditStudentReportViewModel model)
        {
            if (ModelState.IsValid)
            {
                StudentReport studentReport = new StudentReport
                {
                    DocumentDate = model.DocumentDate,
                    Comments     = model.Comments,
                    DocumentLink = Settings.Default.DocumentStoragePath + model.DocumentLink,
                    DocumentType = (from d in _db.DocumentTypes where d.Id == model.DocumentType.Id select d).Single(),
                    Student      = (from s in _db.Students where s.Id == model.Student.Id select s).Single()
                };

                _db.StudentReports.Add(studentReport);
                _db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(model));
        }
        public ActionResult Create([Bind(Include = "Id,LastName,School,FirstName,WorkPhone,CellPhone,Email")] AddEditTeacherViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                Teacher teacher = new Teacher
                {
                    FirstName = viewModel.FirstName,
                    LastName  = viewModel.LastName,
                    CellPhone = viewModel.CellPhone,
                    WorkPhone = viewModel.WorkPhone,
                    Email     = viewModel.Email
                };
                _db.Teachers.Add(teacher);
                _db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(viewModel));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            HfedSchedule hfedSchedule = db.HfedSchedules.Find(id);

            if (hfedSchedule != null)
            {
                db.HfedSchedules.Remove(hfedSchedule);
            }
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            var hfedClient = db.HfedClients.Find(id);

            if (hfedClient != null)
            {
                db.HfedClients.Remove(hfedClient);
            }
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Beispiel #19
0
 public ActionResult Create([Bind(Include = "MotherFather,FirstName,Address,HomePhone,CellPhone,Email,SelectedMotherFather,CaseManagerUser")] AddEditParentViewModel model)
 {
     if (ModelState.IsValid)
     {
         var parent = _db.Parents.Create();
         parent.MotherFather = model.SelectedMotherFather;
         parent.FirstName    = model.FirstName;
         parent.Email        = model.Email;
         parent.Address      = model.Address;
         parent.HomePhone    = model.HomePhone;
         parent.CellPhone    = model.CellPhone;
         if (model.CaseManagerUser != null)
         {
             parent.CaseManagerUser = _db.Users.Find(model.CaseManagerUser.Id);
         }
         _db.Parents.Add(parent);
         _db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(model));
 }
Beispiel #20
0
        public ActionResult Edit([Bind(Include = "Id,Tutor,Student,DayName,TimeOfDay")]
                                 TutorScheduleViewModel tutorSchedule)
        {
            if (ModelState.IsValid)
            {
                var modifiedSchedule = _db.TutorSchedules.Find(tutorSchedule.Id);
                if (modifiedSchedule != null)
                {
                    using (var context = new SenecaContext())
                    {
                        var             sqlString = "SELECT Tutor_Id FROM TutorSchedule WHERE Id = " + tutorSchedule.Id;
                        var             tutorId   = context.Database.SqlQuery <string>(sqlString).FirstOrDefault();
                        ApplicationUser tutor     = _db.Users.Find(tutorId);
                        modifiedSchedule.Tutor = tutor;
                        tutorSchedule.Tutor    = tutor;

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

                    modifiedSchedule.DayOfWeekIndex      = GetDayOfWeekIndex(tutorSchedule.DayName);
                    modifiedSchedule.MinutesPastMidnight = ConvertToMinutesPastMidnight(tutorSchedule.TimeOfDay);
                    _db.Entry(modifiedSchedule).State    = EntityState.Modified;
                    _db.SaveChanges();
                    if (modifiedSchedule.Student != null)
                    {
                        string msgText = "On " + DateTime.Now.ToShortDateString() + " "
                                         + modifiedSchedule.Tutor.FullName + " changed "
                                         + modifiedSchedule.Student.FirstName + " to "
                                         + tutorSchedule.DayName + " " + tutorSchedule.TimeOfDay;
                        Task <ActionResult> unused = new AccountController().EmailSheduleChange(modifiedSchedule.Tutor, msgText);
                    }

                    return(RedirectToAction("Index"));
                }
            }
            return(View(tutorSchedule));
        }
        public ActionResult Edit([Bind(Include = "Id,FirstName,LastName,PhoneNumber,Email")] UpdateMyProfileViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                var user = _db.Users.Find(viewModel.Id);
                if (user != null)
                {
                    user.FirstName   = viewModel.FirstName;
                    user.LastName    = viewModel.LastName;
                    user.PhoneNumber = viewModel.PhoneNumber;
                    user.Email       = viewModel.Email;

                    _db.SaveChanges();
                    return(RedirectToAction("Index", "HfedHome"));
                }
            }
            return(View(viewModel));
        }
Beispiel #22
0
        // POST: Upload
        public ActionResult Upload(HttpPostedFileBase file, int?studentId, int?documentTypeId)
        {
            if (studentId == null)
            {
                TempData["ErrorMessage"] = "Student ID AND Document Type required. Re-enter all.";
                return(RedirectToAction("Index"));
            }
            if (documentTypeId == null)
            {
                TempData["ErrorMessage"] = "Student ID AND Document Type required. Re-enter all.";
                return(RedirectToAction("Index"));
            }

            try
            {
                if (file != null)
                {
                    var    fileName = Path.GetFileName(file.FileName);
                    string path     = Server.MapPath(" ") + "\\" + fileName;
                    path = path.Replace("\\Upload", "\\UploadFiles");
                    path = path.Replace("\\", "/");
                    file.SaveAs(path);

                    CloudStorageAccount storageAccount = CloudStorageAccount.Parse(Properties.Settings.Default.StorageConnectionString);
                    CloudBlobClient     blobClient     = storageAccount.CreateCloudBlobClient();
                    CloudBlobContainer  container      = blobClient.GetContainerReference("studentreports");
                    CloudBlockBlob      blob           = container.GetBlockBlobReference(fileName);

                    if (blob.Exists())
                    {
                        TempData["ErrorMessage"] = "There is already a file with this name. Re-enter all.";
                        return(RedirectToAction("Index"));
                    }

                    if (fileName != null && fileName.ToUpper().Substring(fileName.Length - 3, 3) == "MP4")
                    {
                        blob.Properties.ContentType = "video/mp4";
                    }
                    else
                    {
                        blob.Properties.ContentType = "application/pdf";
                    }

                    using (var fileStream = System.IO.File.OpenRead(path))
                    {
                        blob.UploadFromStream(fileStream);
                    }

                    System.IO.File.Delete(path);

                    int i = path.IndexOf("UploadFiles", StringComparison.Ordinal);
                    path = path.Remove(0, i + 12);

                    var studentReport = new StudentReport
                    {
                        DocumentLink = path.Replace(@"\", "/"),
                        Student      = _db.Students.Find(studentId),
                        DocumentType = _db.DocumentTypes.Find(documentTypeId),
                        DocumentDate = DateTime.Now
                    };
                    _db.StudentReports.Add(studentReport);
                    _db.SaveChanges();

                    return(RedirectToAction("Edit", "StudentReports", new { id = studentReport.Id }));
                } // If(File != null)
                if (User.IsInRole("Administrator"))
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    return(RedirectToAction("Index", "Home")); // Dashboard
                }
            }
            catch (Exception)
            {
                return(null);
            }
        }
        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"));
        }
Beispiel #24
0
        public ActionResult Create([Bind(Include = "Id,FirstName,Gender,BirthDate,GradeLevel,SpecialClass,School,Parent,PrimaryTutor,Teacher,Active")] AddEditStudentViewModel viewModel)
        {
            viewModel.ErrorMessage = null;
            if (viewModel.School.Id == 0)
            {
                viewModel.ErrorMessage = "School Required!";
            }
            if (viewModel.Parent.Id == 0)
            {
                viewModel.ErrorMessage = "Parent Required!";
            }
            if (viewModel.FirstName == null)
            {
                viewModel.ErrorMessage = "First Name Required!";
            }

            if (viewModel.ErrorMessage != null)  // rebuild drop-down lists:
            {
                List <SelectListItem> schoolList = new List <SelectListItem>();
                foreach (School school in _db.Schools)
                {
                    schoolList.Add(new SelectListItem {
                        Text = school.Name, Value = school.Id.ToString()
                    });
                }
                viewModel.Schools = schoolList;
                List <SelectListItem> parentList = new List <SelectListItem>();

                var sortedParents = _db.Parents.OrderBy(p => p.FirstName).ToList();
                foreach (Parent parent in sortedParents)
                {
                    parentList.Add(new SelectListItem {
                        Text = parent.FirstName, Value = parent.Id.ToString()
                    });
                }
                viewModel.Parents = parentList;

                List <SelectListItem> userList = new List <SelectListItem>();
                var sortedUsers = _db.Users.OrderBy(u => u.LastName).ThenBy(u => u.FirstName).ToList();
                foreach (ApplicationUser user in sortedUsers)
                {
                    if (user.Id != null)
                    {
                        userList.Add(new SelectListItem {
                            Text = user.LastName + @", " + user.FirstName, Value = user.Id
                        });
                    }
                }
                viewModel.Users = userList;

                List <SelectListItem> teacherList = new List <SelectListItem>();
                var sortedTeachers = _db.Teachers.OrderBy(p => p.LastName).ToList();
                foreach (Teacher teacher in sortedTeachers)
                {
                    teacherList.Add(new SelectListItem
                    {
                        Text  = teacher.LastName + @", " + teacher.FirstName,
                        Value = teacher.Id.ToString()
                    });
                }
                viewModel.Teachers = teacherList;

                return(View(viewModel));
            }

            if (ModelState.IsValid)
            {
                Student student = new Student
                {
                    FirstName    = viewModel.FirstName,
                    Gender       = viewModel.Gender,
                    BirthDate    = viewModel.BirthDate,
                    GradeLevel   = viewModel.GradeLevel,
                    SpecialClass = viewModel.SpecialClass,
                    Parent       = (from p in _db.Parents where p.Id == viewModel.Parent.Id select p).Single(),
                    School       = (from s in _db.Schools where s.Id == viewModel.School.Id select s).Single()
                };

                if (viewModel.PrimaryTutor.Id != null)
                {
                    student.PrimaryTutor = (from t in _db.Users where t.Id == viewModel.PrimaryTutor.Id select t).Single();
                }
                if (viewModel.Teacher.Id != 0)
                {
                    student.Teacher = (from t in _db.Teachers where t.Id == viewModel.Teacher.Id select t).Single();
                }

                student.Active = viewModel.Active;
                _db.Students.Add(student);
                _db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(RedirectToAction("Create"));
        }
Beispiel #25
0
        // POST: Upload
        public ActionResult Upload(HttpPostedFileBase file, int?studentId, int?documentTypeId)
        {
            if (studentId == null)
            {
                TempData["ErrorMessage"] = "Student ID AND Document Type required. Re-enter all.";
                return(RedirectToAction("Index"));
            }
            if (documentTypeId == null)
            {
                TempData["ErrorMessage"] = "Student ID AND Document Type required. Re-enter all.";
                return(RedirectToAction("Index"));
            }

            var    fileName = Path.GetFileName(file.FileName);
            string path     = Server.MapPath(" ") + "\\" + fileName;

            path = path.Replace("\\Upload", "\\StudentReportFiles");
            path = path.Replace("\\", "/");
            file.SaveAs(path);

            //{
            //    FileName = System.IO.Path.GetFileName(upload.FileName),
            //    FileType = FileType.Avatar,
            //    ContentType = upload.ContentType
            //};
            //using (var reader = new System.IO.BinaryReader(upload.InputStream))
            //{
            //    avatar.Content = reader.ReadBytes(upload.ContentLength);
            //}
            //student.Files = new List<File> { avatar };

            //CloudStorageAccount storageAccount = CloudStorageAccount.Parse(Settings.Default.StorageConnectionString);
            //CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
            //CloudBlobContainer container = blobClient.GetContainerReference("studentreports");
            //CloudBlockBlob blob = container.GetBlockBlobReference(fileName);

            //if (blob.Exists())
            //{
            //    TempData["ErrorMessage"] = "There is already a file with this name. Re-enter all.";
            //    return RedirectToAction("Index");
            //}

            //if (fileName != null && fileName.ToUpper().Substring(fileName.Length - 3, 3) == "MP4")
            //{
            //    blob.Properties.ContentType = "video/mp4";
            //}
            //else
            //{
            //    blob.Properties.ContentType = "application/pdf";
            //}

            //using (var fileStream = System.IO.File.OpenRead(path))
            //{
            //    //blob.UploadFromStream(fileStream);
            //}

            //System.IO.File.Delete(path);

            //int i = path.IndexOf("UploadFiles", StringComparison.Ordinal);
            //path = path.Remove(0, i + 12);

            var studentReport = new StudentReport
            {
                DocumentLink = fileName,
                Student      = _db.Students.Find(studentId),
                DocumentType = _db.DocumentTypes.Find(documentTypeId),
                DocumentDate = DateTime.Now
            };

            _db.StudentReports.Add(studentReport);
            _db.SaveChanges();

            return(RedirectToAction("Edit", "StudentReports", new { id = studentReport.Id }));


            //if (User.IsInRole("Administrator"))
            //{
            //    return RedirectToAction("Index");
            //}
            //else
            //{
            //    return RedirectToAction("Index", "Home"); // Dashboard
            //}
        }
        public ActionResult Create(HttpPostedFileBase file, int?categoryId, string name)
        {
            if (categoryId == null)
            {
                TempData["ErrorMessage"] = "Category required. Re-enter all.";
                return(RedirectToAction("Create"));
            }

            try
            {
                if (file != null)
                {
                    var    fileName = Path.GetFileName(file.FileName);
                    string path     = Server.MapPath(" ") + "\\" + fileName;
                    path = path.Replace("\\TipDocuments", "\\UploadFiles");
                    path = path.Replace("\\", "/");
                    file.SaveAs(path);

                    CloudStorageAccount storageAccount =
                        CloudStorageAccount.Parse(Settings.Default.StorageConnectionString);
                    CloudBlobClient    blobClient = storageAccount.CreateCloudBlobClient();
                    CloudBlobContainer container  = blobClient.GetContainerReference("teachingtips");
                    CloudBlockBlob     blob       = container.GetBlockBlobReference(fileName);

                    if (blob.Exists())
                    {
                        TempData["ErrorMessage"] = "There is already a file with this name. Re-enter all.";
                        return(RedirectToAction("Create"));
                    }

                    if (fileName != null && fileName.ToUpper().Substring(fileName.Length - 3, 3) == "MP4")
                    {
                        blob.Properties.ContentType = "video/mp4";
                    }
                    else
                    {
                        blob.Properties.ContentType = "application/pdf";
                    }

                    using (var fileStream = System.IO.File.OpenRead(path))
                    {
                        blob.UploadFromStream(fileStream);
                    }

                    System.IO.File.Delete(path);

                    int i = path.IndexOf("UploadFiles", StringComparison.Ordinal);
                    path = path.Remove(0, i + 12);

                    string currentUserId = User.Identity.GetUserId();
                    var    tipDocument   = new TipDocument
                    {
                        DocumentLink = path.Replace(@"\", "/"),
                        User         = _db.Users.Find(currentUserId),
                        Category     = _db.TipsCategories.Find(categoryId),
                        Name         = name
                    };
                    _db.TipDocuments.Add(tipDocument);
                    _db.SaveChanges();

                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception)
            {
                return(null);
            }
            TempData["ErrorMessage"] = "File not found error.";
            return(RedirectToAction("Create"));
        }