Ejemplo n.º 1
0
        public ActionResult <SubmissionDTO> Post([FromBody] SubmissionDTO value)
        {
            var dados         = _mapper.Map <Submission>(value);
            var registroSalvo = _submissionService.Save(dados);

            return(Ok(_mapper.Map <SubmissionDTO>(registroSalvo)));
        }
Ejemplo n.º 2
0
        public ActionResult <SubmissionDTO> Post([FromBody] SubmissionDTO value)
        {
            var submission = _mapper.Map <Submission>(value);

            submission = _service.Save(submission);
            return(Ok(_mapper.Map <SubmissionDTO>(submission)));
        }
Ejemplo n.º 3
0
        public void EditSubmission(SubmissionDTO submissionDTO)
        {
            var submission = MapperExtension.mapper.Map <SubmissionDTO, Submission>(submissionDTO);

            _db.Entry(_db.Submissions.Find(submissionDTO.SubmissionId)).CurrentValues.SetValues(submission);
            _db.SaveChanges();
        }
Ejemplo n.º 4
0
        public ActionResult <SubmissionDTO> Post([FromBody] SubmissionDTO value)
        {
            Submission submission = _mapper.Map <Submission>(value);
            var        saved      = _mapper.Map <SubmissionDTO>(_service.Save(submission));

            return(Ok(saved));
        }
Ejemplo n.º 5
0
        public void AddSubmission(SubmissionDTO submissionDTO)
        {
            var submission = MapperExtension.mapper.Map <SubmissionDTO, Submission>(submissionDTO);

            _db.Submissions.Add(submission);
            _db.SaveChanges();
        }
Ejemplo n.º 6
0
        public void Save_Submission_Success()
        {
            // Arrange
            var repo       = MockQuestionRepo(1);
            var gm         = new GameManager(repo, MockLeaderboardRepo(), 1);
            var question   = repo.GetAll().FirstOrDefault();
            var submission = new SubmissionDTO()
            {
                Name            = "Name",
                ProvidedResults = new List <AnswerDTO>()
                {
                    new AnswerDTO()
                    {
                        QuestionId = question.Id,
                        OptionId   = question.Options.FirstOrDefault().Id
                    }
                }
            };

            // Act
            var result = gm.SaveResult(submission);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(true, result.Success);
            Assert.AreEqual(null, result.Error);
        }
Ejemplo n.º 7
0
        public SubmissionModel Map(SubmissionDTO submissionDTO)
        {
            if (submissionDTO == null)
            {
                return(null);
            }

            submissionDTO.Student    = _iStudentMapper.Map(_iStudentService.GetById(submissionDTO.StudentId));
            submissionDTO.Assignment = _iAssignmentMapper.Map(_iAssignmentService.GetById(submissionDTO.AssignmentId));

            var studentModel = _iStudentMapper.Map(submissionDTO.Student);
            var assigModel   = _iAssignmentMapper.Map(submissionDTO.Assignment);

            return(new SubmissionModel
            {
                Id = submissionDTO.Id,
                StudentId = studentModel.Id,
                Student = studentModel,
                AssignmentId = assigModel.Id,
                Assignment = assigModel,
                Link = submissionDTO.Link,
                Remark = submissionDTO.Remark,
                Grade = submissionDTO.Grade
            });
        }
Ejemplo n.º 8
0
        public async Task <int> CreateAndAssignToSingleUserAsync(Controller controller, string studentId, CreateViewModel inputModel, HttpPostedFileBase file)
        {
            AssignmentFileDTO assignmentFile = dtoFactory.CreateDTO <AssignmentFileDTOBuilderData, AssignmentFileDTO>(new AssignmentFileDTOBuilderData(file));

            fileService.Create(assignmentFile);

            string path = Path.Combine(controller.Server.MapPath("~/Files/Assignments"), assignmentFile.FileGuid);

            file.SaveAs(path);

            string    mentorId = controller.User.Identity.GetUserId();
            MentorDTO mentor   = await mentorService.GetByIdAsync(mentorId);

            AssignmentDTOBuilderData builderData   = new AssignmentDTOBuilderData(inputModel, mentorId, assignmentFile);
            AssignmentDTO            newAssignment = dtoFactory.CreateDTO <AssignmentDTOBuilderData, AssignmentDTO>(builderData);

            assignmentService.Create(newAssignment);
            await assignmentService.SaveChangesAsync();

            StudentDTO student = await studentService.GetByIdAsync(studentId);

            if (student == null)
            {
                throw new Exception();
            }

            SubmissionDTOBuilderData bulderData    = new SubmissionDTOBuilderData(studentId, newAssignment.AssignmentId, DateTime.Now.AddDays(3));
            SubmissionDTO            newSubmission = dtoFactory.CreateDTO <SubmissionDTOBuilderData, SubmissionDTO>(bulderData);

            student.Submissions.Add(newSubmission);

            await assignmentService.SaveChangesAsync();

            return(newAssignment.AssignmentId);
        }
Ejemplo n.º 9
0
        public async Task AssignToStudentAsync(string studentId, List <int> assignmentIds)
        {
            if (studentId == null || assignmentIds == null)
            {
                throw new ArgumentNullException();
            }

            StudentDTO student = await studentService.GetByIdAsync(studentId);

            if (student == null)
            {
                return;
            }

            IEnumerable <AssignmentDTO> newAssignmentsList = await assignmentService.GetAllByIdAsync(assignmentIds);

            if (newAssignmentsList == null)
            {
                return;
            }

            foreach (AssignmentDTO assignment in newAssignmentsList)
            {
                SubmissionDTOBuilderData bulderData    = new SubmissionDTOBuilderData(studentId, assignment.AssignmentId, DateTime.Now.AddDays(3));
                SubmissionDTO            newSubmission = dtoFactory.CreateDTO <SubmissionDTOBuilderData, SubmissionDTO>(bulderData);
                assignment.Submissions.Add(newSubmission);
            }

            await assignmentService.SaveChangesAsync();
        }
Ejemplo n.º 10
0
        public ActionResult <SubmissionDTO> Post([FromBody] SubmissionDTO value)
        {
            var converted = _mapper.Map <Submission>(value);
            var result    = _service.Save(converted);

            return(Ok(_mapper.Map <SubmissionDTO>(result)));
        }
Ejemplo n.º 11
0
 public ActionResult <SubmissionDTO> Post([FromBody] SubmissionDTO value)
 {
     return(Ok(
                mapper.Map <SubmissionDTO>(
                    submissionService.Save(mapper.Map <Submission>(value)
                                           ))));
 }
Ejemplo n.º 12
0
        public async Task <bool> EditSubmissionAsync(SubmissionDTO submission)
        {
            var path   = Properties.Resources.editSubmissionPath;
            var result = await _apiHelper.Put(path, submission);

            return(result != null && result.ResponseType == ResponseType.Success);
        }
Ejemplo n.º 13
0
        public IHttpActionResult CreateSubmission(SubmissionDTO subDTO)
        {
            Submission sub = new Submission();

            if (!ModelState.IsValid)
            {
                return(BadRequest()); // the Bad Request method returns a bad request result which is a class that implements IhttActionResult
            }
            try
            {
                var subnew = AutoMapper.Mapper.Map <SubmissionDTO, Submission>(subDTO);
                _context.Submissions.Add(subnew);
                Console.WriteLine(subDTO.ToString());
                _context.SaveChanges();
                subDTO.subKey = sub.subKey;
            }
            catch (DbEntityValidationException dbEx)
            {
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        Trace.TraceInformation("Property: {0} Error: {1}",
                                               validationError.PropertyName,
                                               validationError.ErrorMessage);
                    }
                }
            }

            Console.WriteLine("Finish Statement");
            //RESTFUL convention means we must return the Uri (Unified Resource Identier ) example   /api/submissions/10
            return(Created(new Uri(Request.RequestUri + "/" + sub.subKey), subDTO));
        }
Ejemplo n.º 14
0
        public async Task <IFileStreamWithInfo> GetSubmissionFileAsync(Controller controller, int assignmentId, string studentId)
        {
            SubmissionDTO submission = await service.GetByCompositeKeysAsync(assignmentId, studentId);

            if (submission == null || submission.SubmitFile == null)
            {
                return(null);
            }
            string origFileName            = submission.SubmitFile.FileName;
            string fileGuid                = submission.SubmitFile.FileGuid;
            string mimeType                = MimeMapping.GetMimeMapping(origFileName);
            IFileStreamWithInfo fileStream = null;

            try
            {
                string filePath = Path.Combine(controller.Server.MapPath("~/Files/Assignments"), fileGuid);
                fileStream = new FileStreamWithInfo
                {
                    FileStream = File.ReadAllBytes(filePath),
                    FileName   = origFileName,
                    FileType   = mimeType
                };
            }
            catch
            {
                return(null);
            }
            return(fileStream);
        }
Ejemplo n.º 15
0
        public async Task <IActionResult> Post([FromBody] SubmissionDTO bindingModel)
        {
            ResponseDTO dto = new ResponseDTO(ErrorModel);

            if (ModelState.IsValid)
            {
                // Massage data
                bindingModel.Email     = bindingModel.Email.Trim();
                bindingModel.FirstName = bindingModel.FirstName.Trim();
                bindingModel.LastName  = bindingModel.LastName.Trim();
                bindingModel.Comments  = bindingModel.Comments.Trim();

                // Call service to add submission
                await submissionService.AddSubmissionAsync(bindingModel.Email, bindingModel.FirstName, bindingModel.LastName, bindingModel.Comments, bindingModel.ActivityId.Value);

                // Check if error model caught anything before sending ok response.
                if (ErrorModel.Errors.Count == 0)
                {
                    return(Ok(dto));
                }
            }

            // TODO: Add field to ErrorModel to determine if 500 error should show
            return(BadRequest(dto));
        }
Ejemplo n.º 16
0
        public async Task AssignToStudentsAsync(int assigmentId, List <string> studentIds)
        {
            if (studentIds == null)
            {
                throw new ArgumentNullException("studentIds");
            }
            AssignmentDTO assignment = await assignmentService.GetByIdWithFileAsync(assigmentId);

            if (assignment == null)
            {
                throw new KeyNotFoundException();
            }

            IEnumerable <StudentDTO> students = await studentService.GetAllByIdAsync(studentIds);

            foreach (StudentDTO student in students)
            {
                SubmissionDTOBuilderData bulderData    = new SubmissionDTOBuilderData(student.Id, assignment.AssignmentId, DateTime.Now.AddDays(3));
                SubmissionDTO            newSubmission = dtoFactory.CreateDTO <SubmissionDTOBuilderData, SubmissionDTO>(bulderData);

                student.Submissions.Add(newSubmission);
            }

            await assignmentService.SaveChangesAsync();
        }
Ejemplo n.º 17
0
        private async void SubmitButton_Click(object sender, RoutedEventArgs e)
        {
            Submit.IsEnabled = false;
            OpenFileDialog fileDialog = new OpenFileDialog()
            {
                Filter = "pdf files (*.pdf)|*.pdf"
            };

            if ((bool)fileDialog.ShowDialog())
            {
                var articleFile = ReadData(File.OpenRead(fileDialog.FileName));
                var submission  = new SubmissionDTO()
                {
                    SubmissionDate = DateTime.Now,
                    ArticleFile    = articleFile,
                    ArticleId      = currentArticle.ArticleId
                };
                var result = await core.AddSubmissionAsync(submission);

                if (result)
                {
                    MessageBox.Show("Successfully submitted article");
                }
                else
                {
                    MessageBox.Show("Error occured while submitting article");
                }
                await LoadSubmissions();
            }
            Submit.IsEnabled = true;
        }
 public ActionResult <SubmissionDTO> Post([FromBody] SubmissionDTO value)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     return(Ok(mapper.Map <SubmissionDTO>(service.Save(mapper.Map <Submission>(value)))));
 }
Ejemplo n.º 19
0
        public async Task UpdateAsync(EditViewModel viewModel)
        {
            SubmissionDTOBuilderData builderData      = new SubmissionDTOBuilderData(viewModel);
            SubmissionDTO            editedSubmission = dtoFactory.CreateDTO <SubmissionDTOBuilderData, SubmissionDTO>(builderData);

            service.UpdateDueDateCompletedAndGrade(editedSubmission);

            await service.SaveChangesAsync();
        }
        public string PostTrack([FromBody] SubmissionDTO submission)
        {
            var locationId  = submission.LocationId;
            var trackId     = submission.TrackId;
            var accessToken = submission.AccessToken;

            var error = businessLogic.PostTrackToLocation(locationId, trackId, accessToken);

            return(error);
        }
Ejemplo n.º 21
0
        public async Task RemoveStudentFromAssignmentAsync(int assignmentId, string studentId)
        {
            SubmissionDTO submission = await submissionService.GetByCompositeKeysAsync(assignmentId, studentId);

            if (submission != null)
            {
                submissionService.Delete(submission);
            }
            await submissionService.SaveChangesAsync();
        }
Ejemplo n.º 22
0
 public ActionResult <SubmissionDTO> Post([FromBody] SubmissionDTO value)
 {
     if (value != default)
     {
         var obj = mapper.Map <Submission>(value);
         obj = service.Save(obj);
         var listDTO = mapper.Map <SubmissionDTO>(obj);
         return(Ok(listDTO));
     }
     return(NoContent());
 }
Ejemplo n.º 23
0
        public async Task DeleteAsync(int assignmentId, string studentId)
        {
            SubmissionDTO submission = await service.GetByCompositeKeysAsync(assignmentId, studentId);

            if (submission.SubmitFile != null)
            {
                DeleteFile(submission.SubmitFile);
            }
            service.Delete(submission);
            await service.SaveChangesAsync();
        }
Ejemplo n.º 24
0
        public async Task EvaluateAsync(EvaluateInputModel inputModel)
        {
            SubmissionDTO submission = await service.GetByCompositeKeysAsync(inputModel.assignmentId, inputModel.studentId);

            if (submission == null)
            {
                throw new Exception();
            }

            submission.Grade = (byte)inputModel.Grade;
            await service.SaveChangesAsync();
        }
Ejemplo n.º 25
0
 public IHttpActionResult EditSubmission([FromBody] SubmissionDTO submission)
 {
     if (submission.ArticleFile != null)
     {
         return(BadRequest());
     }
     if (_bll.EditSubmission(submission))
     {
         return(Ok());
     }
     return(InternalServerError());
 }
Ejemplo n.º 26
0
 public bool EditSubmission(SubmissionDTO submission)
 {
     try
     {
         _repository.EditSubmission(submission);
     }
     catch
     {
         return(false);
     }
     return(true);
 }
Ejemplo n.º 27
0
        public ActionResult <SubmissionDTO> Post([FromBody] SubmissionDTO value)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var submission = _mapper.Map <Models.Submission>(value);
            var retorno    = _submissionService.Save(submission);

            return(Ok(_mapper.Map <SubmissionDTO>(retorno)));
        }
Ejemplo n.º 28
0
        public void Update(SubmissionDTO submission)
        {
            var dpt = _dbContext.Submissions.Find(submission.Id);

            _dbContext.Entry(dpt).CurrentValues.SetValues(submission);

            //var entity = _dbSet.SingleOrDefault(a => a.Id == attendance.Id);

            if (dpt != null)
            {
                dpt = submission;
            }
        }
Ejemplo n.º 29
0
        public async Task <bool> ToggleCompleteStatusAsync(int assignmentId, string studentId)
        {
            SubmissionDTO submission = await service.GetByCompositeKeysAsync(assignmentId, studentId);

            if (submission == null)
            {
                throw new Exception();
            }
            submission.Completed = submission.Completed == true ? false : true;
            await service.SaveChangesAsync();

            return(submission.Completed);
        }
Ejemplo n.º 30
0
        public GameResult Submit([FromBody] SubmissionDTO result)
        {
            if (result == null || result.ProvidedResults == null)
            {
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(new GameResult()
                {
                    Error = "No data recieved"
                });
            }

            return(_gameManager.SaveResult(result));
        }