This commit is contained in:
Paul Schneider 2026-02-14 16:54:27 +00:00
commit 45514010f2
3505 changed files with 154 additions and 523 deletions

View file

@ -0,0 +1,165 @@
using System.Threading.Tasks;
using Yavsc.ViewModels.Auth;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Yavsc.Models;
using Yavsc.Models.Messaging;
using Microsoft.Extensions.Localization;
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.EntityFrameworkCore;
using Yavsc.Server.Helpers;
namespace Yavsc.Controllers
{
public class AnnouncesController : Controller
{
private readonly ApplicationDbContext _context;
readonly IStringLocalizer<AnnouncesController> _localizer;
readonly IAuthorizationService _authorizationService;
public AnnouncesController(ApplicationDbContext context,
IAuthorizationService authorizationService,
IStringLocalizer<AnnouncesController> localizer)
{
_context = context;
_authorizationService = authorizationService;
_localizer = localizer;
}
// GET: Announces
public async Task<IActionResult> Index()
{
return View(await _context.Announce.ToListAsync());
}
// GET: Announces/Details/5
public async Task<IActionResult> Details(long? id)
{
if (id == null)
{
return NotFound();
}
Announce announce = await _context.Announce.SingleAsync(m => m.Id == id);
if (announce == null)
{
return NotFound();
}
return View(announce);
}
// GET: Announces/Create
public async Task<IActionResult> Create()
{
var model = new Announce();
await SetupView(model);
return View(model);
}
private async Task SetupView(Announce announce)
{
ViewBag.IsAdmin = User.IsInMsRole(Constants.AdminGroupName);
ViewBag.IsPerformer = User.IsInMsRole(Constants.PerformerGroupName);
ViewBag.AllowEdit = announce==null || announce.Id<=0 || !_authorizationService.AuthorizeAsync(User,announce,new EditPermission()).IsFaulted;
List<SelectListItem> dl = new List<SelectListItem>();
var rnames = System.Enum.GetNames(typeof(Reason));
var rvalues = System.Enum.GetValues(typeof(Reason));
for (int i = 0; i<rnames.Length; i++) {
dl.Add(new SelectListItem { Text =
_localizer[rnames[i]],
Value= rvalues.GetValue(i).ToString() });
}
ViewBag.For = dl.ToArray();
}
// POST: Announces/Create
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Create(Announce announce)
{
if (ModelState.IsValid)
{
// Only allow admin to create corporate annonces
if (announce.For == Reason.Corporate && ! User.IsInMsRole(Constants.AdminGroupName))
{
ModelState.AddModelError("For", _localizer["YourNotAdmin"]);
return View(announce);
}
// Only allow performers to create ServiceProposal
if (announce.For == Reason.ServiceProposal && ! User.IsInMsRole(Constants.PerformerGroupName))
{
ModelState.AddModelError("For", _localizer["YourNotAPerformer"]);
return View(announce);
}
_context.Announce.Add(announce);
await _context.SaveChangesAsync();
return RedirectToAction("Index");
}
await SetupView(announce);
return View(announce);
}
// GET: Announces/Edit/5
public async Task<IActionResult> Edit(long? id)
{
if (id == null)
{
return NotFound();
}
Announce announce = await _context.Announce.SingleAsync(m => m.Id == id);
if (announce == null)
{
return NotFound();
}
return View(announce);
}
// POST: Announces/Edit/5
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Edit(Announce announce)
{
if (ModelState.IsValid)
{
_context.Update(announce);
await _context.SaveChangesAsync();
return RedirectToAction("Index");
}
return View(announce);
}
// GET: Announces/Delete/5
[ActionName("Delete")]
public async Task<IActionResult> Delete(long? id)
{
if (id == null)
{
return NotFound();
}
Announce announce = await _context.Announce.SingleAsync(m => m.Id == id);
if (announce == null)
{
return NotFound();
}
return View(announce);
}
// POST: Announces/Delete/5
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public async Task<IActionResult> DeleteConfirmed(long id)
{
Announce announce = await _context.Announce.SingleAsync(m => m.Id == id);
_context.Announce.Remove(announce);
await _context.SaveChangesAsync();
return RedirectToAction("Index");
}
}
}

View file

@ -0,0 +1,186 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;
using Yavsc.Models;
using Yavsc.ViewModels.Auth;
using Microsoft.AspNetCore.Mvc.Rendering;
using Yavsc.Models.Blog;
using Yavsc.Helpers;
using Microsoft.Extensions.Options;
using Microsoft.EntityFrameworkCore;
using Yavsc.ViewModels.Blog;
using Yavsc.Server.Exceptions;
using Yavsc.Server.Helpers;
// For more information on enabling Web API for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860
namespace Yavsc.Controllers
{
public class BlogspotController : Controller
{
readonly ILogger _logger;
private readonly ApplicationDbContext _context;
private readonly IAuthorizationService _authorizationService;
readonly RequestLocalizationOptions _localisationOptions;
readonly BlogSpotService blogSpotService;
public BlogspotController(
ApplicationDbContext context,
ILoggerFactory loggerFactory,
IAuthorizationService authorizationService,
IOptions<RequestLocalizationOptions> localisationOptions,
BlogSpotService blogSpotService)
{
_context = context;
_logger = loggerFactory.CreateLogger<AccountController>();
_authorizationService = authorizationService;
_localisationOptions = localisationOptions.Value;
this.blogSpotService = blogSpotService;
}
// GET: Blog
[AllowAnonymous]
public async Task<IActionResult> Index(string id, int skip = 0, int take = 25)
{
if (!string.IsNullOrEmpty(id))
{
return View("UserPosts",
await blogSpotService.UserPosts(id, User.GetUserId(),
skip, take));
}
IEnumerable<IBlogPost> index = await this.blogSpotService.Index(User, id, skip, take);
return View(index);
}
[Route("~/Title/{id?}")]
[AllowAnonymous]
[HttpGet]
public IActionResult Title(string id)
{
ViewData["Title"] = id;
return View("Title", blogSpotService.GetTitle(id));
}
private async Task<IEnumerable<BlogPost>> UserPosts(string userName, int pageLen = 10, int pageNum = 0)
{
return await blogSpotService.UserPosts(userName, User.GetUserId(), pageLen, pageNum);
}
// GET: Blog/Details/5
[AllowAnonymous]
public async Task<IActionResult> Details(long? id)
{
if (id == null) return this.NotFound();
try
{
var blog = await blogSpotService.Details(User, id.Value);
ViewData["apicmtctlr"] = "/api/blogcomments";
ViewData["moderatoFlag"] = User.IsInMsRole(Constants.BlogModeratorGroupName);
return View(blog);
}
catch (AuthorizationFailureException ex)
{
return Challenge();
}
}
void SetLangItems()
{
ViewBag.LangItems = _localisationOptions.SupportedUICultures?.Select
(
sc => new SelectListItem { Value = sc.IetfLanguageTag, Text = sc.NativeName, Selected = System.Globalization.CultureInfo.CurrentUICulture == sc }
);
}
// GET: Blog/Create
[Authorize()]
public IActionResult Create(string title)
{
var result = new BlogPostCreateViewModel
{
Title = title
};
SetLangItems();
return View(result);
}
// POST: Blog/Create
[HttpPost, Authorize, ValidateAntiForgeryToken]
public IActionResult Create(BlogPostEditViewModel blogInput)
{
if (ModelState.IsValid)
{
BlogPost post = blogSpotService.Create(User.GetUserId(),
BlogPostEditViewModel.FromViewModel(blogInput));
return RedirectToAction("Index");
}
return View("Edit", blogInput);
}
[Authorize()]
// GET: Blog/Edit/5
public async Task<IActionResult> Edit(long? id)
{
if (id == null)
{
return NotFound();
}
try
{
var blog = await blogSpotService.GetPostForEdition(User, id.Value);
if (blog == null)
{
return NotFound();
}
SetLangItems();
return View(blog);
}
catch (AuthorizationFailureException)
{
return new ChallengeResult();
}
}
// POST: Blog/Edit/5
[HttpPost]
[ValidateAntiForgeryToken, Authorize()]
public async Task<IActionResult> Edit(BlogPostEditViewModel blogEdit)
{
if (ModelState.IsValid)
{
await blogSpotService.Modify(User, blogEdit);
ViewData["StatusMessage"] = "Post modified";
return RedirectToAction("Index");
}
return View(blogEdit);
}
// GET: Blog/Delete/5
[ActionName("Delete"), Authorize()]
public async Task<IActionResult> Delete(long? id)
{
if (id == null)
{
return NotFound();
}
var blog = await blogSpotService.GetBlogPostAsync(id.Value);
if (blog == null)
{
return NotFound();
}
return View(blog);
}
// POST: Blog/Delete/5
[HttpPost, ActionName("Delete"), Authorize("TheAuthor")]
[ValidateAntiForgeryToken]
public async Task<IActionResult> DeleteConfirmed(long id)
{
await blogSpotService.Delete(User, id);
return RedirectToAction("Index");
}
}
}

View file

@ -0,0 +1,139 @@
using System.Security.Claims;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Yavsc.Helpers;
using Yavsc.Models;
using Yavsc.Models.Relationship;
using Yavsc.Server.Helpers;
namespace Yavsc.Controllers
{
public class CircleController : Controller
{
private readonly ApplicationDbContext _context;
public CircleController(ApplicationDbContext context)
{
_context = context;
}
// GET: Circle
public async Task<IActionResult> Index()
{
return View(await _context.Circle.Where(c=>c.OwnerId==User.GetUserId()).ToListAsync());
}
// GET: Circle/Details/5
public async Task<IActionResult> Details(long? id)
{
if (id == null)
{
return NotFound();
}
Circle circle = await _context.Circle.SingleAsync(m => m.Id == id);
if (circle == null)
{
return NotFound();
}
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
if (uid != circle.OwnerId) return this.Unauthorized();
return View(circle);
}
// GET: Circle/Create
public IActionResult Create()
{
return View(new Circle { OwnerId = User.GetUserId() } );
}
// POST: Circle/Create
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Create(Circle circle)
{
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
if (ModelState.IsValid)
{
if (uid != circle.OwnerId)
return this.Unauthorized();
_context.Circle.Add(circle);
await _context.SaveChangesAsync(uid);
return RedirectToAction("Index");
}
return View(circle);
}
// GET: Circle/Edit/5
public async Task<IActionResult> Edit(long? id)
{
if (id == null)
{
return NotFound();
}
Circle circle = await _context.Circle.SingleAsync(m => m.Id == id);
if (circle == null)
{
return NotFound();
}
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
if (uid != circle.OwnerId)
return Unauthorized();
return View(circle);
}
// POST: Circle/Edit/5
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Edit(Circle circle)
{
if (ModelState.IsValid)
{
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
if (uid != circle.OwnerId) return Unauthorized();
_context.Update(circle);
await _context.SaveChangesAsync(uid);
return RedirectToAction("Index");
}
return View(circle);
}
// GET: Circle/Delete/5
[ActionName("Delete")]
public async Task<IActionResult> Delete(long? id)
{
if (id == null)
{
return NotFound();
}
Circle circle = await _context.Circle.SingleAsync(m => m.Id == id);
if (circle == null)
{
return NotFound();
}
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
if (uid != circle.OwnerId) return Unauthorized();
return View(circle);
}
// POST: Circle/Delete/5
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public async Task<IActionResult> DeleteConfirmed(long id)
{
Circle circle = await _context.Circle.SingleAsync(m => m.Id == id);
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
if (uid != circle.OwnerId) return Unauthorized();
_context.Circle.Remove(circle);
await _context.SaveChangesAsync(uid);
return RedirectToAction("Index");
}
}
}

View file

@ -0,0 +1,136 @@
using System.Security.Claims;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.EntityFrameworkCore;
using Yavsc.Helpers;
using Yavsc.Models;
using Yavsc.Models.Relationship;
using Yavsc.Server.Helpers;
namespace Yavsc.Controllers
{
public class CircleMembersController : Controller
{
private readonly ApplicationDbContext _context;
public CircleMembersController(ApplicationDbContext context)
{
_context = context;
}
// GET: CircleMembers
public async Task<IActionResult> Index()
{
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
var applicationDbContext = _context.CircleMembers.Include(c => c.Circle).Include(c => c.Member)
.Where(c=>c.Circle.OwnerId == uid);
return View(await applicationDbContext.ToListAsync());
}
// GET: CircleMembers/Details/5
public async Task<IActionResult> Details(long id)
{
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
CircleMember circleMember = await _context.CircleMembers
.Include(m=>m.Circle)
.FirstOrDefaultAsync(c=>c.CircleId == id);
if (circleMember == null)
{
return NotFound();
}
return View(circleMember);
}
// GET: CircleMembers/Create
public IActionResult Create()
{
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
ViewBag.CircleId = new SelectList(_context.Circle.Where(c=>c.OwnerId == uid), "Id", "Name");
ViewBag.MemberId = new SelectList(_context.Users, "Id", "UserName");
return View();
}
// POST: CircleMembers/Create
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Create(CircleMember circleMember)
{
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
var circle = _context.Circle.SingleOrDefault(c=>c.OwnerId == uid && c.Id == circleMember.CircleId);
if (circle==null)
return new BadRequestResult();
if (ModelState.IsValid)
{
_context.CircleMembers.Add(circleMember);
await _context.SaveChangesAsync(User.GetUserId());
return RedirectToAction("Index");
}
ViewData["CircleId"] = new SelectList(_context.Circle, "Id", "Name", circleMember.CircleId);
ViewData["MemberId"] = new SelectList(_context.Users, "Id", "UserName", circleMember.MemberId);
return View(circleMember);
}
// GET: CircleMembers/Edit/5
public async Task<IActionResult> Edit(long id)
{
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
CircleMember circleMember = await _context.CircleMembers
.Include(m=>m.Member)
.SingleOrDefaultAsync(m => m.CircleId == id && m.MemberId == uid);
if (circleMember == null)
{
return NotFound();
}
return View(circleMember);
}
// POST: CircleMembers/Edit/5
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Edit(CircleMember circleMember)
{
if (ModelState.IsValid)
{
_context.Update(circleMember);
await _context.SaveChangesAsync(User.GetUserId());
return RedirectToAction("Index");
}
ViewData["CircleId"] = new SelectList(_context.Circle, "Id", "Circle", circleMember.CircleId);
ViewData["MemberId"] = new SelectList(_context.Users, "Id", "Member", circleMember.MemberId);
return View(circleMember);
}
// GET: CircleMembers/Delete/5
[ActionName("Delete")]
public async Task<IActionResult> Delete(long id)
{
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
CircleMember circleMember = await _context.CircleMembers
.Include(m=>m.Circle)
.Include(m=>m.Member)
.SingleOrDefaultAsync(m => m.CircleId == id && m.MemberId == uid);
if (circleMember == null)
{
return NotFound();
}
return View(circleMember);
}
// POST: CircleMembers/Delete/5
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public async Task<IActionResult> DeleteConfirmed(long id)
{
CircleMember circleMember = await _context.CircleMembers.SingleAsync(m => m.CircleId == id);
_context.CircleMembers.Remove(circleMember);
await _context.SaveChangesAsync(User.GetUserId());
return RedirectToAction("Index");
}
}
}

View file

@ -0,0 +1,133 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.EntityFrameworkCore;
using Yavsc.Helpers;
using Yavsc.Models;
using Yavsc.Models.Blog;
using Yavsc.Server.Helpers;
namespace Yavsc.Controllers
{
/// <summary>
/// Comment some post.
/// </summary>
public class CommentsController : Controller
{
private readonly ApplicationDbContext _context;
public CommentsController(ApplicationDbContext context)
{
_context = context;
}
// GET: Comments
public async Task<IActionResult> Index()
{
var applicationDbContext = _context.Comment.Include(c => c.Post);
return View(await applicationDbContext.ToListAsync());
}
// GET: Comments/Details/5
public async Task<IActionResult> Details(long? id)
{
if (id == null)
{
return NotFound();
}
Comment comment = await _context.Comment.SingleAsync(m => m.Id == id);
if (comment == null)
{
return NotFound();
}
return View(comment);
}
// GET: Comments/Create
public IActionResult Create()
{
ViewData["ReceiverId"] = new SelectList(_context.BlogSpot, "Id", "Post");
return View();
}
// POST: Comments/Create
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Create(Comment comment)
{
comment.UserCreated = User.GetUserId();
if (ModelState.IsValid)
{
_context.Comment.Add(comment);
await _context.SaveChangesAsync();
return RedirectToAction("Index");
}
ViewData["ReceiverId"] = new SelectList(_context.BlogSpot, "Id", "Post", comment.ReceiverId);
return View(comment);
}
// GET: Comments/Edit/5
public async Task<IActionResult> Edit(long? id)
{
if (id == null)
{
return NotFound();
}
Comment comment = await _context.Comment.SingleAsync(m => m.Id == id);
if (comment == null)
{
return NotFound();
}
ViewData["ReceiverId"] = new SelectList(_context.BlogSpot, "Id", "Post", comment.ReceiverId);
return View(comment);
}
// POST: Comments/Edit/5
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Edit(Comment comment)
{
if (ModelState.IsValid)
{
_context.Update(comment);
await _context.SaveChangesAsync();
return RedirectToAction("Index");
}
ViewData["ReceiverId"] = new SelectList(_context.BlogSpot, "Id", "Post", comment.ReceiverId);
return View(comment);
}
// GET: Comments/Delete/5
[ActionName("Delete")]
public async Task<IActionResult> Delete(long? id)
{
if (id == null)
{
return NotFound();
}
Comment comment = await _context.Comment.SingleAsync(m => m.Id == id);
if (comment == null)
{
return NotFound();
}
return View(comment);
}
// POST: Comments/Delete/5
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public async Task<IActionResult> DeleteConfirmed(long id)
{
Comment comment = await _context.Comment.SingleAsync(m => m.Id == id);
_context.Comment.Remove(comment);
await _context.SaveChangesAsync();
return RedirectToAction("Index");
}
}
}

View file

@ -0,0 +1,75 @@
using System.Security.Claims;
using Microsoft.AspNetCore.Mvc;
namespace Yavsc.Controllers
{
using Microsoft.EntityFrameworkCore;
using Models;
using Models.Identity;
public class DevicesController : Controller
{
private readonly ApplicationDbContext _context;
public DevicesController(ApplicationDbContext context)
{
_context = context;
}
// GET: GCMDevices
public async Task<IActionResult> Index()
{
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
var applicationDbContext = _context.DeviceDeclaration.Include(g => g.DeviceOwner).Where(d=>d.DeviceOwnerId == uid);
return View(await applicationDbContext.ToListAsync());
}
// GET: GCMDevices/Details/5
public async Task<IActionResult> Details(string id)
{
if (id == null)
{
return NotFound();
}
DeviceDeclaration googleCloudMobileDeclaration = await _context.DeviceDeclaration.SingleAsync(m => m.DeviceId == id);
if (googleCloudMobileDeclaration == null)
{
return NotFound();
}
return View(googleCloudMobileDeclaration);
}
// GET: GCMDevices/Delete/5
[ActionName("Delete")]
public async Task<IActionResult> Delete(string id)
{
if (id == null)
{
return NotFound();
}
DeviceDeclaration googleCloudMobileDeclaration = await _context.DeviceDeclaration.SingleAsync(m => m.DeviceId == id);
if (googleCloudMobileDeclaration == null)
{
return NotFound();
}
return View(googleCloudMobileDeclaration);
}
// POST: GCMDevices/Delete/5
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public async Task<IActionResult> DeleteConfirmed(string id)
{
DeviceDeclaration googleCloudMobileDeclaration = await _context.DeviceDeclaration.SingleAsync(m => m.DeviceId == id);
_context.DeviceDeclaration.Remove(googleCloudMobileDeclaration);
await _context.SaveChangesAsync();
return RedirectToAction("Index");
}
}
}

View file

@ -0,0 +1,128 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Yavsc.Models;
using Yavsc.Models.Relationship;
namespace Yavsc.Controllers
{
[Authorize("AdministratorOnly")]
public class HyperLinkController : Controller
{
private readonly ApplicationDbContext _context;
public HyperLinkController(ApplicationDbContext context)
{
_context = context;
}
// GET: HyperLink
public async Task<IActionResult> Index()
{
return View(await _context.HyperLink.ToListAsync());
}
// GET: HyperLink/Details/5
public async Task<IActionResult> Details(string href, string method)
{
if (href == null || method ==null)
{
return NotFound();
}
HyperLink hyperLink = await _context.HyperLink.SingleAsync(m => m.HRef == href && m.Method == method);
if (hyperLink == null)
{
return NotFound();
}
return View(hyperLink);
}
// GET: HyperLink/Create
public IActionResult Create()
{
return View();
}
// POST: HyperLink/Create
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Create(HyperLink hyperLink)
{
if (ModelState.IsValid)
{
_context.HyperLink.Add(hyperLink);
await _context.SaveChangesAsync();
return RedirectToAction("Index");
}
return View(hyperLink);
}
// GET: HyperLink/Edit/5
public async Task<IActionResult> Edit(string href, string method)
{
if (href == null || method ==null)
{
return NotFound();
}
HyperLink hyperLink = await _context.HyperLink.SingleAsync(m => m.HRef == href && m.Method == method);
if (hyperLink == null)
{
return NotFound();
}
return View(hyperLink);
}
// POST: HyperLink/Edit/5
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Edit(HyperLink hyperLink)
{
if (ModelState.IsValid)
{
_context.Update(hyperLink);
await _context.SaveChangesAsync();
return RedirectToAction("Index");
}
return View(hyperLink);
}
// GET: HyperLink/Delete/5
[ActionName("Delete")]
public async Task<IActionResult> Delete(string href, string method)
{
if (href == null || method ==null)
{
return NotFound();
}
HyperLink hyperLink = await _context.HyperLink.SingleAsync(m => m.HRef == href && m.Method == method);
if (hyperLink == null)
{
return NotFound();
}
return View(hyperLink);
}
// POST: HyperLink/Delete/5
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public async Task<IActionResult> DeleteConfirmed(string HRef, string Method)
{
if (HRef == null || Method ==null)
{
return NotFound();
}
HyperLink hyperLink = await _context.HyperLink.SingleAsync(m => m.HRef == HRef && m.Method == Method);
_context.HyperLink.Remove(hyperLink);
await _context.SaveChangesAsync();
return RedirectToAction("Index");
}
}
}

View file

@ -0,0 +1,122 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Yavsc.Abstract.Models.Messaging;
using Yavsc.Helpers;
using Yavsc.Models;
using Yavsc.Models.Messaging;
using Yavsc.Server.Helpers;
namespace Yavsc.Controllers
{
public class NotificationsController : Controller
{
private readonly ApplicationDbContext _context;
public NotificationsController(ApplicationDbContext context)
{
_context = context;
}
// GET: Notifications
public async Task<IActionResult> Index()
{
return View(await _context.Notification.ToListAsync());
}
// GET: Notifications/Details/5
public async Task<IActionResult> Details(long? id)
{
if (id == null)
{
return NotFound();
}
Notification notification = await _context.Notification.SingleAsync(m => m.Id == id);
if (notification == null)
{
return NotFound();
}
return View(notification);
}
// GET: Notifications/Create
public IActionResult Create()
{
return View();
}
// POST: Notifications/Create
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Create(Notification notification)
{
if (ModelState.IsValid)
{
_context.Notification.Add(notification);
await _context.SaveChangesAsync(User.GetUserId());
return RedirectToAction("Index");
}
return View(notification);
}
// GET: Notifications/Edit/5
public async Task<IActionResult> Edit(long? id)
{
if (id == null)
{
return NotFound();
}
Notification notification = await _context.Notification.SingleAsync(m => m.Id == id);
if (notification == null)
{
return NotFound();
}
return View(notification);
}
// POST: Notifications/Edit/5
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Edit(Notification notification)
{
if (ModelState.IsValid)
{
_context.Update(notification);
await _context.SaveChangesAsync(User.GetUserId());
return RedirectToAction("Index");
}
return View(notification);
}
// GET: Notifications/Delete/5
[ActionName("Delete")]
public async Task<IActionResult> Delete(long? id)
{
if (id == null)
{
return NotFound();
}
Notification notification = await _context.Notification.SingleAsync(m => m.Id == id);
if (notification == null)
{
return NotFound();
}
return View(notification);
}
// POST: Notifications/Delete/5
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public async Task<IActionResult> DeleteConfirmed(long id)
{
Notification notification = await _context.Notification.SingleAsync(m => m.Id == id);
_context.Notification.Remove(notification);
await _context.SaveChangesAsync(User.GetUserId());
return RedirectToAction("Index");
}
}
}