public IActionResult Update(long id, [FromBody] UpdateCustomerDto item)
        {
            try
            {
                Result <CustomerName> customerNameOrError = CustomerName.Create(item.Name);
                if (customerNameOrError.IsFailure)
                {
                    return(BadRequest(customerNameOrError.Error));
                }

                Customer customer = _customerRepository.GetById(id);
                if (customer == null)
                {
                    return(BadRequest("Invalid customer id: " + id));
                }

                customer.Name = customerNameOrError.Value;

                return(Ok());
            }
            catch (Exception e)
            {
                return(StatusCode(500, new { error = e.Message }));
            }
        }
Exemple #2
0
        public IActionResult Update(long id, [FromBody] UpdateCustomerDto item)
        {
            Result <CustomerName> customerNameOrError = CustomerName.Create(item.Name);

            if (customerNameOrError.IsFailure)
            {
                return(Error(customerNameOrError.Error));
            }

            Customer customer = _customerRepository.GetById(id);

            if (customer == null)
            {
                return(Error("Invalid customer id: " + id));
            }

            customer.Name = customerNameOrError.Value;

            return(Ok());
        }
Exemple #3
0
        public IActionResult UpdateCustomer(long id, UpdateCustomerDto customerModel)
        {
            var customerNameOrError = CustomerName.Create(customerModel.Name);

            if (customerNameOrError.IsFailure)
            {
                return(Error(customerNameOrError.Error));
            }

            var customer = _customerRepository.GetById(id);

            if (customer == null)
            {
                return(Error($"[{id}] is an invalid customer id"));
            }

            customer.Name = customerNameOrError.Value;

            return(Ok(customer));
        }
Exemple #4
0
        public IActionResult Update(long id, [FromBody] UpdateCustomerDto item)
        {
            var customerNameOrError = CustomerName.Create(item.Name);

            if (!customerNameOrError.IsSuccess)
            {
                return(Error(customerNameOrError.Error));
            }

            Customer customer = _customerRepository.GetById(id);

            if (customer == null)
            {
                return(Error($"Invalid customer id: {id}"));
            }

            customer.Name = customerNameOrError.Value;

            return(Ok());
        }
Exemple #5
0
        public IActionResult Update(long id, [FromBody] UpdateCustomerDto item)
        {
            //try
            //{
            Result <CustomerName> customerNameOrError = CustomerName.Create(item.Name);
            Result result = Result.Combine(customerNameOrError);

            if (result.IsFailure)
            {
                //return BadRequest(result.Error);
                return(Error(result.Error));
            }
            //if (!ModelState.IsValid)
            //{
            //    return BadRequest(ModelState);
            //}


            Customer customer = _customerRepository.GetById(id);

            if (customer == null)
            {
                //return BadRequest("Invalid customer id: " + id);
                return(Error("Invalid customer id: " + id));
            }

            customer.Name = customerNameOrError.Value;
            //_customerRepository.SaveChanges();

            return(Ok());
            //}
            //catch (Exception e)
            //{
            //    return StatusCode(500, new { error = e.Message });
            //}
        }