public async Task <IActionResult> AddDinnerPost(Dinner dinner)
        {
            if (ModelState.IsValid)
            {
                dinner.UserName = User.Identity.Name;
                await _repository.CreateDinnerAsync(dinner);

                return(RedirectToAction("Index", "Home"));
            }
            return(RedirectToAction("Error", "Home"));
        }
Beispiel #2
0
        public async Task <IActionResult> CreateDinnerAsync([FromBody] Dinner dinner)
        {
            //var user = await _userManager.FindByIdAsync(Context.User.GetUserId());
            dinner.UserName = HttpContext.User.Identity.Name;

            GeoLocation.SearchByPlaceNameOrZip(dinner);
            dinner = await _repository.CreateDinnerAsync(dinner);

            var url = Url.RouteUrl("GetDinnerById", new { id = dinner.DinnerId }, Request.Scheme, Request.Host.ToUriComponent());

            HttpContext.Response.StatusCode          = (int)HttpStatusCode.Created;
            HttpContext.Response.Headers["Location"] = url;
            return(new ObjectResult(dinner));
        }