示例#1
0
 /// <summary>
 /// Deletes the homework.
 /// </summary>
 /// <param name="id">The identifier.</param>
 /// <exception cref="CustomException">
 /// </exception>
 public void DeleteHomework(int id)
 {
     try {
         using (var db = new ELearningDatabaseEntities()) {
             //delete the assignements for the homework
             var assignementsToDelete = db.HomeworkAssignements
                                        .Where(a => a.HomeworkId == id)
                                        .ToList();
             foreach (var a in assignementsToDelete)
             {
                 db.HomeworkAssignements.Remove(a);
             }
             db.SaveChanges();
             //delete the homework
             Homeworks hw = db.Homeworks
                            .Where(h => h.HomeworkId == id)
                            .First();
             db.Homeworks.Remove(hw);
             db.SaveChanges();
         }
     }
     catch (ArgumentNullException ane) {
         throw new CustomException(ane.Message);
     }
     catch (InvalidOperationException ex) {
         throw new CustomException(ex.Message);
     }
 }
示例#2
0
        public HttpResponseMessage GetHomeworkById(int id)
        {
            try {
                Homeworks hw = this._homeworkManagement.GetHomeworkById(id);

                if (hw != null)
                {
                    HomeworkDTO dto = new HomeworkDTO();
                    dto.HomeworkAccessSpan  = hw.HomeworkAccessSpan;
                    dto.HomeworkDeadline    = hw.HomeworkDeadline;
                    dto.HomeworkDescription = hw.HomeworkDescription;
                    dto.HomeworkId          = hw.HomeworkId;
                    dto.HomeworkName        = hw.HomeworkName;
                    dto.HomeworkPoints      = hw.HomeworkPoints;
                    dto.HomeworkCode        = hw.HomeworkCode;
                    dto.CourseId            = hw.CourseId;
                    dto.CourseModuleId      = hw.CourseModuleId;
                    dto.OwnerId             = hw.OwnerId;

                    return(Request.CreateResponse <HomeworkDTO>(HttpStatusCode.OK, dto));
                }
                else
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Resource Not Found"));
                }
            }
            catch (Exception) {
                // Log exception code goes here
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Error occured while executing method."));
            }
        }
示例#3
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,Name,Note,Status")] Homeworks homeworks)
        {
            if (id != homeworks.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(homeworks);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!HomeworksExists(homeworks.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(homeworks));
        }
示例#4
0
 /// <summary>
 /// Adds the homework.
 /// </summary>
 /// <param name="hw">The hw.</param>
 /// <exception cref="CustomException"></exception>
 public void AddHomework(Homeworks hw)
 {
     try {
         using (var db = new ELearningDatabaseEntities()) {
             db.Homeworks.Add(hw);
             db.SaveChanges();
         }
     }
     catch (InvalidOperationException ioe) {
         throw new CustomException(ioe.Message);
     }
 }
示例#5
0
 /// <summary>
 /// Edits the homework.
 /// </summary>
 /// <param name="hw">The hw.</param>
 /// <exception cref="CustomException"></exception>
 public void EditHomework(Homeworks hw)
 {
     try {
         using (var db = new ELearningDatabaseEntities()) {
             db.Homeworks.Attach(hw);
             db.Entry(hw).State = System.Data.EntityState.Modified;
             db.SaveChanges();
         }
     }
     catch (InvalidOperationException ex) {
         throw new CustomException(ex.Message);
     }
 }
示例#6
0
        public async Task <IActionResult> Create([Bind("ID,Name,Note,Status")] Homeworks homeworks, int studentId)
        {
            if (ModelState.IsValid)
            {
                var student = _context.Students.Find(studentId);
                homeworks.Students   = student;
                homeworks.CreateTime = DateTime.Now;
                _context.Add(homeworks);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Details", "Students", new { id = studentId }));
            }
            return(View(homeworks));
        }
示例#7
0
        /// <summary>
        /// Gets all group assigned homework.
        /// </summary>
        /// <param name="groupId">The group identifier.</param>
        /// <returns></returns>
        /// <exception cref="CustomException"></exception>
        public List <AssignementDTO> GetAllGroupAssignedHomework(int groupId)
        {
            try {
                using (var db = new ELearningDatabaseEntities()) {
                    List <HomeworkAssignements> ha = db.HomeworkAssignements
                                                     .Where(a => a.GroupId == groupId)
                                                     .ToList();

                    List <AssignementDTO> dto = new List <AssignementDTO>();
                    foreach (var x in ha)
                    {
                        Homeworks hw = db.Homeworks
                                       .Where(h => h.HomeworkId == x.HomeworkId)
                                       .First();
                        string code = "";
                        if (x.CourseId != null && x.CourseId > 0)
                        {
                            code = db.Courses
                                   .Where(c => c.CourseId == x.CourseId)
                                   .Select(c => c.CourdeCode)
                                   .First();
                        }
                        else if (x.CourseModuleId != null && x.CourseModuleId > 0)
                        {
                            code = db.CourseModule
                                   .Where(cm => cm.ModuleId == x.CourseModuleId)
                                   .Select(cm => cm.ModuleName)
                                   .First();
                        }
                        dto.Add(new AssignementDTO {
                            AnswerId            = x.AnswerId,
                            AssignementId       = x.AssignementId,
                            GradeId             = x.GradeId,
                            HomeworkDeadline    = hw.HomeworkDeadline,
                            HomeworkDescription = hw.HomeworkDescription,
                            HomeworkId          = hw.HomeworkId,
                            HomeworkName        = hw.HomeworkName,
                            HomeworkPoints      = hw.HomeworkPoints,
                            HomeworkCode        = hw.HomeworkCode,
                            RecipientId         = groupId,
                            SubjectCode         = code
                        });
                    }
                    return(dto);
                }
            }
            catch (ArgumentNullException ane) {
                throw new CustomException(ane.Message);
            }
        }
 public IActionResult IsHomeworkUnique(Homeworks hw)
 {
     if (_context.Homeworks
         .Include(t => t.TeacherSubjectGroup)
         .Include(t => t.TeacherSubjectGroup.TeacherSubject)
         .Include(t => t.TeacherSubjectGroup.TeacherSubject.Subject)
         .Include(t => t.TeacherSubjectGroup.TeacherSubject.Teacher)
         .Include(t => t.TeacherSubjectGroup.Group)
         .Include(t => t.TeacherSubjectGroup.Group.GroupType)
         .Include(t => t.TeacherSubjectGroup.Group.Grade)
         .Any(t => t.PassDate == hw.PassDate &&
              t.TeacherSubjectGroupId == hw.TeacherSubjectGroupId &&
              t.HomeworkId != hw.HomeworkId))
     {
         return(Json(false));
     }
     return(Json(true));
 }
        public IHttpActionResult AddHomework(AdminHomeWrokDto dto)
        {
            if (context.Homeworks.Any(e => e.ExerciseId == dto.ExerciseId && e.StudentId == dto.StudentId))
            {
                return(BadRequest("To zadanie juz jest przydzielone do tego ucznia!"));
            }
            var homework = new Homeworks()
            {
                StudentId    = dto.StudentId,
                ExerciseId   = dto.ExerciseId,
                TaskDateTime = DateTime.Now.ToString("HH:mm d MMMMM yyyy"),
                IsRead       = false
            };

            context.Homeworks.Add(homework);
            context.SaveChanges();

            return(Ok());
        }
示例#10
0
        private static void GenerateHomeworks(StudentSystemDbContext dbContext)
        {
            var content        = "Task.";
            var allStudentsIds = dbContext.Students.Select(s => s.Id).ToArray();
            var allCoursesIds  = dbContext.Courses.Select(s => s.Id).ToArray();

            for (int i = 1, j = 10; i <= 5; i++, j--)
            {
                var homework = new Homeworks
                {
                    Content   = content + i,
                    StudentId = allStudentsIds[j],
                    CourseId  = allCoursesIds[j]
                };

                dbContext.Homeworks.Add(homework);
            }

            Console.WriteLine("Homeworks are successfully added!");
        }
示例#11
0
        /// <summary>
        /// Gets the view model for a homework.
        /// </summary>
        /// <param name="homework">The homework.</param>
        /// <returns></returns>
        /// <exception cref="CustomException"></exception>
        public HomeworksViewModel GetViewModel(Homeworks homework)
        {
            try {
                HomeworksViewModel hvm = new HomeworksViewModel();
                hvm.HomeworkAccessSpan  = homework.HomeworkAccessSpan;
                hvm.HomeworkDeadline    = homework.HomeworkDeadline;
                hvm.HomeworkDescription = homework.HomeworkDescription;
                hvm.HomeworkId          = homework.HomeworkId;
                hvm.HomeworkName        = homework.HomeworkName;
                hvm.HomeworkPoints      = homework.HomeworkPoints;
                hvm.HomeworkCode        = homework.HomeworkCode;
                hvm.CourseId            = homework.CourseId;
                hvm.CourseModuleId      = homework.CourseModuleId;
                hvm.OwnerId             = homework.OwnerId;

                return(hvm);
            }
            catch (Exception ex) {
                throw new CustomException(ex.Message);
            }
        }
        public async Task <IActionResult> Edit(int id, [Bind("HomeworkId,PassDate,TeacherSubjectGroupId,Homework")] Homeworks homeworks)
        {
            if (id != homeworks.HomeworkId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(homeworks);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!HomeworksExists(homeworks.HomeworkId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["TeacherSubjectGroupId"] = new SelectList(_context.TeacherSubjectGroup
                                                               .Include(t => t.TeacherSubject)
                                                               .Include(t => t.TeacherSubject.Subject)
                                                               .Include(t => t.TeacherSubject.Teacher)
                                                               .Include(t => t.Group)
                                                               .Include(t => t.Group.GroupType)
                                                               .Include(t => t.Group.Grade),
                                                               "TeacherSubjectGroupId",
                                                               "TeacherSubjectGroupName",
                                                               homeworks.TeacherSubjectGroupId);

            return(View(homeworks));
        }
        public async Task <IActionResult> Create([Bind("HomeworkId,PassDate,TeacherSubjectGroupId,Homework")] Homeworks homeworks)
        {
            if (ModelState.IsValid)
            {
                _context.Add(homeworks);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            ViewData["TeacherSubjectGroupId"] = new SelectList(_context.TeacherSubjectGroup
                                                               .Include(t => t.TeacherSubject)
                                                               .Include(t => t.TeacherSubject.Subject)
                                                               .Include(t => t.TeacherSubject.Teacher)
                                                               .Include(t => t.Group)
                                                               .Include(t => t.Group.GroupType)
                                                               .Include(t => t.Group.Grade),
                                                               "TeacherSubjectGroupId",
                                                               "TeacherSubjectGroupName",
                                                               homeworks.TeacherSubjectGroupId);

            return(View(homeworks));
        }
示例#14
0
        public void Edit(string teacher, string name, string start, string end, string newname, string newstart, string newend, string description, string path, UserNode[] nodes)
        {
            Homeworks h = new Homeworks();

            Homework.Homework orig    = h.Homework.Single(hw => hw.Teacher == teacher && hw.Name == name && hw.Start == start.Replace('.', ':') && hw.End == end.Replace('.', ':'));
            Homework.Homework updated = orig;
            updated.Name        = name;
            updated.Start       = start;
            updated.End         = end;
            updated.Path        = path;
            updated.Description = HttpUtility.UrlDecode(description, System.Text.Encoding.Default);
            updated.UserNodes.Clear();
            updated.UserNodes.AddRange(nodes);
            User u = new User();

            u.Authenticate(updated.Teacher, TokenGenerator.ConvertToPlain(updated.Token));
            DriveMapping mapping;
            string       p = Converter.DriveToUNC(updated.Path.Remove(0, 1), updated.Path.Substring(0, 1), out mapping, u);

            u.ImpersonateContained();
            try
            {
                if (!Directory.Exists(p))
                {
                    Directory.CreateDirectory(p);
                }
                if (!Directory.Exists(Path.Combine(p, updated.Name)))
                {
                    Directory.CreateDirectory(Path.Combine(p, updated.Name));
                }
            }
            finally
            {
                u.EndContainedImpersonate();
            }
            h.Update(orig, updated);
        }
示例#15
0
        public HttpResponseMessage UpdateHomework(int id, HomeworkDTO dto)
        {
            try {
                Homeworks hw = new Homeworks();
                hw.HomeworkAccessSpan  = dto.HomeworkAccessSpan;
                hw.HomeworkDeadline    = dto.HomeworkDeadline;
                hw.HomeworkDescription = dto.HomeworkDescription;
                hw.HomeworkId          = dto.HomeworkId;
                hw.HomeworkName        = dto.HomeworkName;
                hw.HomeworkPoints      = dto.HomeworkPoints;
                hw.HomeworkCode        = dto.HomeworkCode;
                hw.CourseId            = dto.CourseId;
                hw.CourseModuleId      = dto.CourseModuleId;
                hw.OwnerId             = dto.OwnerId;

                this._homeworkManagement.EditHomework(hw);

                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            catch (Exception) {
                // Log exception code goes here
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Error occured while executing method."));
            }
        }
示例#16
0
        public MainViewModel()
        {
            Homeworks.Add(new Homework {
                Name = "Ukol1", Date = new DateTime(2020, 3, 27), Subject = Subject.PRG, IsDone = false
            });
            Homeworks.Add(new Homework {
                Name = "Ukol2", Date = new DateTime(2020, 3, 28), Subject = Subject.CJL, IsDone = false
            });

            Add = new RelayCommand(
                () => { Homeworks.Add(new Homework {
                    Name = "Nový úkol"
                }); },
                () => true
                );
            Remove = new RelayCommand(
                () => { Homeworks.Remove(SelectedHomework); },
                () => { return(SelectedHomework != null); }
                );
            Load = new RelayCommand(
                async() => {
                try
                {
                    string serializedSourceText = await Windows.Storage.FileIO.ReadTextAsync(File);
                    Homeworks = JsonSerializer.Deserialize <ObservableCollection <Homework> >(serializedSourceText);
                }
                catch (Exception ex)
                {
                    var messageDialog = new MessageDialog("Error: " + ex.Message);     // vyhození dialogu odsud není ideální, ale funguje
                    await messageDialog.ShowAsync();
                }
            },
                () => true
                );
            Save = new RelayCommand(
                async() => {
                try
                {
                    string serializedData = JsonSerializer.ToJsonString(Homeworks);
                    await Windows.Storage.FileIO.WriteTextAsync(File, serializedData);

                    /* pokusně přes stream
                     * var stream = await File.OpenAsync(Windows.Storage.FileAccessMode.ReadWrite);
                     * using (var outputStream = stream.GetOutputStreamAt(0))
                     * {
                     *  using (var dataWriter = new Windows.Storage.Streams.DataWriter(outputStream))
                     *  {
                     *      dataWriter.WriteString(JsonSerializer.ToJsonString(_students));
                     *      await dataWriter.StoreAsync();
                     *      await outputStream.FlushAsync();
                     *  }
                     * }
                     * stream.Dispose();
                     */
                }
                catch (Exception ex)
                {
                    var messageDialog = new MessageDialog("Error: " + ex.Message);
                    await messageDialog.ShowAsync();
                }
            },
                () => true
                );
        }
示例#17
0
        public void Remove(string teacher, string name, string start, string end)
        {
            Homeworks h = new Homeworks();

            h.Remove(h.Homework.Single(hw => hw.Teacher == teacher && hw.Name == name && hw.Start == start.Replace('-', '/').Replace('.', ':') && hw.End == end.Replace('-', '/').Replace('.', ':')));
        }