Пример #1
0
        public async Task <IActionResult> Create(CreateDepartmentViewModel model)
        {
            if (ModelState.IsValid)
            {
                var headt = await UserManager.FindByIdAsync(model.HeadTeacherId);

                var name = model.Name;
                var inst = await(from i in DBContext.Institutions.Include(d => d.Departments) where i.Id.ToString() == model.InstId select i).FirstOrDefaultAsync();
                if (headt != null && !String.IsNullOrWhiteSpace(name))
                {
                    EDepartment dep = new EDepartment()
                    {
                        Name        = name,
                        HeadTeacher = headt
                    };

                    inst.Departments.Add(dep);
                    DBContext.Departments.Add(dep);
                    await DBContext.SaveChangesAsync();

                    return(RedirectToAction("Index", new { InstId = model.InstId }));
                }
            }
            else
            {
                model.AvailableTeachers = await UserManager.GetUsersInRoleAsync("Teacher");
            }
            return(View(model));
        }
Пример #2
0
        public async Task <IActionResult> Edit(EditInstitutionViewModel model)
        {
            if (ModelState.IsValid)
            {
                var manager = await UserManager.FindByIdAsync(model.ManagerId);

                string name = model.Name;



                var inst = (from i in DBContext.Institutions.Include(m => m.Manager)
                            where i.Id.ToString() == model.Idinst
                            select i).FirstOrDefaultAsync().Result;

                DBContext.Update(inst).Entity.Manager = manager;
                DBContext.Update(inst).Entity.Name    = name;

                await DBContext.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            else
            {
                model.AvailableManagers = await UserManager.GetUsersInRoleAsync("Manager");
            }
            return(View(model));
        }
Пример #3
0
        public async Task <IActionResult> Create(CreateSpecialityViewModel model)
        {
            if (ModelState.IsValid)
            {
                var name = model.Name;
                var dep  = await(from i in DBContext.Departments.Include(s => s.Specialities) where i.Id.ToString() == model.DepId select i).FirstOrDefaultAsync();


                var spec = new ESpeciality()
                {
                    Name = name
                };

                dep.Specialities.Add(spec);
                DBContext.Specialities.Add(spec);
                await DBContext.SaveChangesAsync();

                return(RedirectToAction("Index", new { DepId = model.DepId }));
            }

            return(View(model));
        }
Пример #4
0
 public async Task <IActionResult> UploadFile(IFormFile upload, string tag, string id, string user)
 {
     //здесь пока что нет вообще никакой безопасности
     if (upload != null)
     {
         if (upload.Length >= 10485760)
         {
             return(RedirectToAction("Index", new { DiscId = id, FileError = true }));
         }
         var    euser   = await(from u in DBContext.Users where u.Email.ToLower() == user.ToLower() select u).FirstOrDefaultAsync();
         string t       = tag;
         string outpath = Environment.WebRootPath + "/DisciplineFiles/" + "id" + id + "/" + tag + "/";
         if (!Directory.Exists(outpath))
         {
             Directory.CreateDirectory(outpath);
         }
         outpath += upload.FileName;
         using (var fileStream = new FileStream(outpath, FileMode.Create))
         {
             await upload.CopyToAsync(fileStream);
         }
         var efile = new EFile()
         {
             DateLoad = DateTime.Today.ToShortDateString(),
             UserLoad = euser,
             Tag      = tag,
             Path     = outpath,
             Name     = upload.FileName
         };
         var disc = await(from di in DBContext.Disciplines.Include(f => f.Files)
                          where di.Id.ToString() == id
                          select di).FirstOrDefaultAsync();
         DBContext.Update(disc).Entity.Files.Add(efile);
         await DBContext.SaveChangesAsync();
     }
     return(RedirectToAction("Index", new { DiscId = id }));
 }
Пример #5
0
        public async Task <IActionResult> CreateForumEndpoint(CreateForumEndpointViewModel model)
        {
            if (ModelState.IsValid)
            {
                var creator = await(from u in DBContext.Users
                                    where u.NormalizedEmail == model.CreatorEmail.ToUpper()
                                    select u).FirstOrDefaultAsync();
                var parentNode = await(from n in DBContext.ForumNodes.Include(n => n.ChildEndpoints)
                                       where n.Id.ToString() == model.ParentNodeId
                                       select n).FirstOrDefaultAsync();
                if ((model.EndpointText.IndexOf("<script>") != -1) || (model.EndpointText.IndexOf("</script>") != -1))
                {
                    ModelState.AddModelError("scripts", "Теги <script> запрещены!");
                    return(View(model));
                }
                var safeText = model.EndpointText.Replace("<script>", "");//на всякий
                safeText = safeText.Replace("\n", "<br>");
                var NewEndpoint = new EForumEndpoint()
                {
                    CreatorId    = creator.Id,
                    CreatorEmail = creator.Email,
                    CreatorFio   = creator.FIO,
                    ParentNode   = parentNode,
                    CreationDate = System.DateTime.Now,
                    Name         = model.EndpointName,
                    Text         = safeText,//---
                    PinnedFiles  = new List <EForumFile>()
                };
                // DBContext.ForumEndpoints.Add(NewEndpoint);
                // await DBContext.SaveChangesAsync();
                if (model.UploadedFiles != null)
                {
                    string outfolder = environment.WebRootPath + "/ForumFiles/EPFiles/" + model.EndpointName + "_"
                                       + System.DateTime.Now.ToString("s").Replace(":", "-") + "/";
                    if (!Directory.Exists(outfolder))
                    {
                        Directory.CreateDirectory(outfolder);
                    }

                    foreach (IFormFile file in model.UploadedFiles)
                    {
                        if (file.Length >= 10485760)
                        {
                            ModelState.AddModelError("FileTooBig", "Нельзя загружать файлы свыше 10 Мегабайт.");
                            return(View(model));
                        }
                        var outpath = outfolder + file.FileName;
                        using (var fileStream = new FileStream(outpath, FileMode.Create))
                        {
                            await file.CopyToAsync(fileStream);
                        }
                        var efile = new EForumFile()
                        {
                            Name          = file.FileName,
                            Path          = outpath,
                            TypeOfParent  = 1,
                            ForumEndpoint = NewEndpoint
                        };
                        DBContext.ForumFiles.Add(efile);
                        NewEndpoint.PinnedFiles.Add(efile);
                    }
                }
                DBContext.ForumEndpoints.Add(NewEndpoint);
                await DBContext.SaveChangesAsync();

                //return RedirectToAction("ForumNode", new { NodeId = model.ParentNodeId });
                return(RedirectToAction("ForumEndpoint", new { EndpointId = NewEndpoint.Id }));
            }
            return(View(model));
        }
Пример #6
0
        public async Task <IActionResult> EditSchedule(EditScheduleViewModel model)
        {
            var spec = await(from sp in DBContext.Specialities.Include(s => s.Schedules)
                             where sp.Id.ToString() == model.SpecialityId
                             select sp).FirstOrDefaultAsync();
            var oldShedule = await(from sc in DBContext.WeekSchedules
                                   where sc.id == model.WeekScheduleId
                                   select sc).FirstOrDefaultAsync();

            spec.Schedules.Remove(oldShedule);

            DBContext.Remove(oldShedule);
            if (model.WeekScheduleName == null)
            {
                model.WeekScheduleName = "Без названия";
            }

            var NewWeekSchedule = new EWeekSchedule()
            {
                Name       = model.WeekScheduleName,
                Speciality = spec,
                Schedule   = new List <EDaySchedule>(6)
            };

            // DBContext.WeekSchedules.Add(NewWeekSchedule);

            NewWeekSchedule.Schedule.Add(new EDaySchedule()//mon
            {
                WeekSchedule      = NewWeekSchedule,
                DayNumber         = 0,
                DisciplinesForDay = new List <EScheduleItem>(8)
            });
            //DBContext.DaySchedules.Add(NewWeekSchedule.Schedule[0]);
            for (int i = 0; i < 8; i++)
            {
                var discipline = model.mon[i];
                discipline.DaySchedule = NewWeekSchedule.Schedule[0];
                if (discipline.DisciplineId.ToString() == "-1")
                {
                    discipline.Name       = "Нет пары";
                    discipline.TeacherFIO = "";
                    discipline.Type       = "";
                }
                else
                {
                    var disc = await(from di in DBContext.Disciplines.Include(t => t.Teacher)
                                     where di.Id == discipline.DisciplineId
                                     select di).FirstOrDefaultAsync();
                    discipline.Name       = disc.Name;
                    discipline.TeacherFIO = disc.Teacher.FIO;
                }
                if (discipline.Classroom == null)
                {
                    discipline.Classroom = "";
                }

                NewWeekSchedule.Schedule[0].DisciplinesForDay.Add(discipline);
            }

            NewWeekSchedule.Schedule.Add(new EDaySchedule()//tue
            {
                WeekSchedule      = NewWeekSchedule,
                DayNumber         = 1,
                DisciplinesForDay = new List <EScheduleItem>(8)
            });
            //DBContext.DaySchedules.Add(NewWeekSchedule.Schedule[0]);
            for (int i = 0; i < 8; i++)
            {
                var discipline = model.tue[i];
                discipline.DaySchedule = NewWeekSchedule.Schedule[1];
                if (discipline.DisciplineId.ToString() == "-1")
                {
                    discipline.Name       = "Нет пары";
                    discipline.TeacherFIO = "";
                    discipline.Type       = "";
                }
                else
                {
                    var disc = await(from di in DBContext.Disciplines.Include(t => t.Teacher)
                                     where di.Id == discipline.DisciplineId
                                     select di).FirstOrDefaultAsync();
                    discipline.Name       = disc.Name;
                    discipline.TeacherFIO = disc.Teacher.FIO;
                }
                if (discipline.Classroom == null)
                {
                    discipline.Classroom = "";
                }
                NewWeekSchedule.Schedule[1].DisciplinesForDay.Add(discipline);
            }

            NewWeekSchedule.Schedule.Add(new EDaySchedule()//wed
            {
                WeekSchedule      = NewWeekSchedule,
                DayNumber         = 2,
                DisciplinesForDay = new List <EScheduleItem>(8)
            });
            //DBContext.DaySchedules.Add(NewWeekSchedule.Schedule[0]);
            for (int i = 0; i < 8; i++)
            {
                var discipline = model.wed[i];
                discipline.DaySchedule = NewWeekSchedule.Schedule[2];
                if (discipline.DisciplineId.ToString() == "-1")
                {
                    discipline.Name       = "Нет пары";
                    discipline.TeacherFIO = "";
                    discipline.Type       = "";
                }
                else
                {
                    var disc = await(from di in DBContext.Disciplines.Include(t => t.Teacher)
                                     where di.Id == discipline.DisciplineId
                                     select di).FirstOrDefaultAsync();
                    discipline.Name       = disc.Name;
                    discipline.TeacherFIO = disc.Teacher.FIO;
                }
                if (discipline.Classroom == null)
                {
                    discipline.Classroom = "";
                }
                NewWeekSchedule.Schedule[2].DisciplinesForDay.Add(discipline);
            }

            NewWeekSchedule.Schedule.Add(new EDaySchedule()//thu
            {
                WeekSchedule      = NewWeekSchedule,
                DayNumber         = 3,
                DisciplinesForDay = new List <EScheduleItem>(8)
            });
            //DBContext.DaySchedules.Add(NewWeekSchedule.Schedule[0]);
            for (int i = 0; i < 8; i++)
            {
                var discipline = model.thu[i];
                discipline.DaySchedule = NewWeekSchedule.Schedule[3];
                if (discipline.DisciplineId.ToString() == "-1")
                {
                    discipline.Name       = "Нет пары";
                    discipline.TeacherFIO = "";
                    discipline.Type       = "";
                }
                else
                {
                    var disc = await(from di in DBContext.Disciplines.Include(t => t.Teacher)
                                     where di.Id == discipline.DisciplineId
                                     select di).FirstOrDefaultAsync();
                    discipline.Name       = disc.Name;
                    discipline.TeacherFIO = disc.Teacher.FIO;
                }
                if (discipline.Classroom == null)
                {
                    discipline.Classroom = "";
                }
                NewWeekSchedule.Schedule[3].DisciplinesForDay.Add(discipline);
            }

            NewWeekSchedule.Schedule.Add(new EDaySchedule()//fri
            {
                WeekSchedule      = NewWeekSchedule,
                DayNumber         = 4,
                DisciplinesForDay = new List <EScheduleItem>(8)
            });
            //DBContext.DaySchedules.Add(NewWeekSchedule.Schedule[0]);
            for (int i = 0; i < 8; i++)
            {
                var discipline = model.fri[i];
                discipline.DaySchedule = NewWeekSchedule.Schedule[4];
                if (discipline.DisciplineId.ToString() == "-1")
                {
                    discipline.Name       = "Нет пары";
                    discipline.TeacherFIO = "";
                    discipline.Type       = "";
                }
                else
                {
                    var disc = await(from di in DBContext.Disciplines.Include(t => t.Teacher)
                                     where di.Id == discipline.DisciplineId
                                     select di).FirstOrDefaultAsync();
                    discipline.Name       = disc.Name;
                    discipline.TeacherFIO = disc.Teacher.FIO;
                }
                if (discipline.Classroom == null)
                {
                    discipline.Classroom = "";
                }
                NewWeekSchedule.Schedule[4].DisciplinesForDay.Add(discipline);
            }

            NewWeekSchedule.Schedule.Add(new EDaySchedule()//sat
            {
                WeekSchedule      = NewWeekSchedule,
                DayNumber         = 5,
                DisciplinesForDay = new List <EScheduleItem>(8)
            });
            //DBContext.DaySchedules.Add(NewWeekSchedule.Schedule[0]);
            for (int i = 0; i < 8; i++)
            {
                var discipline = model.sat[i];
                discipline.DaySchedule = NewWeekSchedule.Schedule[5];
                if (discipline.DisciplineId.ToString() == "-1")
                {
                    discipline.Name       = "Нет пары";
                    discipline.TeacherFIO = "";
                    discipline.Type       = "";
                }
                else
                {
                    var disc = await(from di in DBContext.Disciplines.Include(t => t.Teacher)
                                     where di.Id == discipline.DisciplineId
                                     select di).FirstOrDefaultAsync();
                    discipline.Name       = disc.Name;
                    discipline.TeacherFIO = disc.Teacher.FIO;
                }
                if (discipline.Classroom == null)
                {
                    discipline.Classroom = "";
                }
                NewWeekSchedule.Schedule[5].DisciplinesForDay.Add(discipline);
            }
            spec.Schedules.Add(NewWeekSchedule);
            DBContext.Add(NewWeekSchedule);
            await DBContext.SaveChangesAsync();

            return(RedirectToAction("Index", new { SpecId = spec.Id }));
        }
Пример #7
0
        public async Task <IActionResult> ChangeSecuritySettings(UserPageViewModel model)
        {
            List <string> errors = new List <string>();
            var           user   = await userManager.FindByIdAsync(model.UserId);


            if (!(String.IsNullOrWhiteSpace(model.OldPassword) &&
                  String.IsNullOrWhiteSpace(model.NewPassword) &&
                  String.IsNullOrWhiteSpace(model.NewPasswordConfirm)))
            {
                if (String.IsNullOrWhiteSpace(model.OldPassword) ||
                    String.IsNullOrWhiteSpace(model.NewPassword) ||
                    String.IsNullOrWhiteSpace(model.NewPasswordConfirm))
                {
                    errors.Add("Не все поля формы заполнены");
                    return(RedirectToAction("Index", "PersonalPage", new { SecuritySettingsErrors = errors }));
                }

                var oldPassValid = await userManager.CheckPasswordAsync(user, model.OldPassword);

                if (!oldPassValid)
                {
                    errors.Add("Текущий пароль не верный!");
                    return(RedirectToAction("Index", "PersonalPage", new { SecuritySettingsErrors = errors }));
                }
                if (model.NewPassword != model.NewPasswordConfirm)
                {
                    errors.Add("Пароли не совпадают!");
                    return(RedirectToAction("Index", "PersonalPage", new { SecuritySettingsErrors = errors }));
                }
                var validator = HttpContext.RequestServices.GetService(typeof(IPasswordValidator <EUser>))
                                as IPasswordValidator <EUser>;
                var validationResult = await validator.ValidateAsync(userManager, user, model.NewPassword);

                if (!validationResult.Succeeded)
                {
                    errors.Add("Пароль не соответствует<abbr" +
                               " style=\"border:none; text-decoration:none;\"" +
                               " title=\"Минимальная длина - 6 символов; " +
                               "Минимум 1 символ латинского алфавита в верхнем регистре; " +
                               "Минимум 1 символ латинского алфавита в нижнем регистре; " +
                               "Минимум 1 цифра; " +
                               "Минимум 1 небуквенно-цифровой символ." +
                               "\"> <b>требованиям безопасности</b></abbr>");

                    return(RedirectToAction("Index", "PersonalPage", new { SecuritySettingsErrors = errors }));
                }
                var result = await userManager.ChangePasswordAsync(user, model.OldPassword, model.NewPassword);

                if (result.Succeeded)
                {
                    return(RedirectToAction("Index", "PersonalPage", new { SettingsChanged = true }));
                }
                else
                {
                    foreach (var err in result.Errors)
                    {
                        errors.Add(err.Description);
                    }
                    return(RedirectToAction("Index", "PersonalPage", new { SecuritySettingsErrors = errors }));
                }
            }
            if (model.BlockOnFails == true)
            {
                user.BlockOnFailedLogins = 1;
            }
            else
            {
                user.BlockOnFailedLogins = 0;
            }

            if (model.NotifyOnLogin == true)
            {
                user.NotifyOnLogins = 1;
            }
            else
            {
                user.NotifyOnLogins = 0;
            }
            await DBContext.SaveChangesAsync();

            return(RedirectToAction("Index", "PersonalPage", new { SettingsChanged = true }));
        }
Пример #8
0
        public async Task <IActionResult> CreateComplain(CreateComplainViewModel model)
        {
            if (ModelState.IsValid)
            {
                var creator = await(from u in DBContext.Users
                                    where u.NormalizedEmail == model.CreatorEmail.ToUpper()
                                    select u).FirstOrDefaultAsync();

                if ((model.Text.IndexOf("<script>") != -1) || (model.Text.IndexOf("</script>") != -1))
                {
                    ModelState.AddModelError("scripts", "Теги <script> запрещены!");
                    return(View(model));
                }
                var safeText = model.Text.Replace("<script>", "");//на всякий
                safeText = safeText.Replace("\n", "<br>");


                var NewComplain = new EComplain
                {
                    Subject      = model.Subject,
                    Text         = safeText,
                    CreationDate = System.DateTime.Now,
                    PinnedFiles  = new List <EComplainFile>(),
                    Checked      = 0
                };
                if (!model.Anon)
                {
                    NewComplain.CreatorId    = creator.Id;
                    NewComplain.CreatorEmail = creator.Email;
                    NewComplain.CreatorFio   = creator.FIO;
                }
                else
                {
                    NewComplain.CreatorId = "-1";
                }
                DBContext.Complains.Add(NewComplain);
                await DBContext.SaveChangesAsync();

                if (model.UploadedFiles != null)
                {
                    string outfolder = environment.WebRootPath + "/ComplainFiles/" + NewComplain.Id + "/";
                    if (!Directory.Exists(outfolder))
                    {
                        Directory.CreateDirectory(outfolder);
                    }

                    foreach (IFormFile file in model.UploadedFiles)
                    {
                        if (file.Length >= 10485760)
                        {
                            ModelState.AddModelError("FileTooBig", "Нельзя загружать файлы свыше 10 Мегабайт.");
                            return(View(model));
                        }
                        var outpath = outfolder + file.FileName;
                        using (var fileStream = new FileStream(outpath, FileMode.Create))
                        {
                            await file.CopyToAsync(fileStream);
                        }
                        var efile = new EComplainFile()
                        {
                            Name           = file.FileName,
                            Path           = outpath,
                            ParentComplain = NewComplain
                        };
                        DBContext.ComplainFiles.Add(efile);
                        DBContext.Complains.Update(NewComplain).Entity.PinnedFiles.Add(efile);
                    }
                }
                await DBContext.SaveChangesAsync();

                //return RedirectToAction("ForumNode", new { NodeId = model.ParentNodeId });
                return(RedirectToAction("Index", "Home"));
            }
            model.PageLoads += 1;
            return(View(model));
        }