示例#1
0
        public async Task <IActionResult> Create(AmigoCreateViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var result = await _amigoService.CreateAmigoAsync(model);

                    if (result.Succeeded)
                    {
                        return(Redirect(nameof(Index)));
                    }
                    else
                    {
                        ViewBag.alerts = new AlertViewModel {
                            Type = GeneralConstants.ERROR, Text = result.Message
                        };
                    }
                }

                return(View(model));
            }
            catch (Exception ex)
            {
                _logger.LogInformation(ex.Message);
                return(View("Error", new ErrorViewModel {
                    RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier
                }));
            }
        }
示例#2
0
        public async Task <ActionResult <string> > Post([FromBody] AmigoCreate model)
        {
            var result = await _amigoService.CreateAmigoAsync(model);

            if (!result.Succeeded)
            {
                return(NotFound(result.Message));
            }

            return(StatusCode(201));
        }