Пример #1
0
        public ActionResult Add()
        {
            AddBlogVm vm = new AddBlogVm
            {
                Categories = this.blogService.GetAllCategories()
            };

            return(this.View(vm));
        }
Пример #2
0
        public IHttpActionResult AddBlogEntity(AddBlogVm d)
        {
            var blog = new Blog()
            {
                Text = d.Text, CreatedBy = d.CreatedBy, CreationDate = DateTime.Now
            };

            repo.Add(blog);
            repo.SaveChanges();
            return(Ok(blog));
        }
Пример #3
0
 public ActionResult Add(AddBlogBm bm)
 {
     if (!this.ModelState.IsValid)
     {
         return(this.View(bm));
     }
     try
     {
         var strCurrentUserId = User.Identity.GetUserId();
         this.service.AddBlog(bm, strCurrentUserId);
         return(this.RedirectToAction("All"));
     }
     catch (DbEntityValidationException ex)
     {
         var error = ex.EntityValidationErrors.First().ValidationErrors.First();
         this.ModelState.AddModelError(error.PropertyName, error.ErrorMessage);
         AddBlogVm vm = new AddBlogVm
         {
             Categories = this.blogService.GetAllCategories()
         };
         return(this.View(vm));
     }
 }