public List <SubjectModel> GetSubjects(int viewRequestId) { List <SubjectModel> subjects = new List <SubjectModel>(); using (SqlConnection conn = new SqlConnection(_connectionString)) { conn.Open(); SqlCommand cmd = new SqlCommand("dbo.GetSubjects", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@viewRequestId", viewRequestId); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { SubjectModel subject = new SubjectModel(); subject.Id = reader["Id"] != DBNull.Value ? Convert.ToInt32(reader["Id"]) : 0; subject.Question = reader["Question"] != DBNull.Value ? Convert.ToString(reader["Question"]) : string.Empty; subject.Answer = reader["Answer"] != DBNull.Value ? Convert.ToString(reader["Answer"]) : string.Empty; subject.ViewRequestId = reader["ViewRequestId"] != DBNull.Value ? Convert.ToInt32(reader["ViewRequestId"]) : 0; subjects.Add(subject); } } return(subjects); }
public QuestionModel AskQuestion(SubjectModel subject) { if (!new SubjectValidator(subject).Validate(out string errorCode)) { throw new DefinedException(GetLocalizedResource(errorCode)); } Question result = null; _questionRepository.UseTransaction(() => { var user = _userRepository.Get(UserId); if (user == null) { throw new DefinedException(GetLocalizedResource(ErrorDefinitions.User.UserNotFound)); } result = _questionRepository.Add(new Question(subject.Title, subject.Content, subject.CategoryId, UserId)); _questionRepository.SaveChanges(); user.UserScores.IncreaseContribution((int)ContributeTypeDefinition.NewQuestionAdded, new NewQuestionContributionRule().IncreasingValue, result.Id); _questionRepository.SaveChanges(); }); return(QuestionModel(result)); }
public bool AddSubject(SubjectModel subject) { bool isSuccess = false; DbConnection dbConnection = new DbConnection(); SqlCommand cmd = new SqlCommand("add_subject", dbConnection.connection); cmd.CommandType = System.Data.CommandType.StoredProcedure; try { dbConnection.OpenConnection(); cmd.Parameters.AddWithValue("@name", subject.Name); cmd.Parameters.AddWithValue("@image", ConvertImageToBinary(subject.Image)); int rows = cmd.ExecuteNonQuery(); if (rows > 0) { isSuccess = true; } } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { dbConnection.CloseConnection(); } return(isSuccess); }
// GET api/<controller>/5 public SubjectModel Get(int id) { SubjectManager manager = new SubjectManager(); var subject = manager.Get(id); return(SubjectModel.Convert(subject)); }
public SubjectModel LoadSubjectByName(string name) { DbConnection dbConnection = new DbConnection(); SubjectModel subject = null; try { dbConnection.OpenConnection(); SqlCommand cmd = new SqlCommand("select * from subjects where subject_name=@name", dbConnection.connection); cmd.Parameters.AddWithValue("@name", name); SqlDataReader reader = cmd.ExecuteReader(); if (reader.HasRows) { subject = new SubjectModel(); while (reader.Read()) { subject.Id = reader.GetInt32(0); subject.Name = reader.GetString(1); subject.Image = ConvertBinaryToImage((byte[])reader["subject_image"]); } } reader.Close(); } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { dbConnection.CloseConnection(); } return(subject); }
public List <SubjectModel> LoadSubjectsList() { List <SubjectModel> subjects = new List <SubjectModel>(); DbConnection dbConnection = new DbConnection(); try { dbConnection.OpenConnection(); SqlCommand cmd = new SqlCommand("select * from subjects", dbConnection.connection); SqlDataReader reader = cmd.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { SubjectModel subject = new SubjectModel(); subject.Id = reader.GetInt32(0); subject.Name = reader.GetString(1); subject.Image = ConvertBinaryToImage((byte[])reader["subject_image"]); subjects.Add(subject); } } } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { dbConnection.CloseConnection(); } return(subjects); }
public ClashFinder(List <SubjectModel> subjectModels, Func <Slot[], List <List <Slot> > > permutator) { var selectedSubjects = subjectModels.FindAll(x => x.IsSelected); for (var i = 0; i < selectedSubjects.Count; i++) { SubjectModel s = selectedSubjects[i]; int[] subjectState = GetSubjectState(permutator(s.GetSelectedSlots().ToArray())); _subjectStateList.Add(new SubjectModelWithState(s.Name, subjectState)); } for (int i = 0; i < _subjectStateList.Count; i++) { for (int j = 0; j < _subjectStateList.Count; j++) { if (i == j) { continue; } if (_subjectStateList[i].ClashesWith(_subjectStateList[j])) { Message = $"Because\n--{_subjectStateList[i].SubjectName}\nclashes with\n--{_subjectStateList[j].SubjectName}"; return; } } } Message = $"Sorry... the reason is too complicated to be explained."; }
private List <SubjectModel> GetInput(string raw) { var result = new SlotParser().Parse(raw); var subjects = SubjectModel.Parse(result); return(subjects); }
public ICollection <SubjectModel> GetSubjects(int?studyYearId = default(int?), int?departmentID = default(int?)) { ICollection <SubjectModel> lista = new List <SubjectModel>(); try { OracleConnection connection = _context.OpenConnection(); OracleCommand cmd = connection.CreateCommand(); cmd.CommandText = "SELECT Distinct t5.id,t5.title FROM BP07.User_Enrollment t1" + " JOIN BP07.LabGroup t2 ON t1.LabGroupId = t2.Id" + " JOIN BP07.Course_Department t3 ON t2.Course_DepartmentId = t3.Id" + " JOIN BP07.Department t4 ON t3.DepartmentId = t4.id" + " JOIN BP07.Course t5 ON t5.Id = t3.CourseId" + " WHERE t1.studyyearid = '" + studyYearId + "' AND t3.departmentId ='" + departmentID + "'"; OracleDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { int id = reader.GetInt32(0); string naziv = reader.GetString(1); SubjectModel s = new SubjectModel { ID = id, Title = naziv }; lista.Add(s); } return(lista); } catch (Exception e) { return(null); // throw new Exception("Error: " + e.Message); } }
public SubjectModel CreateOrUpdate(SubjectModel model) { Logger.Debug($"{model}"); if (model == null) { throw new System.ArgumentNullException("model"); } Subject subject = null; if (model.Id == null || model.Id == System.Guid.Empty) { subject = this.UnitOfWork.SubjectRepository.CreateSubject(model.Name, model.SubjectGroupId, model.HighlightColor, model.IsActive); } else { subject = this.UnitOfWork.SubjectRepository.UpdateSubject(model.Id, model.Name, model.SubjectGroupId, model.HighlightColor, model.IsActive); } this.UnitOfWork.SaveChanges(); SubjectModel subjectModel = Mapper.Map <Models.Subject, Models.SubjectModel>(subject); return(subjectModel); }
public async Task <IActionResult> PutSubject(int id, [FromBody] SubjectModel subject) { try { if (id != subject.Id) { return(BadRequest(id)); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } await SubjectService.UpdateSubject(id, subject); return(NoContent()); } catch (Exception ex) { if (await SubjectService.GetSubject(id) == null) { return(NotFound()); } else { return(BadRequest(ex)); } } }
public ActionResult Index() { try { var Group = Connection.GDgetAllSubject("Y"); List <GDgetAllSubject_Result> Grouplist = Group.ToList(); SubjectModel tcm = new SubjectModel(); List <SubjectModel> tcmlist = Grouplist.Select(x => new SubjectModel { SubjectId = x.SubjectId, ShortName = x.ShortName, SubjectName = x.SubjectName, CreatedBy = x.CreatedBy, CreatedDate = x.CreatedDate, IsActive = x.IsActive, ModifiedBy = x.ModifiedBy, ModifiedDate = x.ModifiedDate }).ToList(); return(View(tcmlist)); } catch (Exception ex) { Errorlog.ErrorManager.LogError(ex); return(View()); } }
public JsonResult SubjectEdit(int SubjectId, SubjectModel SubjectModel) { try { if (SubjectId == 0) { Core3Base.Infra.Data.Entity.Subjects Subject = new Core3Base.Infra.Data.Entity.Subjects { SubjectName = SubjectModel.Subject.SubjectName, IsActive = SubjectModel.Subject.IsActive, LessonId = SubjectModel.Subject.LessonId }; return(Json(_SubjectService.Add(Subject).HttpGetResponse())); } else { var Subject = _SubjectService.GetSubjectById(SubjectId).Result; Subject.IsActive = SubjectModel.Subject.IsActive; Subject.SubjectName = SubjectModel.Subject.SubjectName; Subject.LessonId = SubjectModel.Subject.LessonId; Subject.DateModified = DateTime.Now; return(Json(_SubjectService.Update(Subject).HttpGetResponse())); } } catch (Exception e) { return(Json(e.Message)); } }
public async Task <bool> AddSubjectAsync(SubjectModel subjectModel) { _context.Subject.Add(subjectModel); var saveResult = await _context.SaveChangesAsync(); return(saveResult == 1); }
public QuestionModel UpdateQuestion(SubjectModel subject) { if (!new SubjectValidator(subject).Validate(out string errorCode)) { throw new DefinedException(GetLocalizedResource(errorCode)); } Question question = null; _questionRepository.UseTransaction(() => { if (!_userRepository.Exists(UserId)) { throw new DefinedException(GetLocalizedResource(ErrorDefinitions.User.UserNotFound)); } question = _questionRepository.Get(subject.Id); if (question == null) { throw new DefinedException(GetLocalizedResource(ErrorDefinitions.Question.QuestionNotExists)); } if (question.OwnerId != UserId) { throw new DefinedException(GetLocalizedResource(ErrorDefinitions.User.AccessDenied)); } question.Update(subject.Title, subject.Content, subject.CategoryId); _questionRepository.SaveChanges(); }); return(QuestionModel(question)); }
public void insertSubject(SubjectModel objLec) { try { string Query = "Insert into subjects(subject_Code,year,semester,sub_name,lec_hours,tut_hours,lab_hours,eve_hours) " + "values('" + objLec.SubCode + "','" + objLec.Year + "','" + objLec.Semester + "','" + objLec.SubName + "','" + objLec.LecHour + "','" + objLec.TutHour + "','" + objLec.LabHour + "','" + objLec.EveHour + "')"; SqlCommand cmd = new SqlCommand(Query, DBConnection.DatabaseConnection); SqlDataReader myReader; DBConnection.OpenConnection(); myReader = cmd.ExecuteReader(); while (myReader.Read()) { } DBConnection.CloseConnection(); } catch (Exception ex) { } }
protected void ddlSubject_SelectedIndexChanged(object sender, EventArgs e) { if (ddlSubject.SelectedIndex != 0) { if (SubjectModel.subjectType(ddlSubject.SelectedValue) == "L") { rdbL.Enabled = true; rdbT.Enabled = true; } else { rdbSubjectType.SelectedIndex = 0; rdbL.Enabled = false; rdbT.Enabled = false; } ArrayList auxPA = DbConnection.getDbData("SELECT SUM(percentage) FROM Activity WHERE idSubject = '" + ddlSubject.SelectedValue + "' AND idType = '" + rdbSubjectType.SelectedValue + "';"); double auxP = 0; double.TryParse((String)auxPA[0], out auxP); lblPercentage.Text = "Porcentaje de la actividad [Disponible: " + (100 - (auxP * 100)) + "%]."; } else { rdbSubjectType.SelectedIndex = 0; rdbL.Enabled = false; rdbT.Enabled = false; } }
public void Subjects_Controller_Test_On_EditModel_With_Invalid_Model() { //Arrange Guid id = new Guid("f616cc8c-2223-4145-b7d0-232a1f6f0795"); string title = "TestT"; int noOfCredits = 10; Subject expectedSubjects = new Subject(title, noOfCredits); expectedSubjects.Id = id; SubjectModel expectedModel = new SubjectModel(); expectedModel.Title = " "; var repo = Substitute.For <IRepository>(); var sut = new SubjectsController(repo); repo.Update(expectedSubjects); //Act sut.ModelState.AddModelError("FirstName", "Firstname Required"); var actual = sut.Edit(id, expectedSubjects).Result; //Assert Assert.IsInstanceOfType(actual, typeof(ViewResult)); }
// [Authorize(Roles = "Manager")] public ActionResult CreateSubject(SubjectModel model) { if (ModelState.IsValid) { Subject subject = new Subject { Name = model.Name }; // create subject _subjectService.CreateSubject(subject); return(StatusCode(201)); // 201: Created } else { // response helper method var errors = new List <string>(); foreach (var state in ModelState) { foreach (var error in state.Value.Errors) { errors.Add(error.ErrorMessage); } } return(BadRequest(errors)); } }
public async Task <IActionResult> Edit(int id, [Bind("Id,Title")] SubjectModel subjectModel) { if (id != subjectModel.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(subjectModel); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SubjectModelExists(subjectModel.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(subjectModel)); }
public SubjectForm(SubjectModel subject, SubjectsForm patrentForm) { InitializeComponent(); _subject = subject; PrepareForm(); _parentForm = patrentForm; }
// [Authorize(Roles = "Manager, Subject")] public ActionResult EditSubject(int subjectId, SubjectModel model) { var subject = _subjectService.GetSubject(subjectId); // if no subject is found if (subject == null) { return(NotFound()); } // check if model matches with data annotation in front-end model if (ModelState.IsValid) { // bind value subject.Name = model.Name; // save change _subjectService.Update(); return(Ok(subject)); } else { var errors = new List <string>(); foreach (var state in ModelState) { foreach (var error in state.Value.Errors) { errors.Add(error.ErrorMessage); } } return(BadRequest(errors)); } }
private SubjectEntity MapOneSubject(SubjectModel subjectModel) { string subjectJson = TimetableSerializer.SerializeToJson(subjectModel); string subjectHash = HashCoder.GetSha256Hash(subjectJson); var info = new SubjectInfoEntity { Title = subjectModel.Title, Teachers = subjectModel.Teachers, LectureStartDate = subjectModel.LectureStartDate, LectureEndDate = subjectModel.LectureEndDate, PracticeStartDate = subjectModel.PracticeStartDate, PracticeEndDate = subjectModel.PracticeEndDate }; string infoJson = TimetableSerializer.SerializeToJson(info); string infoHash = HashCoder.GetSha256Hash(infoJson); info.Hash = infoHash; string daysJson = TimetableSerializer.SerializeToJson(subjectModel.Days); string daysHash = HashCoder.GetSha256Hash(daysJson); SubjectEntity entity = new SubjectEntity { Info = info, Days = MapSchoolDays(subjectModel.Days), HashDays = daysHash, Hash = subjectHash }; return(entity); }
public ClashFinder(List <SubjectModel> selectedSubjects, Func <Slot[], List <List <Slot> > > permutator, SubjectModel target) { _selectedSubjects = selectedSubjects; _target = target; if (selectedSubjects.Count == 2) { ClashingSubjects = ( new SubjectModelWithState(target.Name, null), new SubjectModelWithState(selectedSubjects.Find(x => x.Code != target.Code).Name, null)); return; } for (var i = 0; i < selectedSubjects.Count; i++) { SubjectModel s = selectedSubjects[i]; int[] subjectState = GetSubjectState(permutator(s.GetSelectedSlots().ToArray())); _subjectStateList.Add(new SubjectModelWithState(s.Name, subjectState)); } for (int i = 0; i < _subjectStateList.Count; i++) { for (int j = 0; j < _subjectStateList.Count; j++) { if (i == j) { continue; } if (_subjectStateList[i].ClashesWith(_subjectStateList[j])) { ClashingSubjects = (_subjectStateList[i], _subjectStateList[j]); return; } } } ClashingSubjects = null; }
public List <Teacher> ShowTeachers() { List <TeacherModel> teacherModels = _schoolManagementDbContext.teachers.ToList(); List <Teacher> teachers = new List <Teacher>(); foreach (var item in teacherModels) { Teacher teacher = new Teacher(); teacher.TeacherId = item.TeacherId; teacher.Name = item.Name; teacher.SubjectId = item.SubjectId; teacher.SchoolId = item.SchoolId; SchoolModel schoolModel = _schoolManagementDbContext.schools.Find(item.SchoolId); teacher.school = new School(); teacher.school.SchoolId = schoolModel.SchoolId; teacher.school.Name = schoolModel.Name; teacher.school.Address = schoolModel.Address; SubjectModel subjectModel = _schoolManagementDbContext.subjects.Find(item.SubjectId); teacher.subject = new Subject(); teacher.subject.SubjectId = subjectModel.SubjectId; teacher.subject.SubjectName = subjectModel.SubjectName; teachers.Add(teacher); } return(teachers); }
public static SubjectViewModel ToSubjectViewModel(this SubjectModel Model) { SubjectViewModel ViewModel = new SubjectViewModel(); ViewModel = Mapper.Map <SubjectModel, SubjectViewModel>(Model); return(ViewModel); }
public Teacher ShowTeacherRecord(int id) { TeacherModel teacherModel = _schoolManagementDbContext.teachers.Find(id); Teacher teacher = new Teacher(); teacher.TeacherId = teacherModel.TeacherId; teacher.Name = teacherModel.Name; teacher.SubjectId = teacherModel.SubjectId; teacher.SchoolId = teacherModel.SchoolId; SchoolModel schoolModel = _schoolManagementDbContext.schools.Find(teacherModel.SchoolId); teacher.school = new School(); teacher.school.SchoolId = schoolModel.SchoolId; teacher.school.Name = schoolModel.Name; teacher.school.Address = schoolModel.Address; SubjectModel subjectModel = _schoolManagementDbContext.subjects.Find(teacherModel.SubjectId); teacher.subject = new Subject(); teacher.subject.SubjectId = subjectModel.SubjectId; teacher.subject.SubjectName = subjectModel.SubjectName; return(teacher); }
public IActionResult Delete(SubjectModel subject) { SubjectsServices mongo = new SubjectsServices("school", "subjects", "mongodb://localhost:27017/"); mongo.delete(subject); return(Redirect("/Subjects/")); }
public async Task <IEnumerable <SubjectModel> > GetSubjectsForClass(int classId) { var @class = await this.data.Classes.Include(c => c.Subject).FirstOrDefaultAsync(c => c.Id == classId); if (@class == null) { throw new Exception("Class doesn't exist"); } var classSubjects = @class.Subject.Any() ? @class.Subject : new List <Subject>(); var subjectModel = new SubjectModel(); var subjects = new List <SubjectModel>(); foreach (var subject in classSubjects) { subjectModel = new SubjectModel { Id = subject.Id, Name = subject.Name, SchoolId = subject.SchoolId, ClassId = @class.Id }; subjects.Add(subjectModel); } return(subjects); }
public HttpResponseMessage CreateSubject(SubjectModel model, [ValueProvider(typeof(HeaderValueProviderFactory <string>))] string accessToken) { var responseMsg = this.PerformOperationAndHandleExceptions(() => { var dbContext = new TimetableContext(); using (dbContext) { var user = this.GetUserByAccessToken(accessToken, dbContext); var newSubject = new Subject { Owner = user, Name = model.Name, Color = model.Color, Teacher = model.Teacher }; user.Subjects.Add(newSubject); dbContext.SaveChanges(); var responseModel = new ResponseModel() { Id = newSubject.Id }; var response = this.Request.CreateResponse(HttpStatusCode.OK, responseModel); return(response); } }); return(responseMsg); }
private MainModel() { CameraModel = new CameraModel(); PlayerDataModel = new PlayerDataModel(); AvailablePlayers = new List<PlayerModel>(); ScreenState = ScreenState.PlayerSelection; ChoicesModel = new ChoicesModel(); SubjectModel = new SubjectModel(); ActiveLevelProgress = 0; }