public ActionResult <ExerciseEvaluation> CreateEvaluation([FromBody] EvaluationDTO model, int trainingId, int exerciseId)
        {
            var training = _trainings.GetbyId(trainingId);
            var exercise = _exercises.GetbyId(exerciseId);

            if (training == null)
            {
                return(NotFound("Geen training met dit Id gevonden"));
            }

            if (exercise == null)
            {
                return(NotFound("Geen oefening met dit Id gevonden"));
            }


            try {
                ExerciseEvaluation ee = new ExerciseEvaluation(model.Note, model.FeelingOfExercise, model.Weight, model.Repetitions, model.Sets, exercise);

                training.AddExerciseEvaluationToTraining(ee);

                _evaluations.SaveChanges();
                _trainings.SaveChanges();

                return(Ok(ee));
            } catch (Exception e) {
                return(StatusCode(StatusCodes.Status500InternalServerError, e.Message));
            }
        }
        public async Task <ActionResult <EvaluationDTO> > GetEvaluationDTO(int id)
        {
            //= await _context.EvaluationDTO.FindAsync(id);

            var evaluation = await _context.Evaluation
                             .Include(e => e.Employee).Include(e => e.evaluationProfession)
                             .Include(e => e.evaluationProfession.profession)
                             .Include(e => e.evaluationProfession.evaluationType)
                             .FirstOrDefaultAsync(e => e.ID == id);

            var evaluationDTO = new EvaluationDTO
            {
                ID                     = evaluation.ID,
                Note                   = evaluation.Note,
                EmployeeID             = evaluation.EmployeeID,
                EmployeeName           = evaluation.Employee.Name,
                EvaluationDate         = evaluation.EvaluationDate,
                EvaluationDegreee      = evaluation.EvaluationDegreee,
                EvaluationProfessionID = _context.EvaluationProfessions.Where(e => e.EvaluationTypeID == evaluation.evaluationProfession.EvaluationTypeID && e.ProfessionID == evaluation.evaluationProfession.ProfessionID).FirstOrDefault().ID,
                ProfessionID           = _context.EvaluationProfessions.Where(e => e.ProfessionID == evaluation.evaluationProfession.ProfessionID).FirstOrDefault().profession.ID,
                ProfessionName         = _context.EvaluationProfessions.Where(e => e.ProfessionID == evaluation.evaluationProfession.ProfessionID).FirstOrDefault().profession.Name,
                EvaluationTypeID       = _context.EvaluationProfessions.Where(e => e.EvaluationTypeID == evaluation.evaluationProfession.EvaluationTypeID).FirstOrDefault().evaluationType.ID,
                EvaluationTypeName     = _context.EvaluationProfessions.Where(e => e.EvaluationTypeID == evaluation.evaluationProfession.EvaluationTypeID).FirstOrDefault().evaluationType.Name,
            };

            if (evaluationDTO == null)
            {
                return(NotFound());
            }

            return(evaluationDTO);
        }
        public IActionResult Get(Guid id)
        {
            var           evaluation    = _evaluationRepository.GetEvaluationByID(id);
            EvaluationDTO evaluationDTO = _mapper.Map <EvaluationDTO>(evaluation);

            return(new OkObjectResult(evaluationDTO));
        }
Exemplo n.º 4
0
        private void ValidateEvaluation(EvaluationDTO evaluation)
        {
            if (evaluation == null)
            {
                throw new ServiceException("Evaluation is null")
                      {
                          Type = ExceptionType.NullException
                      }
            }
            ;
            if ((evaluation.Mark > EvaluationDTO.MaxMark) ||
                (evaluation.Mark < EvaluationDTO.MinMark))
            {
                throw new ServiceException(ExceptionType.InvalidFieldException,
                                           $"Invalid mark: {evaluation.Mark}. It must be in range from 1 to 10.");
            }
            if (!_db.ProfileRepository.Contains(evaluation.ProfileId))
            {
                throw new ServiceException($"Profile with id = {evaluation.ProfileId} was not found!")
                      {
                          Type = ExceptionType.ForeignKeyException,
                      }
            }
            ;
            if (!_db.ImageRepository.Contains(evaluation.ImageId))
            {
                throw new ServiceException($"Image with id = {evaluation.ImageId} was not found!")
                      {
                          Type = ExceptionType.ForeignKeyException,
                      }
            }
            ;
        }
    }
}
Exemplo n.º 5
0
        public Evaluation(int id)
        {
            this.id = id;
            EvaluationDTO eval = Get(id);

            sections = eval.Sections.Select(p => p).ToList();
            //sections = GetDbSections(id);
        }
Exemplo n.º 6
0
        public HttpResponseMessage Post(EvaluationDTO evaluation)
        {
            evaluation = model.Add(evaluation);
            HttpResponseMessage response = Request.CreateResponse <EvaluationDTO>(HttpStatusCode.Created, evaluation);

            response.Headers.Location = new Uri(Request.RequestUri + apiUrl + evaluation.Id.ToString());

            return(response);
        }
        public async Task <IActionResult> UpdateAsync([FromRoute] Guid id, [FromBody] EvaluationDTO entity)
        {
            var updated = await _evaluationService.UpdateAsync(entity);

            if (updated)
            {
                return(Ok(entity));
            }
            return(NotFound());
        }
Exemplo n.º 8
0
        public HttpResponseMessage Put(EvaluationDTO evaluation)
        {
            if (!model.Exists(evaluation.Id))
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            model.Update(evaluation);
            HttpResponseMessage response = Request.CreateResponse <EvaluationDTO>(HttpStatusCode.OK, evaluation);

            return(response);
        }
Exemplo n.º 9
0
        public EvaluationDTO Delete(int id)
        {
            EvaluationDTO evaluation = model.Get(id);

            if (evaluation == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            model.Delete(evaluation);
            return(evaluation);
        }
Exemplo n.º 10
0
        public Evaluation(EvaluationDTO dto)
        {
            if (dto.Extra == true)
            {
                Title = dto.Title;
            }

            DescriptionPrivate = dto.DescriptionPrivate;
            DescriptionPupil   = dto.DescriptionPupil;

            Extra = dto.Extra;
        }
Exemplo n.º 11
0
        public async Task <bool> UpdateAsync(EvaluationDTO entity)
        {
            var entityDb = await _evaluationRepository.GetByIdAsync(entity.Id);

            entityDb.Id        = entity.Id;
            entityDb.Mark      = entity.Mark;
            entityDb.Day       = entity.Day;
            entityDb.SubjectId = entity.SubjectId;
            entityDb.TeacherId = entity.TeacherId;
            entityDb.ClassId   = entity.ClassId;

            return(await _evaluationRepository.UpdateAsync(entityDb));
        }
Exemplo n.º 12
0
        public async Task CreateAsync(EvaluationDTO entity)
        {
            Evaluation dbEntity = new Evaluation()
            {
                Id        = entity.Id,
                Mark      = entity.Mark,
                Day       = entity.Day,
                SubjectId = entity.SubjectId,
                TeacherId = entity.TeacherId,
                ClassId   = entity.ClassId
            };

            await _evaluationRepository.CreateAsync(dbEntity);
        }
Exemplo n.º 13
0
        public int MakeEvaluation(EvaluationDTO evaluation)
        {
            ValidateEvaluation(evaluation);
            if (GetDALEvaluationByImageAndProfile(evaluation.ImageId, evaluation.ProfileId) != null)
            {
                throw new ServiceException(ExceptionType.UniqueException,
                                           $"Profile [{evaluation.ProfileId}] already appreciated the image [{evaluation.ImageId}]!");
            }
            Evaluation evaluationDAL = _db.EvaluationRepository
                                       .Add(_mapper.Map <Evaluation>(evaluation));

            _db.Save();
            return(evaluationDAL.Id);
        }
Exemplo n.º 14
0
        public async Task <EvaluationDTO> GetByIdAsync(Guid id)
        {
            Evaluation fromDb = await _evaluationRepository.GetByIdAsync(id);

            EvaluationDTO dbEntity = new EvaluationDTO()
            {
                Id        = fromDb.Id,
                Mark      = fromDb.Mark,
                Day       = fromDb.Day,
                SubjectId = fromDb.SubjectId,
                TeacherId = fromDb.TeacherId,
                ClassId   = fromDb.ClassId
            };

            return(dbEntity);
        }
Exemplo n.º 15
0
        public ActionResult <EvaluationDTO> EditEvaluation([FromBody] EvaluationDTO dto, long groupId, long evaluationId)
        {
            try
            {
                Group s = _groups.GetByIdToEditEvaluation(groupId);
                var   e = s.GetEvaluationById(evaluationId);
                if (e.Extra)
                {
                    e.Title = dto.Title;
                }
                e.DescriptionPupil   = dto.DescriptionPupil;
                e.DescriptionPrivate = dto.DescriptionPrivate;

                _groups.SaveChanges();

                return(new EvaluationDTO(e));
            }
            catch (ArgumentNullException)
            {
                return(NotFound(new CustomErrorDTO("Groep niet gevonden")));
            }
        }
Exemplo n.º 16
0
        public int UpdateOrCreateEvaluation(EvaluationDTO evaluation)
        {
            if (evaluation == null)
            {
                throw new ServiceException("Evaluation is null!")
                      {
                          Type = ExceptionType.NullException
                      }
            }
            ;
            Evaluation evaluationDAL = _db.EvaluationRepository.Get(evaluation.Id) ??
                                       GetDALEvaluationByImageAndProfile(evaluation.ImageId, evaluation.ProfileId);

            if (evaluationDAL == null)
            {
                return(MakeEvaluation(evaluation));
            }
            ValidateEvaluation(evaluation);
            evaluationDAL.Mark = evaluation.Mark;
            _db.Save();
            return(evaluationDAL.Id);
        }
Exemplo n.º 17
0
        public IHttpActionResult PutEvaluation([FromBody] EvaluationModel evaluation)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            int?profileId = GetProfileId();

            if (profileId == null)
            {
                return(new HttpActionResult(HttpStatusCode.NotFound, "User has no profile"));
            }
            EvaluationDTO dto = new EvaluationDTO
            {
                ProfileId = profileId.Value,
                ImageId   = evaluation.ImageId,
                Mark      = evaluation.Mark
            };
            int id = _evaluationService.UpdateOrCreateEvaluation(dto);

            return(Ok(id));
        }
Exemplo n.º 18
0
        public ActionResult <EvaluationDTO> AddEvaluation([FromBody] EvaluationDTO dto, long groupId)
        {
            try
            {
                dto.Extra = true; // evaluations that get addded this way are always extra

                Group      s  = _groups.GetByIdToAddEvaluation(groupId);
                Evaluation pt = new Evaluation(dto);

                pt.EvaluationCriterea   = null;
                pt.EvaluationCritereaId = null;


                s.AddEvaluation(pt);
                _groups.SaveChanges();

                return(new EvaluationDTO(pt));
            }
            catch (ArgumentNullException)
            {
                return(NotFound(new CustomErrorDTO("Groep niet gevonden")));
            }
        }
        public ActionResult <ExerciseEvaluation> EditEvaluation([FromBody] EvaluationDTO model)
        {
            var evaluation = _evaluations.GetbyId(model.Id);

            if (evaluation == null)
            {
                return(NotFound("Geen evaluation met dit Id gevonden"));
            }

            try {
                evaluation.Note            = model.Note;
                evaluation.DifficultyScore = model.FeelingOfExercise;
                evaluation.Weight          = model.Weight;
                evaluation.Repetitions     = model.Repetitions;
                evaluation.Series          = model.Sets;


                _evaluations.SaveChanges();

                return(Ok(evaluation));
            } catch (Exception e) {
                return(StatusCode(StatusCodes.Status500InternalServerError, e.Message));
            }
        }
Exemplo n.º 20
0
        public ActionResult Evaluation(int id)
        {
            EvaluationDTO eval = evalModel.Get(id);

            return(View(eval));
        }
        public async Task <IActionResult> CreateAsync(EvaluationDTO entity)
        {
            await _evaluationService.CreateAsync(entity);

            return(Ok());
        }
Exemplo n.º 22
0
 public void Delete(EvaluationDTO evaluation)
 {
     db.Evaluations.Remove(evaluation);
 }
Exemplo n.º 23
0
 public void Update(EvaluationDTO evaluation)
 {
     db.Entry(evaluation).CurrentValues.SetValues(evaluation);
 }
Exemplo n.º 24
0
        public EvaluationDTO Add(EvaluationDTO evaluation)
        {
            evaluation = db.Evaluations.Add(evaluation);

            return(evaluation);
        }