public async Task <IActionResult> PutUser([FromRoute] string id, [FromBody] PersonalDataRequest personalData) { if (id != personalData.UserId) { return(BadRequest()); } var currentUser = await GetCurrentUser(); var requestedUser = await _context.Users.FirstOrDefaultAsync(u => u.Id == id); if (requestedUser == null) { return(NotFound()); } if (!await _accessService.CanEdit(Guid.Parse(requestedUser.Id), currentUser)) { return(Forbid()); } requestedUser.Name = personalData.Name; requestedUser.Surname = personalData.Surname; await _context.SaveChangesAsync(); return(Ok()); }
public PutUser() { _personalData = new PersonalDataRequest { Name = "new_name", Surname = "new_surename", UserId = _user.Id }; }
public override Task <PersonalDataResponse> SendPersonalData(PersonalDataRequest request, ServerCallContext context) { var person = new Person() { FirstName = request.FirstName, LastName = request.LastName, Age = GetAge(request.Cnp), Gender = GetGender(request.Cnp), Cnp = request.Cnp }; if (person.Age == -1) { Console.WriteLine("\n---------------" + "\n| CONNECTED |" + "\n---------------" + "\nFirst name: " + person.FirstName + "\nLast name: " + person.LastName + "\nCNP: " + person.Cnp + "\nAge: " + "INVALID" + "\nGender: " + person.Gender + "\n---------------\n"); return(Task.FromResult(new PersonalDataResponse() { Status = PersonalDataResponse.Types.Status.Error })); } else { Console.WriteLine("\n---------------" + "\n| CONNECTED |" + "\n---------------" + "\nFirst name: " + person.FirstName + "\nLast name: " + person.LastName + "\nCNP: " + person.Cnp + "\nAge: " + person.Age + "\nGender: " + person.Gender + "\n---------------\n"); return(Task.FromResult(new PersonalDataResponse() { Status = PersonalDataResponse.Types.Status.Success })); } }