public async Task <PeriodResponse> DeleteAsync(int code) { try { var exist = await _periodRepository.FindByIdAsync(code); PeriodResponse response = exist == null ? new PeriodResponse($"Period {code} not found") : new PeriodResponse(exist); _periodRepository.Remove(exist); await _unitOfWork.CompleteAsync(); return(response); } catch (Exception e) { return(new PeriodResponse($"An error occurred when deleting the period: { e.Message }")); } }
public async Task <PeriodResponse> UpdateAsync(int code, Period period) { try { var exist = await _periodRepository.FindByIdAsync(code); PeriodResponse response = exist == null ? new PeriodResponse($"Period {code} not found") : new PeriodResponse(exist); exist.Description = period.Description != "" ? period.Description : exist.Description; exist.Start = period.Start != "" ? period.Start : exist.Start; exist.End = period.End != "" ? period.End : exist.End; _periodRepository.Update(exist); await _unitOfWork.CompleteAsync(); return(response); } catch (Exception e) { return(new PeriodResponse($"An error occurred when updating the period: { e.Message }")); } }