Esempio n. 1
0
        public async Task <IActionResult> SignUp(SignUpRequest signUpRequest)
        {
            var response = new BaseResponse <SignInResponse>();

            if (!ModelState.IsValid)
            {
                var validationErrors = _validationHelper.GetValidationErrors(ModelState);
                response.Errors = validationErrors;
                return(BadRequest(response));
            }

            var errors = await _customerService.Create(signUpRequest, _userManager, _roleManager);

            if (errors == null)
            {
                response.Message = "Customer created successfully";
                return(Ok(response));
            }

            foreach (var identityError in errors)
            {
                response.Errors.Add(identityError.Description);
            }

            response.Message = "Customer couldn't be registered";
            return(BadRequest(response));
        }
Esempio n. 2
0
        public async Task <IActionResult> Create([FromBody] ProductRequest productRequest)
        {
            var response = new BaseResponse <ProductResponse> {
                Data = new ProductResponse()
            };

            if (!ModelState.IsValid)
            {
                var validationErrors = _validationHelper.GetValidationErrors(ModelState);
                response.Errors = validationErrors;
                return(BadRequest(response));
            }

            var result = _productService.Create(productRequest);

            if (result != 0)
            {
                response.Data.ProductId = result;
                response.Message        = "Product created successfully";
                return(Ok(response));
            }

            response.Message = "Product could't be created";
            return(BadRequest(response));
        }
Esempio n. 3
0
        public async Task <IActionResult> Create(OrderRequest orderRequest)
        {
            var response = new BaseResponse <OrderResponse>();

            if (!ModelState.IsValid)
            {
                var validationErrors = _validationHelper.GetValidationErrors(ModelState);
                response.Errors = validationErrors;
                return(BadRequest(response));
            }

            if (User.Identity != null)
            {
                var result = await _orderService.Placement(orderRequest.Products, User.Identity.Name);

                if (result)
                {
                    response.Message = "Order created successfully";
                    return(Ok(response));
                }
            }

            return(BadRequest());
        }