예제 #1
0
        public ActionResult Details(BlogPost entite)
        {
            ViewBag.Tags = _tagsRepo.GetTags();
            string nomUsager = Session["LoggedUser"] as string;
            User   usager    = _usersRepo.GetByUserName(nomUsager);

            entite.UserId = usager.UserId;
            if (!ModelState.IsValid)
            {
                return(View(entite));
            }

            TryUpdateModel(entite);
            var tags = Request["Tags"] != null ?
                       Request["Tags"].Split(new[] { "," }, System.StringSplitOptions.RemoveEmptyEntries) :
                       new List <string>().ToArray();
            int resultat;

            if (entite.Id == 0)
            {
                entite.CreateTime = DateTime.Now;
                resultat          = _bloguesRepo.AddBlog(entite, tags);
            }
            else
            {
                resultat = _bloguesRepo.UpdateBlog(entite, tags);
            }

            if (resultat != 0)
            {
                return(RedirectToAction("Index"));
            }
            ModelState.AddModelError(string.Empty, "oops! veuillez réessayer de nouveau!");
            return(View(entite));
        }
        public ViewResult Edit(Blog b, int blogid)
        {
            string      name    = HttpContext.Session.GetString("Name");
            int         id      = PublicUserRepo.GetId(name);
            List <Blog> myBlogs = BlogRepo.getMyBlogs(id);

            if (ModelState.IsValid)
            {
                foreach (Blog bl in myBlogs)
                {
                    if (bl.blog_Id == b.blog_Id)
                    {
                        bl.Title   = b.Title;
                        bl.Content = b.Content;
                        bl.Date    = b.Date;
                        BlogRepo.RemoveBlog(bl.blog_Id);
                        BlogRepo.AddBlog(b, id); //Sath hi database ma b update kr dia h
                        break;
                    }
                }

                return(View("ViewMyBlogs", myBlogs));
            }
            else
            {
                ModelState.AddModelError(String.Empty, "Please enter correct data");
                return(View());
            }
        }
예제 #3
0
        public void CreateBlog_saves_a_blog_via_context()
        {
            var mockSet = new Mock <DbSet <Blog> >();

            var mockContext = new Mock <BloggingContext>();

            mockContext.Setup(m => m.Blogs).Returns(mockSet.Object);

            var service = new BlogRepo(mockContext.Object);

            service.AddBlog("ADO.NET Blog", "http://blogs.msdn.com/adonet");

            mockSet.Verify(m => m.Add(It.IsAny <Blog>()), Times.Once());
            mockContext.Verify(m => m.SaveChanges(), Times.Once());
        }
 public ViewResult CreateBlog(string nam, Blog b)
 {
     b.Date = DateTime.Today.ToString();
     if (ModelState.IsValid)
     {
         string name = HttpContext.Session.GetString("Name");
         int    id   = PublicUserRepo.GetId(name);
         BlogRepo.AddBlog(b, id);
         PublicUser usr = PublicUserRepo.getUserbyId(id);
         return(View("HomePage", usr));
     }
     else
     {
         ModelState.AddModelError(String.Empty, "Please enter correct data");
         return(View());
     }
 }