Ejemplo n.º 1
0
        public async Task <IActionResult> Create(OwnerCreateDTO ownerCreateDTO)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(ownerCreateDTO));
                }
                Owner owner = new Owner
                {
                    FirstName  = ownerCreateDTO.FirstName,
                    LastName   = ownerCreateDTO.LastName,
                    Patronymic = ownerCreateDTO.Patronymic
                };
                var result = await _ownerService.CreateAsync(owner);

                if (result == -1)
                {
                    ModelState.AddModelError("", "Error create");
                    return(View(ownerCreateDTO));
                }
                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                return(View("Error", ex));
            }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Create(OwnerCreateDTO ownerCreateDTO)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    Owner owner = new Owner
                    {
                        FirstName  = ownerCreateDTO.FirstName,
                        LastName   = ownerCreateDTO.LastName,
                        Patronymic = ownerCreateDTO.Patronymic
                    };
                    var result = await _ownerService.CreateAsync(owner);

                    if (result == -1)
                    {
                        return(BadRequest("Error create"));
                    }
                    return(Ok(owner));
                }
                return(BadRequest(ModelState));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
        public async Task <int> Post([FromBody] OwnerDto owner)
        {
            var id = await _ownerService.CreateAsync(owner.Name);

            return(id);
        }