public async Task <ActionResult> UpdateAsync([FromBody] Company newCompany, long id) { var company = await _companies.GetCompanyByIdAsync(id); if (company == null) { return(NotFound()); } company.Name = newCompany.Name; company.EstablishmentYear = newCompany.EstablishmentYear; if (newCompany.Employees.Any()) { company.Employees = _mapper.Map <IEnumerable <EfDataAccess.Entities.Employee> >(newCompany.Employees); } _companies.UpdateCompany(company); await _companies.SaveChangesAsync(); return(Ok()); }
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")); } }