Esempio n. 1
0
        public async Task <IActionResult> GetMovie(string id)
        {
            _logger.LogInformation("GetMovie");
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }
                var cinemaworldResult = await _applicationDbContext.GetCinemaworldMovie(id);

                var filmworldResult = await _applicationDbContext.GetFilmworldMovie(id);

                if (cinemaworldResult == null)
                {
                    return(new OkObjectResult(filmworldResult));
                }
                if (filmworldResult == null)
                {
                    return(new OkObjectResult(cinemaworldResult));
                }
                if (cinemaworldResult.Price > filmworldResult.Price)
                {
                    return(new OkObjectResult(filmworldResult));
                }
                return(new OkObjectResult(cinemaworldResult));
            }
            catch (Exception e)
            {
                _logger.LogError(e, "GetMovie");
                ModelState.AddErrorToModelState(e);
                return(BadRequest(ModelState));
            }
        }
Esempio n. 2
0
        public async Task <IActionResult> Post([FromBody] CredentialsViewModel credentials)
        {
            _logger.LogInformation("Post");
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                var identity = await Tokens.GetClaimsIdentity(_userManager, _jwtFactory, credentials.UserName, credentials.Password);

                if (identity == null)
                {
                    return(BadRequest(ModelState.AddErrorToModelState("login_failure", "Invalid username or password.")));
                }

                var jwt = await Tokens.GenerateJwt(identity, _jwtFactory, credentials.UserName, _jwtOptions, new JsonSerializerSettings { Formatting = Formatting.Indented });

                return(new OkObjectResult(jwt));
            }
            catch (Exception e)
            {
                _logger.LogError(e, "Post");
                ModelState.AddErrorToModelState(e);
                return(BadRequest(ModelState));
            }
        }
Esempio n. 3
0
        public async Task <IActionResult> Post([FromBody] CustomerRegistrationViewModel model)
        {
            _logger.LogInformation("Post");
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                var userIdentity = _mapper.Map <AppUser>(model);
                var result       = await _userManager.CreateAsync(userIdentity, model.Password);

                if (!result.Succeeded)
                {
                    return(new BadRequestObjectResult(ModelState.AddErrorsToModelState(result)));
                }
                await _applicationDbContext.AddCustomer(userIdentity.Id);

                return(new OkObjectResult("Account created"));
            }
            catch (Exception e)
            {
                _logger.LogError(e, "Post");
                ModelState.AddErrorToModelState(e);
                return(BadRequest(ModelState));
            }
        }
Esempio n. 4
0
        public async Task <IActionResult> Delete(int id)
        {
            _logger.LogInformation("Delete");
            try
            {
                await _applicationDbContext.DeleteCartItem(id);

                return(Ok());
            }
            catch (Exception e)
            {
                _logger.LogError(e, "Delete");
                ModelState.AddErrorToModelState(e);
                return(BadRequest(ModelState));
            }
        }
Esempio n. 5
0
        public async Task <IActionResult> Get()
        {
            _logger.LogInformation("Get");
            try
            {
                var result = await _applicationDbContext.GetCartItems(GetCustomer().Id, false);

                return(new OkObjectResult(result));
            }
            catch (Exception e)
            {
                _logger.LogError(e, "Get");
                ModelState.AddErrorToModelState(e);
                return(BadRequest(ModelState));
            }
        }
Esempio n. 6
0
        public async Task <IActionResult> GetMovies([FromQuery] MovieRequest movieRequest)
        {
            _logger.LogInformation("GetMovies");
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }
                var result = await _applicationDbContext.GetMovieInfos(movieRequest);

                return(new OkObjectResult(result));
            }
            catch (Exception e)
            {
                _logger.LogError(e, "GetMovies");
                ModelState.AddErrorToModelState(e);
                return(BadRequest(ModelState));
            }
        }
Esempio n. 7
0
        public async Task <IActionResult> Post([FromBody] CartViewModel vm)
        {
            _logger.LogInformation("Post");
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }
                await _applicationDbContext.AddCartItem(GetCustomer().Id, vm);

                return(Ok());
            }
            catch (Exception e)
            {
                _logger.LogError(e, "Post");
                ModelState.AddErrorToModelState(e);
                return(BadRequest(ModelState));
            }
        }