示例#1
0
        private void subjectEditButton_Click(object sender, EventArgs e)
        {
            var selectedRowIndex = GetSelectedRowIndex(subjectDataGridView);

            if (selectedRowIndex == null)
            {
                return;
            }
            var subject   = SubjectsRepository.GetAll()[(int)selectedRowIndex];
            var subjectVM = new SubjectVM
            {
                Subject    = subject,
                TeacherIds = TeacherSubjectRepository.GetTeachersForSubject(subject.Id),
            };

            new DetailedSubjectForm
            (
                subjectVM,
                TeachersRepository.GetAll(),
                updatedSubjectVM =>
            {
                SubjectsRepository.Update(updatedSubjectVM.Subject);
                TeacherSubjectRepository.UpdateTeachersForSubject(updatedSubjectVM.Subject.Id, updatedSubjectVM.TeacherIds);
                UpdateSubjectsGrid();
                return(true);
            }
            ).Show();
        }
        public async Task <IActionResult> Post([FromBody] SubjectVM model)
        {
            using (var context = new RypDbContext())
            {
                var type = context.SubjectTypes.FirstOrDefault(x => x.Name == model.Type.Name);

                var subject = new Subject();
                subject.RelatedItems = new List <SubjectPrerequisiteSubject>();
                subject.Name         = model.Name;
                subject.Shifr        = model.Shifr;
                subject.Credits      = model.Credits;
                subject.Lec          = model.Lec;
                subject.Lab          = model.Lab;
                subject.Pr           = model.Pr;
                subject.UserId       = model.UserId;
                subject.Date         = DateTime.Now.ToString();
                subject.TypeId       = type.Id;

                for (int i = 0; i < model.Prerequisites.Count; i++)
                {
                    subject.RelatedItems.Add(new SubjectPrerequisiteSubject {
                        Primary = subject, RelatedId = model.Prerequisites[i].Id
                    });
                }
                //subject.Prerequisites = model.Prerequisites;
                //model.Prerequisites.ForEach(p =>{
                //    context.Attach(p);
                //});

                var result = await context.Subjects.AddAsync(subject);

                context.SaveChanges();
            }
            return(Ok());
        }
示例#3
0
        public async Task <IActionResult> Subject(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            Course course = await _db.Courses.Include(c => c.Category).Where(c => c.Id == id && c.isDeleted == false).FirstOrDefaultAsync();

            if (course == null)
            {
                return(NotFound());
            }
            if (course.isDeleted == true)
            {
                return(NotFound());
            }

            List <Subject> subjects = _db.Subjects.Include(s => s.Course).Where(s => s.CourseId == course.Id && s.isDeleted == false).OrderByDescending(s => s.Id).ToList();

            SubjectVM subjectVM = new SubjectVM
            {
                Subjects = subjects,
                Course   = course
            };


            return(View(subjectVM));
        }
 public HttpResponseMessage EditSubject(int id, [FromBody] SubjectVM domain)
 {
     try
     {
         domain.ID = id;
         _SubjectService.Update(domain.MapVM_DM());
         var msg = Request.CreateResponse(HttpStatusCode.Created, domain);
         msg.Headers.Location = new Uri(Request.RequestUri + "/" + domain.ID.ToString());
         return(msg);
     }
     catch (Exception ex)
     {
         //Errors in this scope indicates system error (not validation errors)
         //If error not handled, log it and add system error
         if (!globalErrors.ErrorHandled)
         {
             globalErrors.AddSystemError("Database Error: Cannot Update Subjects!");
             globalErrors.ErrorHandled = true;
             return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex));
         }
         else
         {
             return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex));
         }
         throw;
     }
 }
示例#5
0
        public ActionResult StudentSubjectList()
        {
            var studentUser      = User.Identity.Name;
            var studentId        = db.students.Where(p => p.StudentEmail == studentUser).Select(o => o.StID).FirstOrDefault();
            var studentClassroom = db.StudentClassRooms.Where(l => l.StID == studentId).Select(p => new ClassRoomList {
                GradeName = p.ClassRoom.GradeName, ClassRoomID = p.ClassRoomID
            }).FirstOrDefault();

            ViewBag.gradeName   = studentClassroom.GradeName;
            ViewBag.classRoomId = studentClassroom.ClassRoomID;
            var subjects    = db.Subjects.Include(s => s.ClassRoom).Where(c => c.ClassRoomID == studentClassroom.ClassRoomID);
            var subjectList = new List <SubjectVM>();
            var termList    = db.Terms.ToList();

            foreach (var subject in subjects)
            {
                var subjectVM = new SubjectVM();
                subjectVM.SubjectID             = subject.SubjectID;
                subjectVM.SubjectName           = subject.SubjectName;
                subjectVM.RequirementPercentage = subject.RequiredPercentage;
                subjectVM.termLists             = termList;
                subjectList.Add(subjectVM);
            }
            return(View(subjectList));
        }
示例#6
0
 public DetailsTests()
 {
     _correctSubjectVM = new SubjectVM()
     {
         Name = "Name"
     };
     _loggerFactory = new Mock <ILoggerFactory>();
 }
示例#7
0
        private EntryVM CreateNewEntry(SubjectVM subject = null, TeacherVM teacher = null)
        {
            var newEntry = new EntryVM {
                Subject = subject, Teacher = teacher
            };

            Context.EntitiesVmRegistry.Entries.Add(newEntry);
            return(newEntry);
        }
示例#8
0
        public async Task <ActionResult> DeleteConfirm(int id)
        {
            var     subjectVM = new SubjectVM();
            Subject subject   = await db.Subjects.SingleOrDefaultAsync(c => c.SubjectID == id);

            db.Subjects.Remove(subject);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
		public ActionResult Calendar(SubjectVM subjectVM)
		{
			if (_subjectService.TrySaveCalendar(subjectVM))
			{
				return RedirectToAction("Calendar", new { id = subjectVM.Id });
			}
			else
			{
				return View(subjectVM);
			}
		}
示例#10
0
        public async Task <ActionResult> Create(SubjectVM subjectVM)
        {
            if (ModelState.IsValid)
            {
                var trn = Mapper.Map <Subject>(subjectVM);
                db.Subjects.Add(trn);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(subjectVM));
        }
示例#11
0
        public async Task <ActionResult> Edit(SubjectVM subjectVM)
        {
            if (ModelState.IsValid)
            {
                var trn = Mapper.Map <Subject>(subjectVM);
                db.Entry(trn).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(subjectVM));
        }
示例#12
0
        public ActionResult SelectSubject(SubjectVM model)
        {
            Subject SubjectSelected = _Subject.GetSubject(model.SubjectId);

            if (SubjectSelected != null)
            {
                HttpContext.Session.SetString(SessionSubject, SubjectSelected.SubjectName);
                HttpContext.Session.SetString(NumberQuestion, model.NumberOfQuestion.ToString());
                return(RedirectToAction("QuizTest"));
            }

            return(View());
        }
示例#13
0
        public SubjectVM GetSubject(Expression <Func <Subject, bool> > filterPredicate)
        {
            if (filterPredicate == null)
            {
                throw new ArgumentNullException($"Predicate is null");
            }
            Subject subjectEntity = _dbContext.Subjects
                                    .Include(s => s.Teacher)
                                    .Include(s => s.SubjectGroups)
                                    .ThenInclude(sg => sg.Group)
                                    .FirstOrDefault(filterPredicate);
            SubjectVM subjectVM = _mapper.Map <SubjectVM>(subjectEntity);

            return(subjectVM);
        }
示例#14
0
        public IActionResult SelectSubject()
        {
            ViewData["User"] = HttpContext.Session.GetString(SessionUser);
            SubjectVM subject = new SubjectVM();

            if (ViewData["User"] != null)
            {
                subject.ListOfSubject = _Subject.GetAll();
                return(View(subject));
            }
            else
            {
                return(RedirectToAction("Login", "Home"));
            }
        }
示例#15
0
        public List <SubjectVM> GetSubjects(int classRoomId, int termId, int studentId)
        {
            var db            = new ApplicationDbContext();
            var subjectList   = db.Subjects.Where(i => i.ClassRoomID == classRoomId).ToList();
            var subjectVmList = new List <SubjectVM>();

            foreach (var subject in subjectList)
            {
                var subjectVm = new SubjectVM();
                subjectVm.SubjectID             = subject.SubjectID;
                subjectVm.SubjectName           = subject.SubjectName;
                subjectVm.RequirementPercentage = subject.RequiredPercentage;
                subjectVm.assessments           = GetAssessments(subject.SubjectID, termId, studentId);
                subjectVmList.Add(subjectVm);
            }
            return(subjectVmList);
        }
示例#16
0
        public async Task <IActionResult> Subjects()
        {
            CreateBreadCrumb(new[] { new { Name = "Home", ActionUrl = "#" },
                                     new { Name = "Subject", ActionUrl = "/Subject/Subjects" } });

            BaseViewModel VModel = null;

            var result = await _SubjectService.GetAllSubjects(500);

            var TempVModel = new SubjectVM();

            TempVModel.SubjectInfo      = new AppGridModel <SubjectBM>();
            TempVModel.SubjectInfo.Rows = result;

            VModel = await GetViewModel(TempVModel);

            return(View("~/Views/Master/Subjects.cshtml", VModel));
        }
 public ActionResult GraphicalReports(int classRoomId, string gradeName)
 {
     ViewBag.gradeName = gradeName;
     ViewBag.classRoomId = classRoomId;
     var subjects = db.Subjects.Include(s => s.ClassRoom).Where(c=>c.ClassRoomID == classRoomId);
     var subjectList = new List<SubjectVM>();
     var termList = db.Terms.ToList();
     foreach (var subject in subjects)
     {
         var subjectVM = new SubjectVM();
         subjectVM.SubjectID = subject.SubjectID;
         subjectVM.SubjectName = subject.SubjectName;
         subjectVM.RequirementPercentage = subject.RequiredPercentage;
         subjectVM.termLists = termList;
         subjectList.Add(subjectVM);
     }
     return View(subjectList);
 }
 public bool TrySaveCalendar(SubjectVM subjectVM)
 {
     if (String.IsNullOrWhiteSpace(subjectVM.Calendar))
     {
         return(false);
     }
     else if (!(subjectVM.Calendar.Contains(".calendar.google.com")))
     {
         return(false);
     }
     else
     {
         Subject subject = Get(subjectVM.Id);
         subject.Calendar = subjectVM.Calendar;
         _unitOfWork.SaveChanges();
         return(true);
     }
 }
示例#19
0
        public DetailedSubjectForm(SubjectVM subjectVM, List <Teacher> teacherOptions, Func <SubjectVM, bool> onSubmit)
        {
            InitializeComponent();

            _subject        = subjectVM?.Subject ?? new Subject();
            _teacherOptions = teacherOptions;
            _onSubmit       = onSubmit;

            teacherOptions.ForEach(teacher => teacherListBox.Items.Add(teacher.Name));

            if (subjectVM != null)
            {
                nameTextBox.Text    = subjectVM.Subject.Name;
                facultyTextBox.Text = subjectVM.Subject.Faculty;
                for (var i = 0; i < teacherOptions.Count; i++)
                {
                    teacherListBox.SetSelected(i, subjectVM.TeacherIds.Contains(teacherOptions[i].Id));
                }
            }
        }
示例#20
0
        public CreateOrUpdateSubjectTests()
        {
            _correctSubjectVM = new SubjectVM()
            {
                Id = 1, Name = "Name", Description = "Description"
            };
            _correctSubjectDTO = new SubjectForCreateOrUpdateDTO()
            {
                Id = 1, Name = "Name", Description = "Description", TeacherId = 4
            };
            _alreadyExistsErrorDescription = "This subject already exists!";

            _loggerFactoryMock  = new Mock <ILoggerFactory>();
            _teacherServiceMock = new Mock <ITeacherService>();
            _teacherServiceMock.Setup(ts => ts.GetTeachers(null)).Returns(() => ListOfTeachersVMs());
            _mapperMock = new Mock <IMapper>();
            _mapperMock.Setup(m => m.Map <SubjectForCreateOrUpdateDTO>(_correctSubjectVM)).Returns(() => _correctSubjectDTO);
            _localizerMock = new Mock <IStringLocalizer <SubjectController> >();
            _localizerMock.Setup(l => l["This subject already exists"]).Returns(() =>
                                                                                new LocalizedString("This subject already exists", _alreadyExistsErrorDescription));
        }
示例#21
0
        // GET: Subject/Edit/5
        public async Task <ActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var subjectVM = new SubjectVM();

            {
                Subject subject = await db.Subjects.SingleOrDefaultAsync(c => c.SubjectID == id);

                if (subject == null)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }

                subjectVM.SubjectID   = subject.SubjectID;
                subjectVM.SubjectName = subject.SubjectName;
            }
            return(View(subjectVM));
        }
        public IActionResult Put(int id, [FromBody] SubjectVM model)
        {
            using (var context = new RypDbContext())
            {
                var type = context.SubjectTypes.FirstOrDefault(x => x.Name == model.Type.Name);

                var subject       = context.Subjects.FirstOrDefault(x => x.Id == id);
                var prerequisites = context.SubjectPrerequisiteSubjects.Where(x => x.PrimaryId == subject.Id).ToList();
                subject.RelatedItems = prerequisites;
                subject.Name         = model.Name;
                subject.Shifr        = model.Shifr;
                subject.Credits      = model.Credits;
                subject.Lec          = model.Lec;
                subject.Lab          = model.Lab;
                subject.Pr           = model.Pr;
                subject.UpdateDate   = DateTime.Now.ToString();
                subject.TypeId       = type.Id;

                for (int i = subject.RelatedItems.Count; i > 0; i--)
                {
                    //subject.RelatedItems.Remove(subject.RelatedItems[i - 1]);
                    context.SubjectPrerequisiteSubjects.Remove(subject.RelatedItems[i - 1]);
                }
                context.SaveChanges();
                subject.RelatedItems = new List <SubjectPrerequisiteSubject>();

                for (int i = 0; i < model.Prerequisites.Count; i++)
                {
                    subject.RelatedItems.Add(new SubjectPrerequisiteSubject {
                        Primary = subject, RelatedId = model.Prerequisites[i].Id
                    });
                }

                context.SaveChanges();
            }

            return(Ok());
        }
示例#23
0
        public SubjectController(Action <BlockController> blockGotFocusHandler, Action <BlockController, bool> collapseRequested)
            : base(blockGotFocusHandler, collapseRequested)
        {
            VM = new SubjectVM(VMGotFocus)
            {
                ItemGotFocus = rowVM =>
                {
                    LastFocusedBoxId = rowVM.Persistent?.RowId ?? -1;
                },
                ItemExpanded = (rowVM, isExpanded) =>
                {
                    if (isExpanded)
                    {
                        LastFocusedBoxId = rowVM.Persistent.RowId;
                        if (rowVM.Status == SubjectVM.ChildrenStatus.No)
                        {
                            HandleCommand(Globals.Commands.OPEN);
                        }
                        else if (rowVM.Status == SubjectVM.ChildrenStatus.YesPlaceholder)
                        {
                            LoadChildrenOf(rowVM);
                        }
                    }
                    else
                    {
                        UnloadChildrenOf(rowVM);
                    }
                },
                OpenRequested = () =>
                {
                    HandleCommand(Globals.Commands.OPEN);
                }
            };

            Refresh(null);
        }
示例#24
0
        public ReportVM getReportVM(int classRoomId, int studentId, int termId)
        {
            var db                = new ApplicationDbContext();
            var report            = new ReportVM();
            var getStudentDetails = db.students.Where(f => f.StID == studentId).FirstOrDefault();

            report.StudentName    = getStudentDetails.StudentName;
            report.StudentSurname = getStudentDetails.StudentSurname;
            report.GradeName      = db.ClassRooms.Where(d => d.ClassRoomID == classRoomId).Select(g => g.GradeName).FirstOrDefault();
            var subjectList    = new List <SubjectVM>();
            var getSubjectList = db.Subjects.Where(y => y.ClassRoomID == classRoomId).ToList();

            foreach (var subject in getSubjectList)
            {
                var subjectDetails = new SubjectVM();
                subjectDetails.SubjectName = subject.SubjectName;
                subjectDetails.Mark        = getSubjectTotal(subject.SubjectID, termId, studentId);
                subjectDetails.Average     = getSubjectAverage(subject.SubjectID, termId, classRoomId);
                subjectDetails.Comment     = getComment(subjectDetails.Mark);
                subjectList.Add(subjectDetails);
            }
            report.subjectList = subjectList;
            return(report);
        }
		public ActionResult Calendar(int id)
		{
			SubjectVM subjectVM = Mapper.Map<SubjectVM>(_subjectService.Get(id));
			return View(subjectVM);
		}
示例#26
0
 public void Put(SubjectVM subject)
 {
     service.Update(subject.ToEntity());
 }
示例#27
0
        public SubjectVM Post(SubjectVM subject)
        {
            var rs = service.Add(subject.ToEntity());

            return(rs == null ? null : BaseVM <object> .ToModel <SubjectVM>(rs));
        }
示例#28
0
        public ActionResult Edit(SubjectVM Sub)
        {
            var editedEmployee = client.PutAsJsonAsync <SubjectVM>("subject/" + Sub.ID, Sub).Result;

            return(RedirectToAction("Index"));
        }
示例#29
0
 public ActionResult Create(SubjectVM Sub)
 {
     client.PostAsJsonAsync <SubjectVM>("subject", Sub).ContinueWith((e => e.Result.EnsureSuccessStatusCode()));
     return(RedirectToAction("Index"));
 }
示例#30
0
 public static void UpdateSubject(this Subject model, SubjectVM viewModel)
 {
     model.ID   = viewModel.ID;
     model.Name = viewModel.Name;
 }