public async Task <ActionResult <StudentModel> > Get(int id) { try { var results = await _repository.GetStudentByIdAsync(id); return(_mapper.Map <StudentModel>(results)); } catch (Exception) { return(StatusCode(StatusCodes.Status500InternalServerError, "Database failure")); } }
public async Task <ActionResult <UserModel> > Patch(UserModel model) { UserModel result; try { if (model.City != null) { int id = model.UserId; Student student = await _studentsRepository.GetStudentByIdAsync(id); student.Username = model.Username; student.Password = model.Password; student.City = _mapper.Map <City>(model.City); student.Technology = _mapper.Map <Technology>(model.Technology); result = _mapper.Map <UserModel>(await _studentsRepository.EditStudent(student)); } else { int id = model.UserId; Company company = await _companyRepository.GetCompanyByIdAsync(id); company.Username = model.Username; company.Password = model.Password; company.CompanyDescription = model.CompanyDescription; result = _mapper.Map <UserModel>(await _companyRepository.EditCompany(company)); } if (result == null) { return(BadRequest("Edit mode failed")); } return(result); } catch (Exception) { return(StatusCode(StatusCodes.Status500InternalServerError, "Database failure")); } }