public ObjectResult Post([FromBody] string Nickname)
        {
            _logger.LogInformation($"Add reader: {Nickname}");
            string       message;
            ObjectResult result;

            try
            {
                var reader = new Reader {
                    Nickname = Nickname
                };
                //, Books = new List<ReadedBook>() };

                if (!database.Readers.Where(x => x.Nickname == Nickname).Any())
                {
                    database.Readers.Add(reader);
                }
                database.SaveChanges();
                message = "Succesful adding";
                result  = Ok(message);
                _logger.LogInformation(message);
            }
            catch
            {
                message = "Problem with database while adding";
                result  = StatusCode(500, message);
                _logger.LogError(message);
            }
            return(result);
        }
Beispiel #2
0
 public ActionResult Create(Book book)
 {
     if (ModelState.IsValid)
     {
         book.BookAdded = DateTime.Now;
         dbContext.Books.Add(book);
         dbContext.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View());
 }
 public ActionResult Create(User user)
 {
     if (ModelState.IsValid)
     {
         user.UserAdded = new DateTime();
         dbContext.Users.Add(user);
         dbContext.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View());
 }