Beispiel #1
0
        public async Task <IActionResult> Create(Beer beer)
        {
            CreateBeer model = new CreateBeer(context);

            context.Add(beer);
            await context.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Beispiel #2
0
        public async Task <IActionResult> CreateBeer([FromBody] CreateBeer createDTO)
        {
            try
            {
                var userId = HttpContext.User.FindFirst("http://schemas.microsoft.com/identity/claims/objectidentifier").Value;

                if (createDTO == null)
                {
                    return(BadRequest(new ValidationErrorResponse(new ValidationErrorModel("Name", "Beer cannot be null."))));
                }

                var entityToCreate = _mapper.Map <Beer>(createDTO);
                entityToCreate.UserId = userId;
                var entity = await _beerService.CreateAsync(entityToCreate);

                var view = _mapper.Map <ViewBeer>(entity);
                return(Ok(view));
            }
            catch
            {
                return(StatusCode(500));
            }
        }
Beispiel #3
0
        public IActionResult Create()
        {
            CreateBeer model = new CreateBeer(context);

            return(View(model));
        }