public async Task <IActionResult> Create([Bind("GroupId")] SchedulePlan schedulePlan)
        {
            if (ModelState.IsValid)
            {
                _context.Add(schedulePlan);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Edit), new { id = schedulePlan.Id }));
            }
            return(await Index());
        }
        public async Task <IActionResult> Create([Bind("Id,SpecialtyId,Name,FormationYear")] AcademicGroup group)
        {
            if (ModelState.IsValid)
            {
                _context.Add(group);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            ViewData["SpecialtyId"] = new SelectList(_context.Specialties.OrderBy(c => c.Code).Select(x => new SelectListItem {
                Text = $"{x.Code} - {x.Name}", Value = x.Code
            }), "Value", "Text");
            return(View(group));
        }
        public async Task <IActionResult> Create([Bind("DisciplineId,Year,Semester,ControlType")] SemesterDiscipline semesterDiscipline, string ReturnUrl)
        {
            ViewData["ReturnUrl"]         = ReturnUrl;
            semesterDiscipline.Discipline = await _context.Disciplines.FirstOrDefaultAsync(d => d.Id == semesterDiscipline.DisciplineId);

            if (_context.SemesterDiscipline
                .Where(x => x.DisciplineId == semesterDiscipline.DisciplineId &&
                       x.Year == semesterDiscipline.Year &&
                       x.Semester == semesterDiscipline.Semester).Count() > 0)
            {
                ModelState.AddModelError("", "Семестровая дисциплина с таким курсом и семестром уже существует!");
                return(View(semesterDiscipline));
            }

            if (ModelState.IsValid)
            {
                _context.Add(semesterDiscipline);
                await _context.SaveChangesAsync();

                if (semesterDiscipline.ControlType == ControlType.Exam)
                {
                    var type = _context.ActivityTypes.FirstOrDefault(x => x.Name == RatingControlsController.EXAMTYPENAME);
                    if (type != null)
                    {
                        var exam = new Activity();
                        exam.MaxPoints            = 40;
                        exam.Number               = 1;
                        exam.SemesterDisciplineId = semesterDiscipline.Id;
                        exam.Title  = "Экзамен";
                        exam.TypeId = type.Id;
                        _context.Add(exam);
                        await _context.SaveChangesAsync();
                    }
                }

                if (!string.IsNullOrEmpty(ReturnUrl) && Url.IsLocalUrl(ReturnUrl))
                {
                    return(Redirect(ReturnUrl));
                }
                else
                {
                    return(RedirectToAction("Edit", "Disciplines", new { id = semesterDiscipline.DisciplineId }));
                }
            }
            return(View(semesterDiscipline));
        }
        public async Task <IActionResult> AddDiscipline(int id, int DisciplineId, string ReturnUrl)
        {
            if (_context.TeacherDisciplines.Where(x => x.TeacherId == id && x.DisciplineId == DisciplineId).Any())
            {
                return(Conflict());
            }

            var newTeacherDisp = new TeacherDiscipline
            {
                TeacherId    = (int)id,
                DisciplineId = DisciplineId
            };

            _context.Add(newTeacherDisp);
            await _context.SaveChangesAsync();

            ViewData["ReturnUrl"] = ReturnUrl;
            return(RedirectToAction(nameof(Edit), new { id, ReturnUrl }));
        }
Example #5
0
        public async Task <IActionResult> Create([Bind("Code,AcademicDegree,Name")] Specialty specialty)
        {
            if (ModelState.IsValid)
            {
                _context.Add(specialty);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(specialty));
        }
        public async Task <IActionResult> Mark([Bind("GraduationWorkId,EventId,Mark")] EventLog eventLog)
        {
            if (!EventExists(eventLog.EventId))
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                _context.Add(eventLog);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Mark), new { id = eventLog.EventId }));
            }
            else
            {
                ModelState.AddModelError($"{eventLog.GraduationWorkId}.Mark", "Не выбран вариант");
            }
            return(await Details(eventLog.EventId));
        }
Example #7
0
        public async Task <IActionResult> Protect(int?id, [Bind("Id,StudentId,ActivityId,Points")] ActivityProtection activityProtection, string ReturnUrl, int?groupId)
        {
            if (ModelState.IsValid)
            {
                if (activityProtection.Points > _context.Activities.Find(activityProtection.ActivityId).MaxPoints || activityProtection.Points < 0)
                {
                    ModelState.AddModelError($"student-{activityProtection.StudentId}", "Оценка должна быть в диапозоне от 0 до " + _context.Activities.Find(activityProtection.ActivityId).MaxPoints);
                }

                activityProtection.ProtectionDate = DateTime.Now;
                if (_context.ActivityProtections.Any(x => x.ActivityId == activityProtection.ActivityId && x.StudentId == activityProtection.StudentId))
                {
                    try
                    {
                        _context.Update(activityProtection);
                        await _context.SaveChangesAsync();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!ActivityProtectionExists(activityProtection.Id))
                        {
                            return(NotFound());
                        }
                        else
                        {
                            throw;
                        }
                    }
                }
                else
                {
                    activityProtection.Id = 0;
                    _context.Add(activityProtection);
                    await _context.SaveChangesAsync();
                }
            }

            ViewData["groupId"]   = groupId;
            ViewData["ReturnUrl"] = ReturnUrl;
            return(RedirectToAction(nameof(Protect), new { id = id, groupId = groupId }));
        }
Example #8
0
        public async Task <IActionResult> Create([Bind("StudentId, Theme, ScientificAdviserId, ReviewerId")] GraduationWork graduationWork)
        {
            if (ModelState.IsValid)
            {
                _context.Add(graduationWork);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["StudentId"]           = new SelectList(_context.Students, "GradebookNumber", "FullName", graduationWork.StudentId);
            ViewData["ScientificAdviserId"] = new SelectList(_context.Teachers, "Id", "FullName", graduationWork.ScientificAdviserId);
            ViewData["ReviewerId"]          = new SelectList(_context.Teachers, "Id", "FullName", graduationWork.ReviewerId);
            return(View(graduationWork));
        }
        public async Task <IActionResult> Create([Bind("Id,Name")] ProposedTopic proposedTopic)
        {
            if (ModelState.IsValid)
            {
                _context.Add(proposedTopic);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ModelState.AddModelError("", "Тема должна быть длиной от 10 до 100 символов");
            ViewData["topics"] = await _context.ProposedTopics.ToListAsync();

            return(View("Index", proposedTopic));
        }
        public async Task <IActionResult> Create([Bind("Id,Name")] Discipline discipline, string returnUrl, int?ForGroup)
        {
            if (ModelState.IsValid)
            {
                _context.Add(discipline);
                await _context.SaveChangesAsync();

                if (ForGroup != null)
                {
                    var groupDiscipline = new GroupDiscipline();
                    groupDiscipline.DisciplineId = discipline.Id;
                    groupDiscipline.GroupId      = (int)ForGroup;
                    _context.Add(groupDiscipline);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction("Details", "AcademicGroups", new { id = ForGroup }));
                }

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["returnUrl"] = returnUrl;
            ViewData["ForGroup"]  = ForGroup;
            return(View(discipline));
        }
        public async Task <IActionResult> Create([Bind("SequentialNumber,Description")] EventTemplate eventTemplate)
        {
            if (ModelState.IsValid)
            {
                var eventTemplates = await _context.EventTemplates.ToListAsync();

                eventTemplates.ForEach(x => x.SequentialNumber += x.SequentialNumber >= eventTemplate.SequentialNumber ? +1 : 0);
                _context.UpdateRange(eventTemplates);
                _context.Add(eventTemplate);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ModelState.AddModelError("", "Описание мероприятия должно содержать от 5 до 150 символов");
            return(await Index(eventTemplate));
        }
        public async Task <IActionResult> Create([Bind("GraduationWorkId,TeacherId,Motivation,RequestType")] TeacherRequest teacherRequest, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (!_context.TeacherRequests.Any(x => x.GraduationWorkId == teacherRequest.GraduationWorkId && x.Status == null && x.RequestType == teacherRequest.RequestType))
                {
                    teacherRequest.CreatingDate = DateTime.Now;
                    _context.Add(teacherRequest);
                    await _context.SaveChangesAsync();
                }

                return(RedirectToUrl(returnUrl));
            }
            ViewData["GraduationWorkId"] = new SelectList(_context.GraduationWorks, "Id", "Id", teacherRequest.GraduationWorkId);
            ViewData["TeacherId"]        = new SelectList(_context.Teachers, "Id", "FullName", teacherRequest.TeacherId);
            return(View(teacherRequest));
        }
        public async Task <IActionResult> Create([Bind("GradebookNumber,GroupId,FullName,PhoneNumber")] Student student, string ReturnUrl)
        {
            if (ModelState.IsValid)
            {
                _context.Add(student);
                await _context.SaveChangesAsync();

                if (!string.IsNullOrEmpty(ReturnUrl) && Url.IsLocalUrl(ReturnUrl))
                {
                    return(Redirect(ReturnUrl));
                }
                else
                {
                    return(RedirectToAction("Details", "AcademicGroups", new { id = student.GroupId }));
                }
            }
            ViewData["GroupId"]   = new SelectList(_context.AcademicGroups, "Id", "Name", student.GroupId);
            ViewData["ReturnUrl"] = ReturnUrl;
            return(View(student));
        }
Example #14
0
        public async Task <IActionResult> CreateConfirm(int?groupId, int?disciplineId)
        {
            if (groupId == null || disciplineId == null)
            {
                return(NotFound());
            }

            var lastNumber          = 0;
            var groupRatingControls = _context.RatingControls.Where(x => x.GroupId == groupId && x.SemesterDisciplineId == disciplineId);

            if (groupRatingControls.Any())
            {
                lastNumber = groupRatingControls.OrderByDescending(x => x.Number).FirstOrDefault().Number;
            }

            var newRatingControl = new RatingControl();

            newRatingControl.Number  = lastNumber + 1;
            newRatingControl.GroupId = (int)groupId;
            newRatingControl.SemesterDisciplineId = (int)disciplineId;
            newRatingControl.CompletionDate       = DateTime.Now;

            _context.Add(newRatingControl);
            await _context.SaveChangesAsync();

            var activities = _context.SemesterDiscipline
                             .Include(x => x.Activities)
                             .ThenInclude(y => y.Type)
                             .Where(x => x.Id == disciplineId)
                             .SelectMany(x => x.Activities)
                             .AsNoTracking()
                             .AsEnumerable();

            var pointMultiplier = 1f;

            if (_context.SemesterDiscipline.Find(disciplineId).ControlType == ControlType.Exam)
            {
                var exam = activities.FirstOrDefault(x => x.Type.Name == EXAMTYPENAME);
                if (exam != null)
                {
                    activities.ToList().Remove(exam);
                }
                pointMultiplier = ((float)(60f / activities.Select(x => x.MaxPoints).Sum()));
            }
            else
            {
                pointMultiplier = ((float)(100f / activities.Select(x => x.MaxPoints).Sum()));
            }

            var students = _context.AcademicGroups
                           .Include(x => x.Students)
                           .ThenInclude(x => x.ActivityProtections
                                        .Where(y => activities
                                               .Any(z => y.ActivityId == z.Id)))
                           .Where(x => x.Id == groupId)
                           .SelectMany(x => x.Students);

            var studentsRating = new List <StudentRating>();

            foreach (var student in students)
            {
                var studentRating = new StudentRating();
                studentRating.RatingId  = newRatingControl.Id;
                studentRating.StudentId = student.GradebookNumber;
                studentRating.Points    = (float)(Math.Round(student.ActivityProtections
                                                             .Select(x => x.Points)
                                                             .Sum() * pointMultiplier
                                                             , 1));

                studentsRating.Add(studentRating);
            }

            _context.AddRange(studentsRating);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Group), new { id = groupId, disciplineId = disciplineId }));
        }