Exemple #1
0
      public async Task <IActionResult> AddAnswer(QOTDAnswer newAnswer, IFormCollection form)
      {
          if (!ModelState.IsValid)
          {
              return(RedirectToAction("About"));
          }

          int intIdt = _context.QOTDQuestion.Max(u => u.id);

          newAnswer.QuestionID = intIdt + 1;

          List <string> AuthorIds = new List <string> {
          };

          foreach (string item in form["Authors"])
          {
              AuthorIds.Add(item);
          }
          var successful = false;

          if (AuthorIds.Count() <= 1)
          {
              newAnswer.Author = AuthorIds[0];
              successful       = await _todoItemService.AddItemAsync(newAnswer);
          }
          else
          {
              List <QOTDAnswer> allAuthors = new List <QOTDAnswer> ()
              {
              };
              foreach (string author in AuthorIds)
              {
                  newAnswer.Author = author;
                  allAuthors.Add(newAnswer);
                  successful = await _todoItemService.AddItemsAsync(allAuthors);
              }
          }
          if (!successful)
          {
              return(BadRequest("Could not add item."));
          }

          return(RedirectToAction("About", new{ QuestionID = intIdt + 1 }));
      }
Exemple #2
0
        public async Task <IActionResult> AddItem(TodoItem newItem)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Index"));
            }

            var currentuser = await _userManager.GetUserAsync(User);

            if (currentuser == null)
            {
                return(Challenge());
            }

            var successful = await _todoItemService.AddItemsAsync(newItem, currentuser);

            if (!successful)
            {
                return(BadRequest("Could not add Item"));
            }

            return(RedirectToAction("Index"));
        }