public ActionResult <IEnumerable <FeeDto> > Update(FeeToCreateUpdateDto feeDto) { using (var context = _repository.GetContext()) { var student = _studentRepo.GetById(feeDto.StudentId); if (student == null) { return(NotFound("Student not found")); } var month = _monthRepo.GetById(feeDto.MonthId); if (month == null) { return(NotFound("Month not found")); } var feeType = _feeTypeRepo.GetById(feeDto.FeeTypeId); if (feeType == null) { return(NotFound("FeeType not found")); } if (feeDto.FeeTypeId != FeeType.IndividualId) { var feeRepeted = _repository.GetByQuery(x => x.StudentId == feeDto.StudentId && x.MonthId == feeDto.MonthId && x.FeeTypeId != FeeType.IndividualId && x.Id != feeDto.Id); if (feeRepeted != null && feeRepeted.Count() > 0) { return(ValidationProblem("El alumno ya tiene el mes abonado.")); } } var entityRepo = _repository.GetByIdInclude(feeDto.Id, IncludeExpressions); if (entityRepo == null) { return(NotFound()); } context.Attach(entityRepo); entityRepo.Update(feeDto.Amount, feeDto.FeeTypeId, feeDto.MonthId, feeDto.IsPaid); _repository.Update(entityRepo); var entity = _repository.GetByIdInclude(feeDto.Id, IncludeExpressions); var response = _mapper.Map <FeeDto>(entity); return(Ok(response)); } }
public ActionResult Create(FeeToCreateUpdateDto feeDto) { var student = _studentRepo.GetById(feeDto.StudentId); if (student == null) { return(NotFound("Student not found")); } var month = _monthRepo.GetById(feeDto.MonthId); if (month == null) { return(NotFound("Month not found")); } var feeType = _feeTypeRepo.GetById(feeDto.FeeTypeId); if (feeType == null) { return(NotFound("FeeType not found")); } if (feeDto.FeeTypeId != FeeType.IndividualId) { var feeRepeted = _repository.GetByQuery(x => x.StudentId == feeDto.StudentId && x.MonthId == feeDto.MonthId && x.FeeTypeId != FeeType.IndividualId); if (feeRepeted != null && feeRepeted.Count() > 0) { return(ValidationProblem("El alumno ya tiene el mes abonado.")); } } Fee fee = new Fee(feeDto.StudentId, feeDto.FeeTypeId, feeDto.MonthId, feeDto.Amount, feeDto.IsPaid, student.FullName + " | " + month.Name); _repository.Create(fee); var response = _repository.GetByIdInclude(fee.Id, IncludeExpressions); return(Ok(response)); }