public async Task <IActionResult> Update(int id, YearDTO yearDTO) { var year = await Updating(id, yearDTO); if (year != null) { var yearMapped = _mapper.Map <YearSendDTO>(year); return(Ok(yearMapped)); } return(ResponeError()); }
private async Task <Year> Updating(int id, YearDTO yearDTO) { var year = await _repo.Get(id); if (year == null) { errorsList.Add("Rok nie istnieje"); return(null); } if (IsInstitute() && GetInstituteID() != year.Specialization.Major.Institute.ID) { errorsList.Add("Nie możesz modyfikować roków z innych wydziałów"); return(null); } Tools.CopyValues(year, yearDTO); if (IsSuperUser() && yearDTO.SpecializationID != null) { var spec = await _repo.Get <Specialization>((int)yearDTO.SpecializationID); if (spec != null) { year.Specialization = spec; } } var updatedYear = await _repo.Update(year); if (updatedYear != null) { return(updatedYear); } errorsList.Add("Nie udało się zmodyfikować roku"); return(null); }