示例#1
0
        public async Task <IActionResult> Login(Login dto)
        {
            var validator = new LoginFluentValidator();
            var errors    = await validator.ValidateAsync(dto);

            if (!errors.IsValid)
            {
                return(UnprocessableEntity(ValidationFormatter.Format(errors)));
            }

            try {
                string token = await _loginService.Login(dto);

                HttpContext
                .Response
                .Cookies
                .Append("token", token, new CookieOptions {
                    HttpOnly = true
                });

                return(Ok(new { message = "You have succesfully logged in.", token }));
            } catch (EntityNotFoundException e) {
                return(NotFound(new { message = e.Message }));
            } catch (PasswordNotValidException e) {
                return(BadRequest(new { message = e.Message }));
            } catch (Exception) {
                return(StatusCode(500, new { ServerErrorResponse.Message }));;
            }
        }
        public async Task <IActionResult> Post([FromBody] CreateDeveloperDTO dto)
        {
            var validator = new DeveloperFluentValidatior(_context);
            var errors    = await validator.ValidateAsync(dto);

            if (!errors.IsValid)
            {
                return(UnprocessableEntity(ValidationFormatter.Format(errors)));
            }

            try {
                await _developerService.Create(dto);

                return(StatusCode(201));
            } catch (Exception) {
                return(StatusCode(500, new { ServerErrorResponse.Message }));
            }
        }
示例#3
0
        public async Task <IActionResult> Post([FromForm] CreateGameDTO dto)
        {
            var validator = new GameFluentValidator(_context);
            var errors    = await validator.ValidateAsync(dto);

            if (!errors.IsValid)
            {
                return(UnprocessableEntity(ValidationFormatter.Format(errors)));
            }

            try {
                await _gamesService.Create(dto);

                return(StatusCode(201));
            } catch (Exception e) {
                var s = 2;
                return(StatusCode(500, e));
            }
        }
        public async Task <IActionResult> Put(int id, [FromBody] CreateDeveloperDTO dto)
        {
            var validator = new DevelopUpdateFluentValidator(_context, id);
            var errors    = await validator.ValidateAsync(dto);

            if (!errors.IsValid)
            {
                return(UnprocessableEntity(ValidationFormatter.Format(errors)));
            }

            try {
                await _developerService.Update(id, dto);

                return(NoContent());
            } catch (EntityNotFoundException e) {
                return(NotFound(e.Message));
            } catch (Exception) {
                return(StatusCode(500, new { ServerErrorResponse.Message }));
            }
        }
示例#5
0
        public async Task <IActionResult> Put(int id, [FromForm] CreateGameDTO dto)
        {
            var validator = new GameUpdateFluentValidator(_context, id);
            var errors    = await validator.ValidateAsync(dto);

            if (!errors.IsValid)
            {
                return(UnprocessableEntity(ValidationFormatter.Format(errors)));
            }

            try {
                await _gamesService.Update(id, dto);

                return(NoContent());
            } catch (EntityNotFoundException e) {
                return(NotFound(new { message = e.Message }));
            } catch (Exception) {
                return(StatusCode(500, new { message = "Server error, please try later." }));
            }
        }
示例#6
0
        public async Task <IActionResult> Post([FromForm] CreateGameDTO dto)
        {
            var validator = new GameFluentValidator(_context);
            var errors    = await validator.ValidateAsync(dto);

            if (!errors.IsValid)
            {
                return(UnprocessableEntity(ValidationFormatter.Format(errors)));
            }

            try
            {
                var user = Int32.Parse(HttpContext.User.FindFirst("id").Value);
                dto.UserId = user;
                await _gamesService.Create(dto);

                return(StatusCode(201));
            } catch (Exception e)
            {
                return(StatusCode(500, e));
            }
        }
        public async Task <IActionResult> Register(Register dto)
        {
            var validator = new RegisterFluentValidator(_context);
            var errors    = await validator.ValidateAsync(dto);

            if (!errors.IsValid)
            {
                return(UnprocessableEntity(ValidationFormatter.Format(errors)));
            }

            try {
                var user = await _registerService.Register(dto);

                _emailService.Body    = "You have succcessfully registered.";
                _emailService.Subject = "Registration mail";
                _emailService.ToEmail = user.Email;
                _emailService.Send();
                //EMAIL
                return(StatusCode(201));
            } catch (Exception) {
                return(StatusCode(500, new { ServerErrorResponse.Message }));
            }
        }