public bool CreateConnections(int[] documents, LessonPlan lessonPlan) { foreach (int id in documents) { int identifier = (int)char.GetNumericValue(id.ToString()[0]); bool success = true; switch (identifier) { case 1: success = documentConnector.ConnectArt(lessonPlan, id); break; case 2: success = documentConnector.ConnectPoem(lessonPlan, id); break; case 3: success = documentConnector.ConnectWriting(lessonPlan, id); break; default: Console.WriteLine("Invalid Document Id"); success = false; break; } Data.SaveChanges(); if (success == false) { return(false); } } return(true); }
public void Post([FromBody] LessonPlanRequest lessonPlan) { var ClassId = (from academicClasses in _dbcontext.AcademicClasses join academicClassSubject in _dbcontext.AcademicClassSubjects on academicClasses.AcademicClassId equals academicClassSubject.AcademicClassId join sub in _dbcontext.Subjects on academicClassSubject.SubjectID equals sub.SubjectID orderby sub.SubjectID select new { academicClasses.ClassName, academicClassSubject.AcademicClassId, academicClassSubject.AcademicClassSubjectId, sub.SubjectDescr }).Where(X => X.ClassName == lessonPlan.ClassName && X.SubjectDescr == lessonPlan.SubjectName).Distinct().FirstOrDefault(); LessonPlan _updLessonPlan = new LessonPlan(); _updLessonPlan.AcademicClassId = ClassId.AcademicClassId; _updLessonPlan.AcademicClassSubjectId = ClassId.AcademicClassSubjectId; _updLessonPlan.date = lessonPlan.date; _updLessonPlan.classWork = lessonPlan.classWork; _updLessonPlan.homeWork = lessonPlan.homeWork; _updLessonPlan.lesson = lessonPlan.lesson; _updLessonPlan.games = lessonPlan.games; _updLessonPlan.activity = lessonPlan.activity; _updLessonPlan.classActivity = lessonPlan.classActivity; _updLessonPlan.topic = lessonPlan.topic; _updLessonPlan.extraInfo = lessonPlan.extraInfo; _updLessonPlan.concept = lessonPlan.concept; _dbcontext.LessonPlans.Add(_updLessonPlan); _dbcontext.SaveChanges(); }
public async Task <IActionResult> Edit(int id, LessonPlan lessonPlan) //[Bind("Id,classroom,dayId,startTime,stopTime, course")] { if (id != lessonPlan.Id) { return(NotFound()); } if (ModelState.IsValid) { lessonPlan.day = (Days)lessonPlan.dayId; try { _context.Update(lessonPlan); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!LessonPlanExists(lessonPlan.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(lessonPlan)); }
private Guid Insert(LessonPlan lessonPlan, ref StringBuilder sbError) { // check if lesson plan exist for that date range bool dbFlag = false; var allLessonPlans = _uofRepository.LessonPlanRepository.GetListLessonPlansByTeacherClassSubjectID(lessonPlan.TeacherClassSubjectId, ref dbFlag); if (allLessonPlans == null) { var isRangeExist = allLessonPlans.Where(c => c.DateStart >= lessonPlan.DateStart && c.DateEnd <= lessonPlan.DateEnd).FirstOrDefault(); if (isRangeExist != null) { sbError.Append("There is a lesson plan for that date already"); return(Guid.Empty); } } var save = _uofRepository.LessonPlanRepository.Save(lessonPlan, _user.Username, ref dbFlag); if (save == null) { sbError.Append("Error saving lesson plan"); return(Guid.Empty); } return((Guid)save.LessonPlanId); }
public LessonPlan GetLessonPlanById(int id) { LessonPlan otherMethod = Data.Lessonplans.Where(l => l.LessonPlanId == id).FirstOrDefault(); otherMethod.Lesson_Art = Data.lessonPlan_ArtPieces.Where(l => l.LessonPlanId == id).ToList(); otherMethod.Lesson_Poems = Data.lessonPlan_Poems.Where(l => l.LessonPlanId == id).ToList(); otherMethod.Lesson_Writing = Data.lessonPlan_WritingAssignments.Where(l => l.LessonPlanId == id).ToList(); otherMethod.Themes = Data.LessonThemes.Where(l => l.LessonId == id).ToList(); otherMethod.ArtPieces = new List <ArtPiece>(); otherMethod.poems = new List <Poem>(); otherMethod.WritingAssignments = new List <WritingAssignment>(); foreach (LessonPlan_ArtPiece art in otherMethod.Lesson_Art) { otherMethod.ArtPieces.Add(Data.ArtPieces.Where(w => w.ArtPieceId == art.ArtPieceId).FirstOrDefault()); } foreach (var poem in otherMethod.Lesson_Poems) { otherMethod.poems.Add(Data.Poems.Find(poem.PoemId)); } foreach (var writing in otherMethod.Lesson_Writing) { otherMethod.WritingAssignments.Add(Data.WritingAssignments.Find(writing.WritingAssignmentId)); } return(otherMethod); }
public async Task <bool> Do(RegisterLessonPlanEvent message) { try { LessonPlan lessonPlan = _unitOfWork.lessonPlanRepository.Get(message.Id); if (lessonPlan != null) { lessonPlan.AssignDescription(message.Description); lessonPlan.AssignIsActive(message.IsActive); lessonPlan.AssignIsDeleted(message.IsDeleted); lessonPlan.AssignModifiedDate(DateTime.Now); lessonPlan.IncreaseRowVersion(); lessonPlan.AssignSession(message.SessionId); lessonPlan.AssignLevel(message.Level); _unitOfWork.lessonPlanRepository.Update(lessonPlan); await _unitOfWork.CommitAsync(); return(true); } LessonPlan newLessonPlan = LessonPlan.CreateInstance(null, message.Level, message.SessionId, message.IsActive, message.Description); await _unitOfWork.lessonPlanRepository.AddAsync(newLessonPlan); await _unitOfWork.CommitAsync(); return(true); } catch (Exception) { _unitOfWork.Dispose(); return(false); } }
public async Task <IActionResult> EditLessonPlan(Guid?classId, DateTime?date) { var lessonPlan = await _unitOfWork.LessonPlans.GetOneAsync(x => x.IsActive && x.ClassId == classId && x.Date == date); var model = new LessonPlanViewModel(); if (lessonPlan != null) { model = LessonPlan.Init(lessonPlan); } else { model.Date = date.Value; } var sundayDateOfWeek = model.Date.AddDays(7 - (int)model.Date.DayOfWeek); LessonPlanWeakly weeklyLessonPlan = await _unitOfWork.LessonPlanWeaklies.GetOneAsync(x => x.IsActive && x.ClassId == classId && x.WeekDateSunday == sundayDateOfWeek); if (weeklyLessonPlan != null) { model.WeeklyTheme = weeklyLessonPlan.Theme; model.LessonPlanWeeklyId = weeklyLessonPlan.Id; } return(View(model)); }
public ActionResult <object> Approve([FromBody] LessonPlan level) { try { Init(); StringBuilder sbError = new StringBuilder(""); if (!ModelState.IsValid) { Response.StatusCode = 400; return((string)"Failed getting level id"); } else { var isSaved = _levelService.ApproveLessonPlan((Guid)level.LessonPlanId, ref sbError); if (isSaved == null) { Response.StatusCode = 400; return((string)"level save failed " + sbError.ToString()); } else { return(Ok(isSaved)); } } } catch (Exception er) { return(Error(er)); } }
public LessonPlan CreateLessonPLan(LessonPlanCreationDTO createDTO) { LessonPlan newLesson = new LessonPlan() { LessonPlanId = CreateId(5), Title = createDTO.name, CompleteLessonPlanURL = createDTO.CompleteDocumentURL, OutlineURl = createDTO.DocumentOutlineURL, ImageURL = createDTO.DocumentOutlinePicture }; while (Data.Lessonplans.Find(newLesson.LessonPlanId) != null) { newLesson.LessonPlanId = newLesson.LessonPlanId * 10; } Data.Database.OpenConnection(); try { Data.Add(newLesson); Data.Database.ExecuteSqlCommand("SET IDENTITY_INSERT dbo.Lessonplans ON"); Data.SaveChanges(); Data.Database.ExecuteSqlCommand("SET IDENTITY_INSERT dbo.Poems OFF"); } catch { return(null); } finally { Data.Database.CloseConnection(); } return(newLesson); }
public void Seed(ModelBuilder modelBuilder) { var userSysAdmin = User.CreateInstance(DefaultData.SysAdminId, "Ali", "Jahanbin", DefaultData.SysAdminPassword, "*****@*****.**", DefaultData.SysAdminUsername, UserRoleEnum.SysAdmin, "09224957626", LevelEnum.Intermediate, true, string.Empty); var userTeacher = User.CreateInstance(DefaultData.TeacherUserId, "Ali", "Jahanbin", DefaultData.TeacherPassword, "*****@*****.**", DefaultData.TeacherUsername, UserRoleEnum.Teacher, "09224957626", LevelEnum.Advanced, true, string.Empty); var userStudent = User.CreateInstance(DefaultData.StudentId, "Ali", "Jahanbin", DefaultData.SysAdminPassword, "*****@*****.**", DefaultData.SysAdminUsername, UserRoleEnum.Student, "09224957626", LevelEnum.Begginer, true, string.Empty); var defaultInstitute = Institute.CreateInstance(DefaultData.InstituteId, "TestInstitute", Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), true, Guid.NewGuid().ToString()); var defaultField = Field.CreateInstance(DefaultData.FieldId, "DefaultField", defaultInstitute.Id, true, string.Empty); var defaultCourse = Course.CreateInstance(DefaultData.CourseId, "DefaultCourse", AgeRangeEnum.Adults, defaultField.Id, true, string.Empty); var defaultTerm = Term.CreateInstance(DefaultData.TermId, "DefaultTerm", defaultCourse.Id, true, string.Empty); var defaultLessonPlan = LessonPlan.CreateInstance(DefaultData.LessonPlanId, LevelEnum.Begginer, DefaultData.SessionId, true, string.Empty); var defaultSession = Session.CreateInstance(DefaultData.SessionId, "DefaultSession", defaultLessonPlan.Id, defaultTerm.Id, true, string.Empty); var defaultPost = Post.CreateInstance(DefaultData.PostId, "DefaultPost", 1, ContentTypeEnum.Text, "Sample Content", defaultLessonPlan.Id, true, string.Empty); modelBuilder.Entity <Institute>().HasData(defaultInstitute); modelBuilder.Entity <Field>().HasData(defaultField); modelBuilder.Entity <Course>().HasData(defaultCourse); modelBuilder.Entity <Term>().HasData(defaultTerm); modelBuilder.Entity <LessonPlan>().HasData(defaultLessonPlan); modelBuilder.Entity <Session>().HasData(defaultSession); modelBuilder.Entity <Post>().HasData(defaultPost); modelBuilder.Entity <User>().HasData(userSysAdmin, userTeacher, userStudent); }
public UpdateLessonPlanResponse Update(UpdateLessonPlanRequest request) { try { request.Validate(); var lessonPlan = LessonPlan.CreateInstance(request.Id, (LevelEnum)request.Level, request.SessionId, request.IsActive, request.Description); this._unitOfWork.lessonPlanRepository.Update(lessonPlan); this._unitOfWork.Commit(); _busControl.Publish <RegisterLessonPlanEvent>(new RegisterLessonPlanEvent() { Description = "Updated in CourseManagement module", Id = lessonPlan.Id, IsActive = lessonPlan.IsActive, Level = (short)lessonPlan.Level, CreateDate = lessonPlan.CreateDate, ModifiedDate = lessonPlan.ModifyDate, IsDeleted = lessonPlan.IsDeleted, SessionId = lessonPlan.SessionId }); return(new UpdateLessonPlanResponse(true, "به روز رسانی با موفقیت انجام شد")); } catch (BusinessException e) { this._logger.Warning("Course Management-LessonPlan Service-Update LessonPlan ", e.Message); return(new UpdateLessonPlanResponse(false, "به روز رسانی با مشکل مواجه شد.", e.Message.ToString())); } catch (Exception e) { this._logger.Error("Course Management-LessonPlan Service-Update LessonPlan ", e.Message); return(new UpdateLessonPlanResponse(false, "به روز رسانی با مشکل مواجه شد.", e.Message.ToString())); } }
private Guid Update(LessonPlan lessonPlan, ref StringBuilder sbError) { bool dbFlag = false; var lessonPlanObj = _uofRepository.LessonPlanRepository.GetByLessonPlanID((Guid)lessonPlan.LessonPlanId, ref dbFlag); if (lessonPlanObj != null) { sbError.Append("Lesson Pla does not exist"); return(Guid.Empty); } // check if lesson plan exist for that date range var allLessonPlans = _uofRepository.LessonPlanRepository.GetListLessonPlansByTeacherClassSubjectID(lessonPlan.TeacherClassSubjectId, ref dbFlag); if (allLessonPlans == null) { var isRangeExist = allLessonPlans.Where(c => c.DateStart >= lessonPlan.DateStart && c.DateEnd <= lessonPlan.DateEnd && c.LessonPlanId != (Guid)lessonPlan.LessonPlanId).FirstOrDefault(); if (isRangeExist != null) { sbError.Append("There is a lesson plan for that date already"); return(Guid.Empty); } } var setting = _uofRepository.SettingRepository.GetSettingBySchoolID(_user.SchoolID, ref dbFlag); if (setting != null) { sbError.Append("Failed getting setting"); return(Guid.Empty); } if (DateTime.Now.Subtract(lessonPlan.CreatedDate).Days > setting.LessonPlanNotEditedAfterDaysOfCreation) { sbError.Append("Record can has been locked for updates/edits "); return(Guid.Empty); } if (lessonPlan.ApprovedByID != null) { sbError.Append("Record has been approved and can no longer be edited "); return(Guid.Empty); } var save = _uofRepository.LessonPlanRepository.Save(lessonPlan, _user.Username, ref dbFlag); if (save == null) { sbError.Append("Error updating lesson plan"); return(Guid.Empty); } return((Guid)save.LessonPlanId); }
public async Task <JsonResult> LessonPlansJson(Guid?classId) { var lessonPlansForClass = await _unitOfWork.LessonPlans.GetAsync(x => x.IsActive && x.ClassId == classId); var result = LessonPlan.ToJson(lessonPlansForClass); var weeklyLessonPlan = await _unitOfWork.LessonPlanWeaklies.GetAsync(x => x.IsActive && x.ClassId == classId); result.AddRange(LessonPlanWeakly.ToJson(weeklyLessonPlan)); return(Json(result)); }
private LessonPlanDTO GetDTOFromLessonPlan(LessonPlan lessonPlan) { return(new LessonPlanDTO() { LessonID = lessonPlan.Id, StudentID = lessonPlan.StudentID, StartDate = lessonPlan.StartDate, EndDate = lessonPlan.EndDate }); }
public void IsValid_EndDateNoStartDateNotValid() { //Arrange var lp = new LessonPlan() { StudentID = 1, EndDate = DateTime.Now }; //Act/Assert Assert.False(lp.IsValid()); }
public void IsValid_MissingStudentIDNotValid() { //Arrange var lp = new LessonPlan() { StudentID = 0 }; //Act/Assert Assert.False(lp.IsValid()); }
public void Duration_ReturnsDuration() { //Arrange/Act var lp = new LessonPlan() { StudentID = 1, StartDate = DateTime.Now, EndDate = DateTime.Now.AddMinutes(10) }; //Assert Assert.Equal(10, lp.Duration); }
public void Duration_IsNullIfMissingEndDate() { //Arrange/Act var lp = new LessonPlan() { StudentID = 1, StartDate = DateTime.Now }; //Assert Assert.Null(lp.Duration); }
public void IsValid_ValidObjectPassesValidation() { //Arrange var lp = new LessonPlan() { StudentID = 1, StartDate = DateTime.Now, EndDate = DateTime.Now.AddMinutes(10) }; //Act/Assert Assert.True(lp.IsValid()); }
public void IsValid_EndDateBeforeStartDateNotValid() { //Arrange var lp = new LessonPlan() { StudentID = 1, EndDate = DateTime.Now, StartDate = DateTime.Now.AddMinutes(10) }; //Act/Assert Assert.False(lp.IsValid()); }
private List <Link> BuildLessonPlanLinks(LessonPlan lessonPlan) { List <Link> links = new List <Link>(); //Self links.Add(new Link(Url.Link("GetLessonPlan", new { Id = lessonPlan.Id }), "self", "GET")); //Assignments links.Add(new Link(Url.Link("AssignmentsForLesson", new { lessonId = lessonPlan.Id }), "assignments", "GET")); return(links); }
public async Task <ActionResult> SaveLesson([FromBody] LessonPlanCreationDTO creationDTO) { LessonPlan lesson = LessonPlanCreation.SaveLessonPLan(creationDTO); if (lesson == null) { return(BadRequest()); } else { return(Ok(lesson)); } }
public bool CreateLessonPlan(LessonPlanCreate model) { using (var ctx = new ApplicationDbContext()) { var newLessonPlan = new LessonPlan() { CourseId = model.CourseId, //LessonPlanId = model.LessonPlanId, LessonPlanName = model.LessonPlanName }; ctx.LessonPlans.Add(newLessonPlan); return(ctx.SaveChanges() > 0); } }
public bool ConnectWriting(LessonPlan lesson, int writing) { try { Data.Add(new LessonPlan_WritingAssignment() { LessonPlanId = lesson.LessonPlanId, WritingAssignmentId = writing }); } catch { return(false); } return(true); }
public static LessonPlanDto Convert(this LessonPlan source) { if (source == null) { return(null); } return(new LessonPlanDto { Id = source.Id, Level = source.Level, LevelCaption = source.Level.GetDescription(), IsActive = source.IsActive, SessionId = source.SessionId }); }
public bool ConnectPoem(LessonPlan lesson, int poemId) { try { Data.Add(new LessonPlan_Poem { LessonPlanId = lesson.LessonPlanId, PoemId = poemId }); } catch { return(false); } return(true); }
public bool ConnectArt(LessonPlan lesson, int art) { try { Data.Add(new LessonPlan_ArtPiece() { ArtPieceId = art, LessonPlanId = lesson.LessonPlanId }); } catch { return(false); } return(true); }
public async Task <JsonResult> EditLessonPlan(LessonPlanViewModel model) { //Update weekly theme var sundayDateOfWeek = model.Date.AddDays(7 - (int)model.Date.DayOfWeek); LessonPlanWeakly weeklyLessonPlan = await _unitOfWork.LessonPlanWeaklies.GetOneAsync(x => x.IsActive && x.Id == model.LessonPlanWeeklyId); if (weeklyLessonPlan != null) { weeklyLessonPlan.Theme = model.WeeklyTheme; _unitOfWork.LessonPlanWeaklies.Update(weeklyLessonPlan); } else { if (String.IsNullOrEmpty(model.WeeklyTheme) == false) { weeklyLessonPlan = LessonPlanWeakly.Create(model, sundayDateOfWeek, _userId); await _unitOfWork.LessonPlanWeaklies.Insert(weeklyLessonPlan); } } //Update daily theme if (model.LessonPlanId == null) { if (String.IsNullOrEmpty(model.Theme) == false) { var lessonPlan = LessonPlan.Create(model, _userId); await _unitOfWork.LessonPlans.Insert(lessonPlan); } } else { var lessonPlan = await _unitOfWork.LessonPlans.GetOneAsync(x => x.IsActive && x.Id == model.LessonPlanId); lessonPlan.Update(model); _unitOfWork.LessonPlans.Update(lessonPlan); } var result = await _unitOfWork.SaveAsync(); if (result.Succeeded) { return(Json(new JsonMessage { Color = "#ff6849", Message = "Lesson plan saved", Header = "Success", Icon = "success", AdditionalData = model })); } return(Json(new JsonMessage { Color = "#ff6849", Message = "Error", Header = "Success", Icon = "error", AdditionalData = model })); }
private Boolean TimeValidation(LessonPlan lessonPlan) { if (lessonPlan.startTime >= lessonPlan.stopTime) { ModelState.AddModelError("", "Course duration is 0"); return(false); } foreach (LessonPlan existingLesson in _context.LessonPlan) { if (!(existingLesson.startTime >= lessonPlan.stopTime || existingLesson.stopTime <= lessonPlan.startTime) && existingLesson.dayId == lessonPlan.dayId && existingLesson.ClassRoomId == lessonPlan.ClassRoomId) { return(false); } Console.WriteLine(existingLesson.startTime); } return(true); }
protected LessonPlanViewData(LessonPlan announcement) : base(announcement) { StartDate = announcement.StartDate; EndDate = announcement.EndDate; ClassId = announcement.ClassRef; ClassName = announcement.ClassName; FullClassName = announcement.FullClassName; HideFromStudents = !announcement.VisibleForStudent; LpGalleryCategoryId = announcement.LpGalleryCategoryRef; PersonId = announcement.PrimaryTeacherRef; PersonName = announcement.PrimaryTeacherName; PersonGender = announcement.PrimaryTeacherGender; InGallery = announcement.InGallery; GalleryOwnerRef = announcement.GalleryOwnerRef; CategoryName = announcement.CategoryName; }