예제 #1
0
 public AccountBookRepository(HomeworkModel hwm)
 {
     if (hwm != null)
     {
         this.__hwm = hwm;
     }
 }
예제 #2
0
        public bool Update(HomeworkModel entity)
        {
            try
            {
                entity.Standard = _dbContext.Standards.FirstOrDefault(x => x.StandardId == entity.StandardId);
                var currentEntity = _dbContext.Set <HomeworkModel>().AsQueryable().FirstOrDefault(x => x.HomeworkId == entity.HomeworkId);
                if (currentEntity == null)
                {
                    return(false);
                }
                currentEntity.HomeworkName = entity.HomeworkName;
                currentEntity.IssueDate    = entity.IssueDate;
                currentEntity.DueDate      = entity.DueDate;
                currentEntity.StandardId   = entity.StandardId;
                currentEntity.Standard     = entity.Standard;

                if (entity.ImageFileUrl != null)
                {
                    currentEntity.ImageFileUrl.Url = entity.ImageFileUrl.Url;
                }

                return(true);
            }
            catch (Exception ex)
            {
                LogException(ex);
                throw ex;
            }
        }
예제 #3
0
        public IHttpActionResult Post(HomeworkModel model)
        {
            if (model == null)
            {
                return(this.BadRequest("No data received."));
            }

            if (!this.ModelState.IsValid)
            {
                return(this.BadRequest("Invalid homework data."));
            }


            var courseId = this.data.Courses.All().Where(c => c.Name == model.CourseName).Select(x => x.Id).FirstOrDefault();

            if (courseId == null)
            {
                return(this.BadRequest("Course not found."));
            }

            if (!this.data.Students.All().Any(s => s.StudentIdentification == model.StudentIdentification))
            {
                return(this.BadRequest("Student not found."));
            }

            var homework = Mapper.Map <Homework>(model);

            homework.CourseId = courseId;

            this.data.Homeworks.Add(homework);

            this.data.SaveChanges();

            return(this.Ok());
        }
 public ActionResult Upload(HomeworkModel model, string returnUrl, string topic_id)
 {
     if (!ModelState.IsValid)
     {
         return(View(model));
     }
     try
     {
         System.Diagnostics.Debug.WriteLine(model.TopicId);
         System.Diagnostics.Debug.WriteLine(model.Author);
         if (model.UploadFile.ContentLength > 0)
         {
             string fileName = Path.GetFileName(model.UploadFile.FileName);
             string path     = Path.Combine(Server.MapPath("~/Static/Homework/"), topic_id + "_" + User.Identity.GetUserName() + "_" + fileName);
             model.UploadFile.SaveAs(path);
         }
         ViewBag.Message = "File Uploaded Successfully!!";
         var database = new HomeworkDataBase();
         database.accessDataBase();
         database.insertHomwork(model, User.Identity.GetUserName(), topic_id, topic_id + "_" + User.Identity.GetUserName() + "_" + Path.GetFileName(model.UploadFile.FileName));
         return(RedirectToAction("Index", "Topic"));
     }
     catch
     {
         ViewBag.Message = "File upload failed!!";
         return(View());
     }
 }
예제 #5
0
        public ActionResult Edit(int id)
        {
            if (!_permissionService.Authorize("ManageHomework"))
            {
                return(AccessDeniedView());
            }

            if (id == 0)
            {
                throw new ArgumentNullException("id");
            }

            var model       = new HomeworkModel();
            var objHomework = _smsService.GetHomeworkById(id);

            if (objHomework != null)
            {
                model = objHomework.ToModel();
            }

            model.AvailableAcadmicYears = _smsService.GetAllAcadmicYears().Select(x => new SelectListItem()
            {
                Text     = x.Name.Trim(),
                Value    = x.Id.ToString(),
                Selected = model.AcadmicYearId == x.Id
            }).ToList();
            return(View(model));
        }
        public ActionResult Mark(string username, string classId, int classNumber)
        {
            HomeworkModel homeworkModel = new HomeworkModel();

            ViewBag.homework = homeworkModel.GetHomework(username, classId, classNumber);
            return(View());
        }
예제 #7
0
        public IHttpActionResult Update(int id, HomeworkModel homework)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.BadRequest(ModelState));
            }

            var existingHw = this.data
                             .Homeworks
                             .All()
                             .FirstOrDefault(h => h.Id == id);

            if (existingHw == null)
            {
                return(this.BadRequest("No such homework found!"));
            }

            existingHw.FileUrl           = homework.FileUrl;
            existingHw.Student.FirstName = homework.StudentFirstName;
            existingHw.Student.LastName  = homework.StudentLastName;

            this.data.SaveChanges();

            homework.Id = existingHw.StudentIdentification;
            return(this.Ok(homework));
        }
        public IHttpActionResult AddHomework(int id, HomeworkModel homework)
        {
            var course = this.data.Courses
                         .All()
                         .FirstOrDefault(c => c.Id == id);

            if (course == null)
            {
                return(BadRequest("Course not exist - invalid id"));
            }

            if (!this.ModelState.IsValid)
            {
                return(BadRequest(this.ModelState));
            }

            var newHomework = new Homework
            {
                Content  = homework.Content,
                Deadline = homework.Deadline
            };

            course.Homeworks.Add(newHomework);
            foreach (var student in course.Students)
            {
                student.Homeworks.Add(newHomework);
            }

            this.data.Courses.SaveChanges();

            return(Ok(homework));
        }
        public ActionResult SubmitHomework(string classId, int classNumber)
        {
            string        username      = HttpContext.Request.Cookies["login"]["name"];
            HomeworkModel homeworkModel = new HomeworkModel();

            ViewBag.homework = homeworkModel.GetHomework(username, classId, classNumber);
            return(View());
        }
        public ActionResult ViewScore(string classId, int classNumber)
        {
            HomeworkModel homeworkModel = new HomeworkModel();
            LessonModel   lessonModel   = new LessonModel();

            ViewBag.homeworks = homeworkModel.GetListHomeworkOfLesson(classId, classNumber);
            ViewBag.lesson    = lessonModel.GetLesson(classId, classNumber);
            return(View());
        }
예제 #11
0
 public IActionResult Put(Guid id, [FromBody] HomeworkModel model)
 {
     try {
         var homework = homeworks.Update(id, HomeworkModel.ToEntity(model));
         return(CreatedAtRoute("Get", new { id = homework.Id }, HomeworkModel.ToModel(homework)));
     } catch (ArgumentException e) {
         return(BadRequest(e.Message));
     }
 }
예제 #12
0
        public IActionResult Get(Guid id)
        {
            var homework = homeworks.Get(id);

            if (homework == null)
            {
                return(NotFound());
            }
            return(Ok(HomeworkModel.ToModel(homework)));
        }
예제 #13
0
        public ActionResult List()
        {
            if (!_permissionService.Authorize("ManageHomework"))
            {
                return(AccessDeniedView());
            }

            var model = new HomeworkModel();

            return(View(model));
        }
        public HttpResponseMessage CreateHomework(HomeworkModel model,
                                                  [ValueProvider(typeof(HeaderValueProviderFactory <string>))] string accessToken)
        {
            var responseMsg = this.PerformOperationAndHandleExceptions(() =>
            {
                var dbContext = new TimetableContext();
                using (dbContext)
                {
                    var user            = this.GetUserByAccessToken(accessToken, dbContext);
                    var subject         = model.Subject;
                    var existingSubject = dbContext.Subjects.FirstOrDefault(s => s.Name == subject);

                    var homework = new Homework
                    {
                        Owner      = user,
                        IsDone     = model.IsDone,
                        SubmitDate = model.SubmitDate
                    };

                    user.Homeworks.Add(homework);
                    dbContext.SaveChanges();

                    if (existingSubject == null)
                    {
                        var newSubject = new Subject {
                            Name = subject, Owner = user
                        };
                        user.Subjects.Add(newSubject);
                        dbContext.SaveChanges();
                        homework.Subject = newSubject;
                        newSubject.Homeworks.Add(homework);
                    }
                    else
                    {
                        homework.Subject = existingSubject;
                        existingSubject.Homeworks.Add(homework);
                    }


                    dbContext.SaveChanges();

                    var responseModel = new ResponseModel()
                    {
                        Id = homework.Id
                    };

                    var response = this.Request.CreateResponse(HttpStatusCode.OK, responseModel);
                    return(response);
                }
            });

            return(responseMsg);
        }
예제 #15
0
 public void Add(HomeworkModel entity)
 {
     try
     {
         entity.Standard = _dbContext.Standards.FirstOrDefault(x => x.StandardId == entity.StandardId);
         _dbContext.Entry(entity).State = EntityState.Added;
     }
     catch (Exception ex)
     {
         LogException(ex);
         throw ex;
     }
 }
        public HomeworkModel GetHomeworkById(int id,
                                             [ValueProvider(typeof(HeaderValueProviderFactory <string>))] string accessToken)
        {
            return(this.PerformOperationAndHandleExceptions(() =>
            {
                var dbContext = new TimetableContext();
                var user = this.GetUserByAccessToken(accessToken, dbContext);
                var homework = user.Homeworks.FirstOrDefault(l => l.Id == id);

                var models = HomeworkModel.Parse(homework);

                return models;
            }));
        }
        public IEnumerable <HomeworkModel> GetAll(
            [ValueProvider(typeof(HeaderValueProviderFactory <string>))] string accessToken)
        {
            return(this.PerformOperationAndHandleExceptions(() =>
            {
                var dbContext = new TimetableContext();
                var user = this.GetUserByAccessToken(accessToken, dbContext);
                var homeworks = user.Homeworks.Where(h => h.SubmitDate >= DateTime.Today).ToList();

                var models = HomeworkModel.ParseModels(homeworks);

                return models.OrderBy(m => m.SubmitDate);
            }));
        }
예제 #18
0
        public void Remove(HomeworkModel entity)
        {
            try
            {
                _dbContext.Entry(entity).State = EntityState.Deleted;

                //return await (_dbContext.SaveChangesAsync());
            }
            catch (Exception ex)
            {
                LogException(ex);
                throw ex;
            }
        }
        //Find Single Homework base on "term" (async)
        public async Task <HomeworkDTO> SearchSingleHomeworkByIdAsync(int Id)
        {
            try
            {
                using (var unitOfWork = unitOfWorkFactory.Create())
                {
                    HomeworkModel model = await Task.Run(() => unitOfWork.HomeworkRepository.GetSingleOrDefaultHomework(x => x.HomeworkId == Id));

                    return(_Mapper_ToDTO.Map <HomeworkModel, HomeworkDTO>(model));
                }
            }
            catch (Exception ex)
            {
                LogException(ex);
                throw ex;
            }
        }
예제 #20
0
        public ActionResult Create()
        {
            if (!_permissionService.Authorize("ManageHomework"))
            {
                return(AccessDeniedView());
            }

            var model = new HomeworkModel();

            model.AvailableAcadmicYears = _smsService.GetAllAcadmicYears().Select(x => new SelectListItem()
            {
                Text     = x.Name.Trim(),
                Value    = x.Id.ToString(),
                Selected = x.IsActive
            }).ToList();
            return(View(model));
        }
        //Update Homework (async)
        public async Task <HomeworkDTO> UpdateHomeworkAsync(HomeworkDTO modelDTO)
        {
            try
            {
                using (var unitOfWork = unitOfWorkFactory.Create())
                {
                    if (!string.IsNullOrEmpty(modelDTO._ImageFileUrl))
                    {
                        var tempImageTypeModel = unitOfWork.ImageFileTypeRepository.GetSingleOrDefaultImageFileType(x => x.Type.Contains("HomeworkFile"));

                        ImageFileTypeDTO imageFileTypeDTO = _Mapper_ToDTO.Map <ImageFileTypeModel, ImageFileTypeDTO>(tempImageTypeModel);

                        modelDTO.ImageFileUrl = new ImageFileUrlDTO()
                        {
                            Url             = modelDTO._ImageFileUrl,
                            CreateDate      = DateTime.Now,
                            ImageFileTypeId = imageFileTypeDTO.ImageFileTypeId
                        };
                    }
                    else
                    {
                        modelDTO.ImageFileUrl = null;
                    }

                    HomeworkModel model = _Mapper_ToModel.Map <HomeworkDTO, HomeworkModel>(modelDTO);

                    bool result = unitOfWork.HomeworkRepository.Update(model);

                    HomeworkDTO modelRTN = null;
                    if (result)
                    {
                        await unitOfWork.SaveChangesAsync();

                        modelRTN = _Mapper_ToDTO.Map <HomeworkModel, HomeworkDTO>(model);
                    }

                    return(modelRTN);
                }
            }
            catch (Exception ex)
            {
                LogException(ex);
                throw ex;
            }
        }
예제 #22
0
        public ActionResult Edit(HomeworkModel model, FormCollection frm, bool continueEditing)
        {
            if (!_permissionService.Authorize("ManageHomework"))
            {
                return(AccessDeniedView());
            }

            var user = _userContext.CurrentUser;
            // Check for duplicate classroom, if any
            var checkHomework = _smsService.CheckHomeworkExists(model.Name, model.Id);

            if (checkHomework)
            {
                ModelState.AddModelError("Name", "A Homework with the same name already exists. Please choose a different name.");
            }

            if (ModelState.IsValid)
            {
                var objHomework = _smsService.GetHomeworkById(model.Id);
                if (objHomework != null)
                {
                    model.CreatedOn        = objHomework.CreatedOn;
                    objHomework            = model.ToEntity(objHomework);
                    objHomework.ModifiedOn = DateTime.Now;
                    _smsService.UpdateHomework(objHomework);
                }
            }
            else
            {
                model.AvailableAcadmicYears = _smsService.GetAllAcadmicYears().Select(x => new SelectListItem()
                {
                    Text     = x.Name.Trim(),
                    Value    = x.Id.ToString(),
                    Selected = model.AcadmicYearId == x.Id
                }).ToList();
                return(View(model));
            }

            SuccessNotification("Homework updated successfully.");
            if (continueEditing)
            {
                return(RedirectToAction("Edit", new { id = model.Id }));
            }
            return(RedirectToAction("List"));
        }
        public IHttpActionResult Create(HomeworkModel homework)
        {
            if (!this.ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var newHomework = new Homework
            {
                Deadline = homework.Deadline,
                TimeSent = homework.TimeSent
            };

            this.data.Homeworks.Add(newHomework);
            this.data.SaveChanges();

            homework.Id = newHomework.Id;
            return(Ok(homework));
        }
예제 #24
0
        public IHttpActionResult Create(HomeworkModel homework)
        {
            if (!this.ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var newHomework = new Homework
            {
                StudentIdentification = homework.StudentIdentification,
                CourseId = Guid.Parse(homework.CourseId)
            };

            this.data.Homeworks.Add(newHomework);
            this.data.SaveChanges();

            homework.Id = newHomework.Id;
            return(Ok(homework));
        }
        public IHttpActionResult Create(HomeworkModel item)
        {
            if (!this.ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var newItem = new Homework()
            {
                Content = item.Content,
            };

            this.data.Homeworks.Add(newItem);
            this.data.Homeworks.SaveChanges();

            item.ID = newItem.ID;

            return(Ok(item));
        }
        public ActionResult MarkHandler(FormCollection form)
        {
            string username    = form["username"].Trim();
            string classId     = form["classId"].Trim();
            int    classNumber = Convert.ToInt32(form["classNumber"]);
            int    score       = Convert.ToInt32(form["score"]);

            Homework homework = new Homework()
            {
                StudentUsername = username,
                ClassId         = classId,
                ClassNumber     = classNumber,
                Score           = score
            };

            HomeworkModel homeworkModel = new HomeworkModel();

            homeworkModel.Update(homework);
            return(RedirectToAction("ViewHomework", new  { classId, classNumber }));
        }
예제 #27
0
        public void GetHomeworkTest()
        {
            var homeworkModel = new HomeworkModel
            {
                Id          = Guid.NewGuid(),
                Description = "A basic homework",
            };
            var mock = new Mock <IHomeworkLogic>(MockBehavior.Strict);

            mock.Setup(m => m.Get(homeworkModel.Id)).Returns(homeworkModel.ToEntity());
            var controller = new HomeworksController(mock.Object);

            var result        = controller.Get(homeworkModel.Id);
            var createdResult = result as OkObjectResult;
            var model         = createdResult.Value as HomeworkModel;

            mock.VerifyAll();
            Assert.AreEqual(homeworkModel.Description, model.Description);
            Assert.AreEqual(homeworkModel.Id, model.Id);
        }
        public IHttpActionResult Update(int id, HomeworkModel homework)
        {
            if (!this.ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var existingHomework = this.data.Homeworks.All().First(h => h.HomeworkId == id);

            if (existingHomework == null)
            {
                return(BadRequest("Such homework does not exist!"));
            }

            existingHomework.Content = homework.Content;
            this.data.SaveChanges();

            homework.HomeworkId = id;

            return(Ok(homework));
        }
        public IHttpActionResult Update(int id, HomeworkModel item)
        {
            if (!this.ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var existingItem = this.data.Homeworks.Find(id);

            if (existingItem == null)
            {
                return(BadRequest("Invalid Course"));
            }

            // Check if some of the fields in the new data are not null
            existingItem.Content = item.Content;
            this.data.Courses.SaveChanges();

            item.ID = existingItem.ID;
            return(Ok(item));
        }
        public ActionResult SubmitHomeworkHandler(FormCollection form)
        {
            string username        = HttpContext.Request.Cookies["login"]["name"];
            string classId         = form["classId"].Trim();
            int    classNumber     = Convert.ToInt32(form["classNumber"]);
            string homwworkContent = SaveHomework(username, classId, classNumber);

            Homework homework = new Homework()
            {
                StudentUsername = username,
                ClassId         = classId,
                ClassNumber     = classNumber,
                HomeworkContent = homwworkContent
            };

            HomeworkModel homeworkModel = new HomeworkModel();

            homeworkModel.Submit(homework);

            return(RedirectToAction("RegisterInfo", new { classId }));
        }