コード例 #1
0
        public async Task <IActionResult> Create([Bind("EventId")] UserEvent userEvent)
        {
            var identidade = _userManager.GetUserId(User);
            int id         = userEvent.EventId;

            if (_baseContext.EvenEventExists(id, identidade))
            {
                return(RedirectToAction(nameof(Index)));
            }

            if (ModelState.IsValid)
            {
                userEvent.UserId = identidade;

                var post = _baseApi.Consumer.PostAsJsonAsync <UserEvent>("api/UserEventsApi", userEvent);
                post.Wait();

                var result = post.Result;
                if (result.IsSuccessStatusCode)
                {
                    return(RedirectToAction("Index"));
                }

                if (_baseContext.EventCount(id))
                {
                    return(View(ViewBag.Text = "Limit number reached"));
                }

                if (_baseContext.EventCountMore(id))
                {
                    return(RedirectToAction(nameof(Index)));
                }

                if (!_baseContext.EventCountMore(id))
                {
                    return(RedirectToAction(nameof(Index)));
                }

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["EventId"] = new SelectList(_context.Events, "Id", "Id", userEvent.EventId);
            return(View(userEvent));
        }