Ejemplo n.º 1
0
        public ActionResult Create(AddCustomerVM customer)
        {
            try
            {
                if (!customer.IsValid())
                {
                    //todo: create custom exceptions
                    return(new JsonResult()
                    {
                    });
                }


                var customerDTO = customer.FillDTO(customer);

                // call application service
                _customerAppService.AddNewCustomer(customerDTO);


                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> AddCustomer([FromBody] AddCustomerVM customerVM)
        {
            if (!string.IsNullOrEmpty(customerVM.Email))
            {
                customerVM.Email = customerVM.Email.ToLower();
            }
            if (await _customerService.CustomerExists(customerVM.Email))
            {
                ModelState.AddModelError("Email", "Email is already taken");
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var Create = _mapper.Map <Customer>(customerVM);

            _customerService.Add(Create);
            if (await _customerService.SaveAll())
            {
                return(Ok("Customer Created Successfully"));
            }
            return(BadRequest("Failed to create customer"));
        }
 public AddCustomerPage()
 {
     InitializeComponent();
     BindingContext = new AddCustomerVM();
 }