public Guid UpdateProfessor(Guid Id, ProfessorUpdateRequest professor) { Guid ProfessorId = Guid.NewGuid(); Create(); using (connection) { SqlCommand Usercommand = new SqlCommand("Select ProfessorId From [dbo].[User] WHERE ID = @Id ", connection); Usercommand.Parameters.Add("@Id", SqlDbType.UniqueIdentifier); Usercommand.Parameters["@Id"].Value = Id; using (var reader = Usercommand.ExecuteReader()) { while (reader.Read()) { ProfessorId = Guid.Parse(reader["professorId"].ToString()); } } SqlCommand command = new SqlCommand("UPDATE dbo.Professor SET University=@University,Vocation=@Vocation,Department=@Department,LastUpdatedAt=@LastUpdatedAt WHERE ID = @Id ", connection); command.Parameters.Add("@Id", SqlDbType.UniqueIdentifier); command.Parameters["@Id"].Value = ProfessorId; command.Parameters.Add("@University", SqlDbType.VarChar); command.Parameters["@University"].Value = professor.University; command.Parameters.Add("@Vocation", SqlDbType.VarChar); command.Parameters["@Vocation"].Value = professor.Vocation; command.Parameters.Add("@Department", SqlDbType.VarChar); command.Parameters["@Department"].Value = professor.Department; command.Parameters.Add("@LastUpdatedAt", SqlDbType.DateTime); command.Parameters["@LastUpdatedAt"].Value = DateTime.Now; command.ExecuteNonQuery(); connection.Close(); } return(ProfessorId); }
//Id=User public ProfessorResponse Update(Guid Id, ProfessorUpdateRequest request) { ProfessorResponse professor = _professorDao.GetById(Id); if (!string.IsNullOrWhiteSpace(request.Department)) { professor.Department = request.Department; } if (!string.IsNullOrWhiteSpace(request.University)) { professor.University = request.University; } if (!string.IsNullOrWhiteSpace(request.Vocation)) { professor.Vocation = request.Vocation; } Guid ID = _professorDao.UpdateProfessor(Id, _mapper.Map <ProfessorUpdateRequest>(professor)); var response = new ProfessorResponse(_userService.UpdateUser(Id, request), ID, professor.University, professor.Department, professor.Vocation); return(response); }
public ProfessorResponse Put(Guid id, [FromBody] ProfessorUpdateRequest request) { return(_professorService.Update(id, request)); }