Exemplo n.º 1
0
        private void MockAuthors()
        {
            Author author = new Author()
            {
                FirstName = "Fn",
                LastName  = "Ln"
            };

            _author_dal.Add(author);

            Author author2 = new Author()
            {
                FirstName = "Fn2",
                LastName  = "Ln2"
            };

            _author_dal.Add(author2);

            _author_dal.Save();
        }
        [ValidateAntiForgeryToken] // Création d'un nouvel auteur
        public ActionResult Create([Bind(Include = "Name, Firstname")] Author author)
        {
            AuthorDAL dal = new AuthorDAL((List <Author>)Session["Authors"]);

            if (ModelState.IsValid)
            {
                dal.Add(author);
                return(RedirectToAction("Index"));
            }

            return(View(author));
        }
Exemplo n.º 3
0
        public void CreateNewAuthorAndAddToDB()
        {
            Author author = new Author()
            {
                FirstName = "Fn",
                LastName  = "Ln"
            };

            _author_dal.Add(author);

            Author author2 = new Author()
            {
                FirstName = "Fn2",
                LastName  = "Ln2"
            };

            _author_dal.Add(author2);

            _author_dal.Save();

            Assert.AreEqual(2, _author_dal.GetAll().Count);
        }
Exemplo n.º 4
0
 public ActionResult CreateAuthor(Author au)
 {
     using (AuthorDAL service = new AuthorDAL())
     {
         try
         {
             service.Add(au);
             TempData["Message"] = Helper.MsgBox.GetMsg("success", "Success! ", "Your data has been added");
         }
         catch (Exception ex)
         {
             TempData["Message"] = Helper.MsgBox.GetMsg("danger", "Error", ex.Message);
         }
     }
     return(RedirectToAction("Index"));
 }
Exemplo n.º 5
0
        private void GenerateAuthors()
        {
            var random = new Random();

            Session["Authors"] = new List <Author>();

            var dal = new AuthorDAL((List <Author>)Session["Authors"]);

            for (int i = 0; i < random.Next(10, 20); i++)
            {
                Random.Person p = random.NextPerson(Random.AllowedLanguage.FRENCH);
                Author        a = new Author()
                {
                    Firstname = p.FirstName, Name = p.LastName
                };
                dal.Add(a);
            }
        }