public IActionResult ShowText(string name) { Lection l = lS.getAuthorByLName(name); ViewBag.usName = uS.getUserNameById(l.UserId); return(View("ShowLection", lS.getLectionByName(name))); }
public void UpdateLection(LectionId lectionId, Lection lection) { if (lection == null) { _logger.Log(string.Format("You sent a null lection:\n {0}", nameof(NullReferenceException))); } string sql = "Update lection Set " + "lectorId = @lectorId, lectionName = @lectionName, lectionData = @lectionData " + "Where lectionId = @lectionId"; try { using (var sqlConnection = new SqlConnection(_connectionString)) { sqlConnection.Open(); using (SqlCommand command = new SqlCommand(sql, sqlConnection)) { command.Parameters.AddWithValue("@lectionId", lectionId.Id); command.Parameters.AddWithValue("@lectorId", lection.lector.lectorId.Id); command.Parameters.AddWithValue("@lectionName", lection.lectionName); command.Parameters.AddWithValue("@lectionData", lection.lectionData); command.ExecuteNonQuery(); } } } catch (SqlException sqlException) { _logger.Log(string.Format("You have an error with sql:\n {0}", sqlException)); } catch (ArgumentNullException argException) { _logger.Log(string.Format("You have a null argument:\n {0}", argException)); } }
public IActionResult getStars(string star, string name) { Lection l = lS.getAuthorByLName(name); if (!lkS.checkExistLike(uS.getUserbyName(User.Identity.Name).Id, lS.getLectionByName(name).Id)) { Likes like = new Likes(); like.userStar = Convert.ToInt32(star); like.LectionId = lS.getLectionByName(name).Id; like.UserId = uS.getUserbyName(User.Identity.Name).Id; lkS.addLike(like); lkS.Save(); lS.likeLection(lS.getLectionByName(name).Id, lkS.getNowRating(lS.getLectionByName(name).Id)); lS.Save(); User user = uS.getUserById(l.UserId); user.ammountStars++; uS.plusStar(user); uS.Save(); } else { Likes like = lkS.getLikeById(uS.getUserbyName(User.Identity.Name).Id, lS.getLectionByName(name).Id); like.userStar = Convert.ToInt32(star); lkS.updateLike(like); lkS.Save(); lS.likeLection(lS.getLectionByName(name).Id, lkS.getNowRating(lS.getLectionByName(name).Id)); lS.Save(); } ViewBag.usName = uS.getUserNameById(l.UserId); return(View("ShowLection", lS.getLectionByName(name))); }
public void CreateLection(LectionDTO lection) { Lection newLection = map.Map <Lection>(lection); db.Lections.Add(newLection); db.Save(); }
public IActionResult SimilarLections(int id) { Lection lection = _db.Lections.FirstOrDefault(l => l.Id == id); if (lection == null) { return(NotFound()); } List <double> coeffsList = new double[_db.Lections.Count()].ToList(); List <Lection> lections = _db.Lections.Where(l => l.Id != id).ToList(); foreach (Lection l in lections) { coeffsList[l.Id - 1] = Measures.CorrelationDistance(lection, l) * Measures.EqualValues(lection, l); } List <LectionCoeff> lc = new List <LectionCoeff>(); for (int i = 0; i < coeffsList.Count; i++) { if (coeffsList[i] > 0) { lc.Add(new LectionCoeff { Id = i + 1, Coeff = coeffsList[i] }); } } return(View(lc.OrderByDescending(c => c.Coeff).ToList())); }
public void likeLection(int idLection, double nowStar) { Lection lection = unitOfWork.Lections.Get(idLection); lection.stars = nowStar; unitOfWork.Lections.Update(lection); }
public void AllItemsTest() { //_context.Lections.RemoveRange(_context.Lections); var repo = new LectionsRepository(_context); Assert.AreEqual(_context.Lections.Count(), repo.AllItems.Count()); var item1 = new Lection { Day = DayOfWeek.Tuesday, Start = new DateTime(1976, 1, 1, 9, 35, 0), Finish = new DateTime(1976, 1, 1, 10, 55, 0) }; repo.AddItem(item1); var item2 = new Lection { Day = DayOfWeek.Tuesday, Start = new DateTime(1976, 1, 1, 11, 20, 0), Finish = new DateTime(1976, 1, 1, 12, 40, 0) }; repo.AddItem(item2); Assert.AreEqual(_context.Lections.Count(), repo.AllItems.Count()); _context.Lections.Remove(item1); _context.Lections.Remove(item2); }
public LectionDTO GetByID(int lectionID) { Lection lection = db.Lections.Get(lectionID); LectionDTO result = map.Map <LectionDTO>(lection); return(result); }
public async Task <ActionResult <Lection> > AddLection([FromBody] Lection lection) { await _context.AddAsync(lection); await _context.SaveChangesAsync(); return(NoContent()); }
public void EditLection(LectionDTO lection) { Lection editedLection = db.Lections.Get(lection.LectionID); map.Map(lection, editedLection); db.Lections.Update(editedLection); db.Save(); }
public void AddLection(Lection lection) { if (lection == null) { _logger.Log("You sent empty lection in AddLection"); throw new NullReferenceException("You sent empty lection in AddLection"); } _lectionsDal.InsertLection(lection); }
public Lection GetLecionById(LectionId lectionId) { var result = new Lection(); result.lector = new Lector(); string sql = string.Format("SELECT L.LectionId, L.LectionName, L.LectionData, " + "LRS.FirstName, LRS.SecondName, LRS.Email, LRS.LectorId " + "From Lection, Lectors " + "INNER JOIN Lection L ON L.LectionId = L.LectionId " + "INNER JOIN Lectors LRS ON L.LectorId = LRS.LectorId " + "Where L.LectionId = @LectionId "); try { using (var sqlConnection = new SqlConnection(_connectionString)) { sqlConnection.Open(); using (SqlCommand command = new SqlCommand(sql, sqlConnection)) { command.Parameters.AddWithValue("@LectionId", lectionId.Id); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { if (!Int32.TryParse(reader["LectionId"].ToString(), out result.lectionId.Id)) { //TODO Add exception Name and Logging throw new FormatException(); } if (!Int32.TryParse(reader["LectorId"].ToString(), out result.lector.lectorId.Id)) { //TODO Add exception Name and Logging throw new FormatException(); } result.lector.firstName = (string)reader["FirstName"]; result.lector.secondName = (string)reader["SecondName"]; result.lector.email = (string)reader["Email"]; result.lectionName = (string)reader["lectionName"]; result.lectionData = (DateTime)reader["lectionData"]; } } } return(result); } catch (SqlException sqlException) { _logger.Log(string.Format("You have an error with sql:\n {0}", sqlException)); return(null); } catch (ArgumentNullException argException) { _logger.Log(string.Format("You have a null argument:\n {0}", argException)); return(null); } }
public BLection(Lection lection) { var config = new MapperConfiguration(cfg => cfg.CreateMap <Lection, BLection>()); Mapper mapper = new Mapper(config); BLection tmpBLection = mapper.Map <BLection>(lection); this.GroupId = tmpBLection.GroupId; this.LectorId = tmpBLection.LectorId; this.StartedOn = tmpBLection.StartedOn; }
public IActionResult SaveEditLection([FromForm] Lection l) { Lection lection = lS.getLectionByName(l.name); lection.smallDescription = l.smallDescription; lection.text = l.text; lection.dateUpdate = DateTime.Now; lS.updateUserLection(lection); lS.Save(); return(View("Lections", lS.getAllLections())); }
public IActionResult Delete(int id) { Lection lection = _db.Lections.FirstOrDefault(l => l.Id == id); if (lection == null) { return(NotFound()); } _db.Lections.Remove(lection); _db.SaveChanges(); return(RedirectToAction("Index")); }
public IActionResult Index(Lection newLection) { Lection lection = _db.Lections.FirstOrDefault(l => l.Id == newLection.Id); if (lection != null) { return(Conflict()); } _db.Lections.Add(newLection); _db.SaveChanges(); return(RedirectToAction("Index")); }
public IActionResult AdminDeleteLection(string name) { Lection lection = lS.getLectionByName(name); User user = uS.getUserById(lection.UserId); user.ammountLections--; uS.updateProfile(user); uS.Save(); lS.deleteUserLection(lS.getLectionByName(name)); lS.Save(); return(View("Lections", lS.getAllLections())); }
// GET: Moderator/ManageLections/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Lection lection = db.Lection.Find(id); if (lection == null) { return(HttpNotFound()); } return(View(lection)); }
static void Main(string[] args) { University univer = new University(); Teacher histTeach = new Teacher("Eugeniy Ponasenkov", LectionType.History); Teacher engTeach = new Teacher("Aleksandr Pushkin", LectionType.Literature); Teacher mathTeach = new Teacher("Isaak Newton", LectionType.Math); Teacher physTeach = new Teacher("Albert Einstein", LectionType.Physics); TechStudent tst1 = new TechStudent("Sergei Tishkov"); TechStudent tst2 = new TechStudent("Aleksandr Maisak"); TechStudent tst3 = new TechStudent("Anton Akulenok"); HumanitarianStudent hst1 = new HumanitarianStudent("Anton Chekhov"); HumanitarianStudent hst2 = new HumanitarianStudent("Leo Tolstoi"); HumanitarianStudent hst3 = new HumanitarianStudent("Feodor Dostoevsky"); univer.AddPersons(histTeach, engTeach, mathTeach, physTeach, tst1, tst2, tst3, hst1, hst2, hst3); univer.AddPerson(tst1); Console.WriteLine("\n\n********************************\n\n"); Console.WriteLine("End of the first test. Press any key to enter the second test."); Console.ReadKey(true); Console.Clear(); var fridaySecondLection = Lection.CreateLection(LectionType.Math, DayOfWeek.Friday, 2, univer, mathTeach); univer.AddLection(fridaySecondLection); univer.CheckDayAndLection(DayOfWeek.Friday, 2); Console.WriteLine("\n\n********************************\n\n"); Console.WriteLine("End of the second test. Press any key to enter the third test."); Console.ReadKey(true); Console.Clear(); var mondayFirstLection = Lection.CreateLection(LectionType.Literature, DayOfWeek.Monday, 1, univer, engTeach); var tuedaySecondLection = Lection.CreateLection(LectionType.Math, DayOfWeek.Tuesday, 2, univer, mathTeach); var wednesdayFirstLection = Lection.CreateLection(LectionType.Physics, DayOfWeek.Wednesday, 1, univer, physTeach); var thursdayThirdLection = Lection.CreateLection(LectionType.Physics, DayOfWeek.Thursday, 3, univer, physTeach); var fridaySecondLection_Redefine = Lection.CreateLection(LectionType.Literature, DayOfWeek.Friday, 2, univer, engTeach); var saturdayFirstLEction = Lection.CreateLection(LectionType.Math, DayOfWeek.Saturday, 1, univer, mathTeach); var saturdayThirdLection = Lection.CreateLection(LectionType.History, DayOfWeek.Saturday, 3, univer, histTeach); univer.AddLections(mondayFirstLection, tuedaySecondLection, wednesdayFirstLection, thursdayThirdLection, fridaySecondLection_Redefine, saturdayFirstLEction, saturdayThirdLection); univer.CheckWholeWeek(); }
public void AddLection_Lection_MethodWasCalled() { var lection = new Lection(); var mockConfig = new MockConfig(""); var mockLogger = new MockLogger(); var studentsDalStab = new Mock <IStudentsDal>(); var lectorsDalStab = new Mock <ILectorsDal>(); var lectionsDalStab = new Mock <ILectionsDal>(); var journalDalStab = new Mock <IStudentsAndLectionsDal>(); var logic = new LearningBL(mockConfig, mockLogger, studentsDalStab.Object, journalDalStab.Object, lectionsDalStab.Object, lectorsDalStab.Object); lectionsDalStab.Setup(s => s.InsertLection(lection)).Verifiable(); logic.AddLection(lection); lectionsDalStab.Verify(c => c.InsertLection(lection), Times.Once); }
public ActionResult DeleteConfirmed(int id) { Lection lection = db.Lection.Find(id); FileOperations.DeleteIfExist(Server, lection.LectionPath); var task = db.ELTask.Where(x => x.LectionId == lection.LectionId && x.AuthorId == 1); if (task.Count() > 0) { db.ELTask.Remove(task.First()); } db.Lection.Remove(lection); db.SaveChanges(); return(RedirectToAction("Index")); }
// GET: Moderator/ManageLections/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Lection lection = db.Lection.Find(id); if (lection == null) { return(HttpNotFound()); } ViewBag.OwnerId = new SelectList(db.User, "UserId", "UserId", lection.OwnerId); ViewBag.LectionType = new SelectList(db.LectionGroup, "LectionGroupId", "Name", lection.LectionType); return(View(lection)); }
public async Task <int> CreateAsync(string title, string description, int courseId, string url, string userId) { var lection = new Lection { Title = title, Description = description, CourseId = courseId, Url = url, UserId = userId, }; await this.lectionsRepository.AddAsync(lection); await this.lectionsRepository.SaveChangesAsync(); return(lection.Id); }
public ActionResult Edit([Bind(Include = "LectionId,Name,OwnerId,LectionType,Description,Editable,ExportOwner,Complexity,ComplexityOrder,LectionPath")] Lection lection, HttpPostedFileBase file) { if (ModelState.IsValid) { var path = FileOperations.SaveFile(file, Server, pathToSave, extensions); if (!string.IsNullOrWhiteSpace(path)) { FileOperations.DeleteIfExist(Server, lection.LectionPath); lection.LectionPath = path; } lection.LectionText = new byte[] { }; db.Entry(lection).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.OwnerId = new SelectList(db.User, "UserId", "UserId", lection.OwnerId); ViewBag.LectionType = new SelectList(db.LectionGroup, "LectionGroupId", "Name", lection.LectionType); return(View(lection)); }
public ActionResult Create([Bind(Include = "LectionId,Name,OwnerId,LectionType,Description,Editable,ExportOwner,Complexity,ComplexityOrder,LectionPath")] Lection lection, HttpPostedFileBase file) { if (ModelState.IsValid) { lection.LectionPath = FileOperations.SaveFile(file, Server, pathToSave, extensions); lection.LectionText = new byte[] { }; ELTask task = new ELTask() { AuthorId = 1, Difficult = lection.Complexity, Group = "Lection", Lection = lection, Name = lection.Name, Description = "Прочитайте зазначену лекцію" }; db.ELTask.Add(task); db.Lection.Add(lection); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.OwnerId = new SelectList(db.User, "UserId", "UserId", lection.OwnerId); ViewBag.LectionType = new SelectList(db.LectionGroup, "LectionGroupId", "Name", lection.LectionType); return(View(lection)); }
public IEnumerable <LectionDTO> GetActiveByDate(int userID, DateTime date) { Student student = db.Students.Find(x => x.UserID == userID).FirstOrDefault(); List <Lection> activeLections = new List <Lection>(); IEnumerable <Course> activeCourses = student.Courses.Where(x => x.StartDate.AddDays(x.DurationInDays).Date >= date.Date); foreach (Course item in activeCourses) { foreach (Lection lec in item.Lections) { Lection lect = db.ScheduledEvents.Find(x => x.Course.CourseID == item.CourseID && x.Lection.LectionID == lec.LectionID && x.Date >= date).FirstOrDefault().Lection; if (lect != null) { activeLections.Add(lect); } } } List <LectionDTO> result = map.Map <List <LectionDTO> >(activeLections); return(result); }
public void AddItemTest() { //_context.Lections.RemoveRange(_context.Lections); var repo = new LectionsRepository(_context); var item = new Lection { Day = DayOfWeek.Tuesday, Start = new DateTime(1976, 1, 1, 8, 0, 0), Finish = new DateTime(1976, 1, 1, 9, 20, 0) }; repo.AddItem(item); var newitem = _context.Lections.FirstOrDefault(x => x.Day == item.Day && x.Start == item.Start && x.Finish == item.Finish); Assert.AreEqual(item.Day, newitem.Day); Assert.AreEqual(item.Start, newitem.Start); Assert.AreEqual(item.Finish, newitem.Finish); _context.Lections.Remove(item); }
public IActionResult SaveLection([FromForm] Lection lection) { if (lS.checkExistLectionName(lection.name)) { lection.UserId = uS.getUserIdByName(User.Identity.Name); lection.dateCreate = DateTime.Now; lection.dateUpdate = DateTime.Now; lS.createUserLection(lection); lS.Save(); User user = uS.getUserbyName(User.Identity.Name); user.ammountLections++; uS.plusLection(user); uS.Save(); return(View("AllLections", lS.getAllLections())); } else { ViewBag.message = "Lection name exist"; return(View("CreateLection")); } }
public void ChangeItemTest() { //_context.Lections.RemoveRange(_context.Lections); var repo = new LectionsRepository(_context); var item = new Lection { Day = DayOfWeek.Tuesday, Start = new DateTime(1976, 1, 1, 11, 20, 0), Finish = new DateTime(1976, 1, 1, 12, 40, 0) }; repo.AddItem(item); int Id = _context.Lections.FirstOrDefault(x => x.Day == item.Day && x.Start == item.Start && x.Finish == item.Finish).Id; var newitem = repo.GetItem(Id); newitem.Day = DayOfWeek.Saturday; repo.ChangeItem(newitem); Assert.AreEqual(newitem.Day, repo.GetItem(newitem.Id).Day); Assert.AreEqual(newitem.Start, repo.GetItem(newitem.Id).Start); Assert.AreEqual(newitem.Finish, repo.GetItem(newitem.Id).Finish); _context.Lections.Remove(newitem); }
public void AddItemsTest() { //_context.Lections.RemoveRange(_context.Lections); var repo = new LectionsRepository(_context); Lection l1 = new Lection { Day = DayOfWeek.Tuesday, Start = new DateTime(1975, 1, 1, 11, 20, 0), Finish = new DateTime(1975, 1, 1, 12, 40, 0) }; Lection l2 = new Lection { Day = DayOfWeek.Tuesday, Start = new DateTime(1975, 1, 1, 12, 55, 0), Finish = new DateTime(1975, 1, 1, 14, 15, 0) }; repo.AddItems(new Lection[] { l1, l2 }); Lection newlection1 = _context.Lections.FirstOrDefault(x => x.Day == l1.Day && x.Start == l1.Start && x.Finish == l1.Finish); Lection newlection2 = _context.Lections.FirstOrDefault(x => x.Day == l2.Day && x.Start == l2.Start && x.Finish == l2.Finish); Assert.AreEqual(l1.Day, newlection1.Day); Assert.AreEqual(l1.Start, newlection1.Start); Assert.AreEqual(l1.Finish, newlection1.Finish); Assert.AreEqual(l2.Day, newlection2.Day); Assert.AreEqual(l2.Start, newlection2.Start); Assert.AreEqual(l2.Finish, newlection2.Finish); _context.Lections.Remove(l1); _context.Lections.Remove(l2); }