示例#1
0
 public ActionResult Create(ClientViewModel client)
 {
     if (ModelState.IsValid)
     {
         var clientDomain = Mapper.Map <ClientViewModel, Client>(client);
         _clientAppService.Add(clientDomain);
         return(RedirectToAction("Index"));
     }
     return(View(client));
 }
示例#2
0
        public ActionResult Create(ClientAddressViewModel clientAddressViewModel)
        {
            if (ModelState.IsValid)
            {
                _clientAppService.Add(clientAddressViewModel);
                return(RedirectToAction("Index"));
            }

            return(View(clientAddressViewModel));
        }
示例#3
0
        public IActionResult Create(ClientViewModel model)
        {
            try
            {
                var bank = appService.Add(model);

                return(Created($"api/[controller]/{model.Id}", new ResponceViewModel <ClientViewModel>(model)));
            }
            catch (Exception ex)
            {
                logger.LogError($"Exception thrown in Create client: {ex}");
                return(BadRequest(new ResponceViewModel <string>($"Create client failed. {ex.Message}")));
            }
        }
        public ActionResult Create(ClientViewModel clientViewModel)
        {
            if (ModelState.IsValid)
            {
                var client = _mapper.Map <Client>(clientViewModel);

                client.Created = DateTime.Now;

                _serviceApp.Add(client);

                return(RedirectToAction("Index"));
            }

            return(View(clientViewModel));
        }
        public IActionResult Create([FromBody] ClientModel clientModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var client = clientService.Add(mapper.Map <Client>(clientModel));

            if (client == 1)
            {
                return(Created("Create", clientModel));
            }
            else
            {
                return(BadRequest(clientModel));
            }
        }
示例#6
0
        public async Task <ActionResult> Create(
            [Bind(Include = "ClientId,Name,Email,Phone")]
            ClientViewModel clientViewModel)
        {
            if (ModelState.IsValid)
            {
                var result = clientAppService.Add(clientViewModel);
                if (!result.IsValid)
                {
                    foreach (var validationAppError in result.Errors)
                    {
                        ModelState.AddModelError(string.Empty, validationAppError.Message);
                    }
                    return(View(clientViewModel));
                }

                // TODO: check if this should be the action to redirect to
                return(RedirectToAction(nameof(Index)));
            }

            return(View(clientViewModel));
        }