Exemplo n.º 1
0
        public IActionResult Create(BlogCreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                SessionUser user = userSessionService.Get("LoginUser");

                Category category = categoryService.Get(x => x.IsActive == true && x.id == model.Categoryid);
                if (user != null && category != null)
                {
                    Blog blog = new Blog()
                    {
                        Category     = category,
                        Content      = model.Content,
                        Title        = model.Title,
                        Description  = model.Discription,
                        Userid       = user.id,
                        Tags         = model.Tags,
                        CreateUserid = user.id
                    };
                    blogService.Add(blog);
                    blogService.Save();
                }
                else
                {
                    ViewBag.ErrorMassage = "Kritik Hata";
                }
            }
            else
            {
                ViewBag.ErrorMassage = "Tüm bilgileri eksiksiz giriniz.";
            }
            return(View(new BlogCreateViewModel()
            {
                Categories = categoryService.GetMany(x => x.IsActive == true).Select(a =>
                                                                                     new SelectListItem
                {
                    Value = a.id.ToString(),
                    Text = a.Name
                }).ToList(),
                Categoryid = model.Categoryid,
                Content = model.Content,
                Title = model.Title
            }));
        }
Exemplo n.º 2
0
        public IActionResult Logout()
        {
            SessionUser user = userSessionService.Get("LoginUser");

            if (user != null)
            {
                userSessionService.Set(null, "LoginUser");
            }
            return(RedirectToAction("Index", "Home", new { area = "" }));
        }