Пример #1
0
        public IActionResult Start()
        {
            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(NotFound("User not found"));
            }

            var registration = _registrationRepository.GetLast(mailAdress);

            if (registration == null)
            {
                return(NotFound("Registration not found"));
            }


            if (!registration.Paid)
            {
                return(BadRequest("Registration has not been paid"));
            }

            var route = _routeRepository.GetBy(registration.RouteId);

            if (route == null)
            {
                return(NotFound("Route not found"));
            }

            var walk = _walkRepository.GetByUserAndRoute(user.Id, route.Id);



            if (walk == null
                // && DateCheckHelper.CheckEqualsDate(route.Date, now)
                )
            {
                walk = new Walk(DateTime.Now, route);
                _walkRepository.Add(mailAdress, walk);
                return(Ok());
            }
            else
            {
                return(BadRequest("Walk already exsists"));
            }
        }
Пример #2
0
        public async Task <ActionResult <Walk> > PostWalk([FromHeader] string token, [FromHeader] string email, [FromBody] Walk walk)
        {
            // if user not authenticated
            if (!await _walkerRepository.Authenticated(token, email))
            {
                return(Unauthorized());
            }

            if (await _walkRepository.Exists(email))
            {
                return(Conflict());
            }

            Guid guid = Guid.NewGuid();

            walk.Id        = guid.ToString();
            walk.Status    = 0;
            walk.UserEmail = email;
            await _walkRepository.Add(walk);

            walk.WithoutWalkerInfo();
            return(Ok(walk));
        }