public IActionResult Stop() { if (!User.Identity.IsAuthenticated) { return(Unauthorized()); } string mailAdress = User.Identity.Name; if (mailAdress == null) { return(BadRequest()); } var user = _userRepository.GetBy(mailAdress); if (user == null) { return(BadRequest()); } var walk = user.Walks.Last(); if (walk == null) { return(NotFound()); } walk.EndTime = DateTime.Now; _walkRepository.Update(user.Email, walk); var registration = _registrationRepository.GetLast(user.Email); var route = _routeRepository.GetBy(registration.RouteId); var certificateDTO = CertificateMapper.DTOFrom(user, walk, route); _mailService.SendCertificate(certificateDTO); return(Ok()); }
public async Task <IActionResult> PutWalk([FromHeader] string token, [FromHeader] string email, [FromRoute] string id, [FromHeader] bool isUser, [FromBody] Walk walk) { // if user and not authenticated if (isUser && !await _walkerRepository.Authenticated(token, email)) { return(Unauthorized()); } // is safewalker and not authenticated else if (!isUser && !await _safewalkerRepository.Authenticated(token, email)) { return(Unauthorized()); } var oldWalk = await _walkRepository.Get(id); if (oldWalk == null) { return(NotFound()); } // Check if person is part of the walk if (isUser && oldWalk.UserEmail != email) { return(Unauthorized()); } // map fields from input walk to existing walk if (isUser) { oldWalk.UserMapFields(walk); } else { oldWalk.WalkerEmail = email; oldWalk.WalkerMapFields(walk); } var newWalk = await _walkRepository.Update(oldWalk); return(Ok(newWalk)); }