Пример #1
0
        public IActionResult Save(Customer customer)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new CustomerFormViewModel
                {
                    Customer        = customer,
                    MembershipTypes = _db.MembershipTypes.ToList()
                };

                return(View("CustomerForm", viewModel));
            }


            if (customer.Id == 0)
            {
                _repo.CreateCustomer(customer);
            }
            else
            {
                _repo.UpdateCustomer(customer.Id, customer);
            }

            return(RedirectToAction("Index", "Customers"));
        }
        public override async Task <CreateCustomerResponse> CreateCustomer(CreateCustomerRequest request,
                                                                           ServerCallContext context)
        {
            var id = await repository.CreateCustomer(request.ToCustomer());

            return(new CreateCustomerResponse {
                Id = id.ToString()
            });
        }
Пример #3
0
 public async Task <Customer> Handle(CreateCustomerCommand request, CancellationToken cancellationToken)
 {
     return(await _customersRepository.CreateCustomer(new Customer
     {
         Name = request.Name,
         Address = request.Address,
         EmailAddress = request.EmailAddress,
         PhoneNumber = request.PhoneNumber
     }));
 }
        public IActionResult CreateCustomer(Customer customer)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _repo.CreateCustomer(customer);

            //return new ObjectResult(customer) { StatusCode = 400 };
            return(Created(Url.ActionLink("CreateCustomer", "CustomersController"), customer));
        }
Пример #5
0
        public async Task <IHttpActionResult> CreateCustomer([FromBody] CustomerDto customerDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var customer = await repository.CreateCustomer(customerDto);

            if (customer == null)
            {
                return(BadRequest("Could not create a customer."));
            }

            return(CreatedAtRoute("GetCustomer", new { id = customer.Id }, customer));
        }
Пример #6
0
 public ActionResult Create([Bind(Exclude = "Id")] Customers CustomersToCreate)
 {
     try
     {
         if (ModelState.IsValid)
         {
             _repository.CreateCustomer(CustomersToCreate);
             return(RedirectToAction("Index"));
         }
     }
     catch (Exception ex)
     {
         ModelState.AddModelError("", ex);
         ViewData["CreateError"] = "Unable to create; view innerexception";
     }
     return(View("Create"));
 }
Пример #7
0
        public IActionResult CreateCustomer([FromBody] CustomerDto customer)
        {
            if (customer == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var newCustomer = repository.CreateCustomer(customer);

            var uri = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host}{HttpContext.Request.Path}/{newCustomer.Id}";

            return(Created(uri, newCustomer));
        }