using System.Collections.Generic; using System.Security.Claims; using System.Threading.Tasks; using Microsoft.AspNet.Mvc; using Microsoft.Data.Entity; using Yavsc.Models; using YavscLib; using System.Linq; namespace Yavsc.Controllers.Generic { public abstract class SettingsController : Controller where TSettings : class, ISpecializationSettings, new() { protected ApplicationDbContext _context; protected object dbSet; protected IQueryable QueryableDbSet { get { return (IQueryable) dbSet; } } protected ISet RwDbSet { get { return (ISet) dbSet; } } public SettingsController(ApplicationDbContext context) { _context = context; dbSet=_context.GetDbSet(); } public async Task Index() { var existing = await this.QueryableDbSet.SingleOrDefaultAsync(p=>p.UserId == User.GetUserId()); return View(existing); } // GET: BrusherProfile/Details/5 public async Task Details(string id) { if (id == null) { id = User.GetUserId(); } var profile = await QueryableDbSet.SingleAsync(m => m.UserId == id); if (profile == null) { return HttpNotFound(); } return View(profile); } // GET: BrusherProfile/Create public IActionResult Create() { return View(); } // GET: BrusherProfile/Edit/5 public async Task Edit(string id) { if (id == null) { id = User.GetUserId(); } TSettings setting = await QueryableDbSet.SingleOrDefaultAsync(m => m.UserId == id); if (setting == null) { setting = new TSettings { }; } return View(setting); } // GET: BrusherProfile/Delete/5 [ActionName("Delete")] public async Task Delete(string id) { if (id == null) { return HttpNotFound(); } var brusherProfile = await QueryableDbSet.SingleAsync(m => m.UserId == id); if (brusherProfile == null) { return HttpNotFound(); } return View(brusherProfile); } // POST: BrusherProfile/Delete/5 [HttpPost, ActionName("Delete")] [ValidateAntiForgeryToken] public abstract Task DeleteConfirmed(string id); // POST: BrusherProfile/Edit/5 [HttpPost] [ValidateAntiForgeryToken] public abstract Task Edit(TSettings profile); } }