Esempio n. 1
0
 public ActionResult AddTheme(int id)
 {
     if (!Roles.IsUserInRole("admin"))
     {
         var isExist = repository.Themes.Where(t => t.UserId == WebSecurity.CurrentUserId).OrderByDescending(t => t.CreationDate).FirstOrDefault();
         if (isExist != null)
         {
             if ((DateTime.Now - isExist.CreationDate).TotalMinutes < 60)
             {
                 TempData["failure"] = "Новую тему можно создать один раз в час.";
                 return RedirectToAction("Section", new { id = id, page = 1 });
             }
         }
     }
     var model = new AddThemeModel {
         UserId = (int)WebSecurity.CurrentUserId,
         SectionId = id
     };
     return View(model);
 }
Esempio n. 2
0
 public ActionResult AddTheme(AddThemeModel theme)
 {
     if (ModelState.IsValid)
     {
         var themeToAdd = new Theme
         {
             SectionId = theme.SectionId,
             UserId = theme.UserId,
             ThemeTitle = theme.ThemeTitle,
             ThemeText = theme.ThemeText,
             CreationDate = DateTime.Now
         };
         repository.AddTheme(themeToAdd);
         TempData["success"] = "Новая тема успешно создана.";
     }
     else
     {
         return View(theme);
     }
     return RedirectToAction("Section", "Forum", new { id = theme.SectionId });
 }