public void EditNote(SolutionModel model)
 {
     var query = db.Rozwiązania.Where(x => x.IdRozwiązania == model.SolutionId).FirstOrDefault();
     query.Komentarz = model.Comment;
     query.Ocena = model.Note;
     db.SaveChanges();
 }
 public FileContentResult Download(int SolutionId)
 {
     CourseServices cs = new CourseServices();
     SolutionModel model = new SolutionModel();
     model = cs.GetSolution(SolutionId);
     FileServices fs = new FileServices();
     string ContentType = fs.GetContentType(model.Extension);
     return File(model.Solution,ContentType,model.FileName);
 }
        public ActionResult InsertSolution(SolutionModel model,HttpPostedFileBase upload)
        {
            CourseServices cs = new CourseServices();
            UserServices us = new UserServices();
            HttpCookie loggedStudent = Request.Cookies["LoggedUser"];
            model.Student = us.GetStudent(loggedStudent.Values.Get("Login"));
            model.StudentId = model.Student.IdUcznia;
            model.FileName = upload.FileName;
            using (var reader = new System.IO.BinaryReader(upload.InputStream))
            {
                model.Solution = reader.ReadBytes(upload.ContentLength);
            }
            cs.NewSolution(model);

            return RedirectToAction("ManageCourses","Student");
        }
 public void SolutionEdit(SolutionModel model)
 {
     var solutionToEdit = db.Rozwiązania.Where(x => x.IdRozwiązania == model.SolutionId).FirstOrDefault();
     if(!(solutionToEdit.Ocena.HasValue && solutionToEdit.Komentarz != String.Empty))
     {
         solutionToEdit.TreśćRozwiązania = model.Solution;
         solutionToEdit.DataWstawienia = DateTime.Now;
         db.SaveChanges();
     }
 }
 public void NewSolution(SolutionModel model)
 {
     if (db.Rozwiązania.Count() > 0)
     {
         db.Rozwiązania.Add(new Rozwiązania()
         {
             IdRozwiązania = db.Rozwiązania.Max(x => x.IdRozwiązania) + 1,
             IdUcznia = model.StudentId,
             IdZadania = model.TaskId,
             TreśćRozwiązania = model.Solution,
             DataWstawienia = DateTime.Now,
             NazwaPliku = model.FileName,
             Rozszerzenie = model.FileName.Split(new Char[] { '.' }).Last()
         });
     }
     else
     {
         db.Rozwiązania.Add(new Rozwiązania()
         {
             IdRozwiązania = 1,
             IdUcznia = model.StudentId,
             IdZadania = model.TaskId,
             TreśćRozwiązania = model.Solution,
             DataWstawienia = DateTime.Now,
             NazwaPliku = model.FileName,
             Rozszerzenie = model.FileName.Split(new Char[] { '.' }).Last()
         });
     }
     db.SaveChanges();
 }
 public SolutionModel GetSolution(int TaskId,StudentModel model)
 {
     SolutionModel solution = new SolutionModel();
     var query = db.Rozwiązania.Where(x => x.IdZadania == TaskId && x.IdUcznia == model.IdUcznia).FirstOrDefault();
     solution.Student = model;
     solution.StudentId = model.IdUcznia;
     solution.Note = query.Ocena;
     solution.Notes = GetPossibleNotes();
     solution.SolutionId = query.IdRozwiązania;
     solution.Solution = query.TreśćRozwiązania;
     solution.FileName = query.NazwaPliku;
     solution.Extension = query.Rozszerzenie;
     solution.Comment = query.Komentarz;
     return solution;
 }
 public SolutionModel GetSolution(int SolutionId)
 {
     var query = db.Rozwiązania.Where(x => x.IdRozwiązania == SolutionId).FirstOrDefault();
     UserServices us = new UserServices();
     SolutionModel model = new SolutionModel{
         SolutionId = query.IdRozwiązania,
         StudentId = query.IdUcznia,
         TaskId = query.IdZadania,
         Solution = query.TreśćRozwiązania,
         FileName = query.NazwaPliku,
         Extension = query.Rozszerzenie,
         Comment = query.Komentarz,
         Note = query.Ocena,
         Student = us.GetStudent(query.IdUcznia),
         Notes = GetPossibleNotes()
     };
     return model;
 }
 public ActionResult NoteEdit(int SolutionId)
 {
     SolutionModel solution = new SolutionModel();
     CourseServices service = new CourseServices();
     solution = service.GetSolution(SolutionId);
     return View(solution);
 }
 public ActionResult StudentSolution(int SolutionId)
 {
     SolutionModel model = new SolutionModel();
     CourseServices service = new CourseServices();
     model = service.GetSolution(SolutionId);
     return View(model);
 }
 public ActionResult NoteEdit(SolutionModel model)
 {
     CourseServices service = new CourseServices();
     service.EditNote(model);
     return RedirectToAction("TaskSolutions", new { TaskId = model.TaskId });
 }
 public ActionResult StudentSolution(int TaskId)
 {
     CourseServices cs = new CourseServices();
     UserServices us = new UserServices();
     HttpCookie cookie = Request.Cookies.Get("LoggedUser");
     cookie.Values.Get("Name");
     cookie.Values.Get("Surname");
     cookie.Values.Get("Login");
     StudentModel student = new StudentModel();
     student = us.GetStudent(cookie.Values.Get("Login"));
     SolutionModel solution = new SolutionModel();
     solution = cs.GetSolution(TaskId, student);
     return View(solution);
 }