From 4ae095ccb375a96bd4a5fd79e3d1b34db7a7137f Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Fri, 4 May 2018 13:56:22 +0200 Subject: [PATCH] re-organisation --- .../{ => Accounting}/AccountController.cs | 0 .../{ => Accounting}/ManageController.cs | 0 .../{ => Accounting}/OAuthController.cs | 0 .../{ => Accounting}/UsersController.cs | 0 .../AdministrationController.cs | 0 .../MailingTemplateController.cs | 0 .../AnnouncesController.cs | 0 .../{ => Communicating}/CircleController.cs | 244 ++++---- .../CircleMembersController.cs | 270 ++++----- .../GCMDevicesController.cs | 0 .../{ => Contracting}/ActivityController.cs | 0 .../{ => Contracting}/ClientController.cs | 278 +++++----- .../{ => Contracting}/CoWorkingController.cs | 264 ++++----- .../{ => Contracting}/CommandController.cs | 524 +++++++++--------- .../CommandFormsController.cs | 262 ++++----- .../{ => Contracting}/DjSettingsController.cs | 240 ++++---- .../{ => Contracting}/DoController.cs | 378 ++++++------- .../{ => Contracting}/EstimateController.cs | 440 +++++++-------- .../FormationSettingsController.cs | 30 +- .../{ => Contracting}/FormsController.cs | 242 ++++---- .../FrontOfficeController.cs | 0 .../GeneralSettingsController.cs | 240 ++++---- .../Haircut/BrusherProfileController.cs | 34 +- .../Haircut}/ColorsController.cs | 242 ++++---- .../Haircut/HairCutCommandController.cs | 0 .../Haircut/HairPrestationsController.cs | 240 ++++---- .../Haircut/HairTaintsController.cs | 258 ++++----- .../InstrumentationController.cs | 298 +++++----- .../InstrumentsController.cs | 240 ++++---- .../MusicalTendenciesController.cs | 240 ++++---- .../SIRENExceptionsController.cs | 0 .../{ => Deliver}/BlogspotController.cs | 518 ++++++++--------- .../{ => Deliver}/CommentsController.cs | 0 .../{ => Deliver}/NotificationsController.cs | 242 ++++---- .../Controllers/{ => Survey}/BugController.cs | 0 .../{ => Survey}/FeatureController.cs | 0 .../{ => Survey}/TestController.cs | 0 37 files changed, 2862 insertions(+), 2862 deletions(-) rename Yavsc/Controllers/{ => Accounting}/AccountController.cs (100%) rename Yavsc/Controllers/{ => Accounting}/ManageController.cs (100%) rename Yavsc/Controllers/{ => Accounting}/OAuthController.cs (100%) rename Yavsc/Controllers/{ => Accounting}/UsersController.cs (100%) rename Yavsc/Controllers/{ => Administration}/AdministrationController.cs (100%) rename Yavsc/Controllers/{ => Administration}/MailingTemplateController.cs (100%) rename Yavsc/Controllers/{ => Communicating}/AnnouncesController.cs (100%) rename Yavsc/Controllers/{ => Communicating}/CircleController.cs (96%) rename Yavsc/Controllers/{ => Communicating}/CircleMembersController.cs (97%) rename Yavsc/Controllers/{ => Communicating}/GCMDevicesController.cs (100%) rename Yavsc/Controllers/{ => Contracting}/ActivityController.cs (100%) rename Yavsc/Controllers/{ => Contracting}/ClientController.cs (96%) rename Yavsc/Controllers/{ => Contracting}/CoWorkingController.cs (97%) rename Yavsc/Controllers/{ => Contracting}/CommandController.cs (97%) rename Yavsc/Controllers/{ => Contracting}/CommandFormsController.cs (96%) rename Yavsc/Controllers/{ => Contracting}/DjSettingsController.cs (96%) rename Yavsc/Controllers/{ => Contracting}/DoController.cs (97%) rename Yavsc/Controllers/{ => Contracting}/EstimateController.cs (97%) rename Yavsc/Controllers/{ => Contracting}/FormationSettingsController.cs (95%) rename Yavsc/Controllers/{ => Contracting}/FormsController.cs (96%) rename Yavsc/Controllers/{ => Contracting}/FrontOfficeController.cs (100%) rename Yavsc/Controllers/{ => Contracting}/GeneralSettingsController.cs (96%) rename Yavsc/Controllers/{ => Contracting}/Haircut/BrusherProfileController.cs (95%) rename Yavsc/Controllers/{ => Contracting/Haircut}/ColorsController.cs (96%) rename Yavsc/Controllers/{ => Contracting}/Haircut/HairCutCommandController.cs (100%) rename Yavsc/Controllers/{ => Contracting}/Haircut/HairPrestationsController.cs (96%) rename Yavsc/Controllers/{ => Contracting}/Haircut/HairTaintsController.cs (96%) rename Yavsc/Controllers/{ => Contracting}/InstrumentationController.cs (97%) rename Yavsc/Controllers/{ => Contracting}/InstrumentsController.cs (96%) rename Yavsc/Controllers/{ => Contracting}/MusicalTendenciesController.cs (96%) rename Yavsc/Controllers/{ => Contracting}/SIRENExceptionsController.cs (100%) rename Yavsc/Controllers/{ => Deliver}/BlogspotController.cs (97%) rename Yavsc/Controllers/{ => Deliver}/CommentsController.cs (100%) rename Yavsc/Controllers/{ => Deliver}/NotificationsController.cs (96%) rename Yavsc/Controllers/{ => Survey}/BugController.cs (100%) rename Yavsc/Controllers/{ => Survey}/FeatureController.cs (100%) rename Yavsc/Controllers/{ => Survey}/TestController.cs (100%) diff --git a/Yavsc/Controllers/AccountController.cs b/Yavsc/Controllers/Accounting/AccountController.cs similarity index 100% rename from Yavsc/Controllers/AccountController.cs rename to Yavsc/Controllers/Accounting/AccountController.cs diff --git a/Yavsc/Controllers/ManageController.cs b/Yavsc/Controllers/Accounting/ManageController.cs similarity index 100% rename from Yavsc/Controllers/ManageController.cs rename to Yavsc/Controllers/Accounting/ManageController.cs diff --git a/Yavsc/Controllers/OAuthController.cs b/Yavsc/Controllers/Accounting/OAuthController.cs similarity index 100% rename from Yavsc/Controllers/OAuthController.cs rename to Yavsc/Controllers/Accounting/OAuthController.cs diff --git a/Yavsc/Controllers/UsersController.cs b/Yavsc/Controllers/Accounting/UsersController.cs similarity index 100% rename from Yavsc/Controllers/UsersController.cs rename to Yavsc/Controllers/Accounting/UsersController.cs diff --git a/Yavsc/Controllers/AdministrationController.cs b/Yavsc/Controllers/Administration/AdministrationController.cs similarity index 100% rename from Yavsc/Controllers/AdministrationController.cs rename to Yavsc/Controllers/Administration/AdministrationController.cs diff --git a/Yavsc/Controllers/MailingTemplateController.cs b/Yavsc/Controllers/Administration/MailingTemplateController.cs similarity index 100% rename from Yavsc/Controllers/MailingTemplateController.cs rename to Yavsc/Controllers/Administration/MailingTemplateController.cs diff --git a/Yavsc/Controllers/AnnouncesController.cs b/Yavsc/Controllers/Communicating/AnnouncesController.cs similarity index 100% rename from Yavsc/Controllers/AnnouncesController.cs rename to Yavsc/Controllers/Communicating/AnnouncesController.cs diff --git a/Yavsc/Controllers/CircleController.cs b/Yavsc/Controllers/Communicating/CircleController.cs similarity index 96% rename from Yavsc/Controllers/CircleController.cs rename to Yavsc/Controllers/Communicating/CircleController.cs index 56f480bf..840b2b69 100644 --- a/Yavsc/Controllers/CircleController.cs +++ b/Yavsc/Controllers/Communicating/CircleController.cs @@ -1,122 +1,122 @@ - -using System.Security.Claims; -using System.Threading.Tasks; -using Microsoft.AspNet.Mvc; -using Microsoft.Data.Entity; -using Yavsc.Models; -using Yavsc.Models.Relationship; - -namespace Yavsc.Controllers -{ - public class CircleController : Controller - { - private ApplicationDbContext _context; - - public CircleController(ApplicationDbContext context) - { - _context = context; - } - - // GET: Circle - public async Task Index() - { - return View(await _context.Circle.ToListAsync()); - } - - // GET: Circle/Details/5 - public async Task Details(long? id) - { - if (id == null) - { - return HttpNotFound(); - } - - Circle circle = await _context.Circle.SingleAsync(m => m.Id == id); - if (circle == null) - { - return HttpNotFound(); - } - - return View(circle); - } - - // GET: Circle/Create - public IActionResult Create() - { - return View(); - } - - // POST: Circle/Create - [HttpPost] - [ValidateAntiForgeryToken] - public async Task Create(Circle circle) - { - if (ModelState.IsValid) - { - _context.Circle.Add(circle); - await _context.SaveChangesAsync(User.GetUserId()); - return RedirectToAction("Index"); - } - return View(circle); - } - - // GET: Circle/Edit/5 - public async Task Edit(long? id) - { - if (id == null) - { - return HttpNotFound(); - } - - Circle circle = await _context.Circle.SingleAsync(m => m.Id == id); - if (circle == null) - { - return HttpNotFound(); - } - return View(circle); - } - - // POST: Circle/Edit/5 - [HttpPost] - [ValidateAntiForgeryToken] - public async Task Edit(Circle circle) - { - if (ModelState.IsValid) - { - _context.Update(circle); - await _context.SaveChangesAsync(User.GetUserId()); - return RedirectToAction("Index"); - } - return View(circle); - } - - // GET: Circle/Delete/5 - [ActionName("Delete")] - public async Task Delete(long? id) - { - if (id == null) - { - return HttpNotFound(); - } - - Circle circle = await _context.Circle.SingleAsync(m => m.Id == id); - if (circle == null) - { - return HttpNotFound(); - } - - return View(circle); - } - - // POST: Circle/Delete/5 - [HttpPost, ActionName("Delete")] - [ValidateAntiForgeryToken] - public async Task DeleteConfirmed(long id) - { - Circle circle = await _context.Circle.SingleAsync(m => m.Id == id); - _context.Circle.Remove(circle); - await _context.SaveChangesAsync(User.GetUserId()); - return RedirectToAction("Index"); - } - } -} + +using System.Security.Claims; +using System.Threading.Tasks; +using Microsoft.AspNet.Mvc; +using Microsoft.Data.Entity; +using Yavsc.Models; +using Yavsc.Models.Relationship; + +namespace Yavsc.Controllers +{ + public class CircleController : Controller + { + private ApplicationDbContext _context; + + public CircleController(ApplicationDbContext context) + { + _context = context; + } + + // GET: Circle + public async Task Index() + { + return View(await _context.Circle.ToListAsync()); + } + + // GET: Circle/Details/5 + public async Task Details(long? id) + { + if (id == null) + { + return HttpNotFound(); + } + + Circle circle = await _context.Circle.SingleAsync(m => m.Id == id); + if (circle == null) + { + return HttpNotFound(); + } + + return View(circle); + } + + // GET: Circle/Create + public IActionResult Create() + { + return View(); + } + + // POST: Circle/Create + [HttpPost] + [ValidateAntiForgeryToken] + public async Task Create(Circle circle) + { + if (ModelState.IsValid) + { + _context.Circle.Add(circle); + await _context.SaveChangesAsync(User.GetUserId()); + return RedirectToAction("Index"); + } + return View(circle); + } + + // GET: Circle/Edit/5 + public async Task Edit(long? id) + { + if (id == null) + { + return HttpNotFound(); + } + + Circle circle = await _context.Circle.SingleAsync(m => m.Id == id); + if (circle == null) + { + return HttpNotFound(); + } + return View(circle); + } + + // POST: Circle/Edit/5 + [HttpPost] + [ValidateAntiForgeryToken] + public async Task Edit(Circle circle) + { + if (ModelState.IsValid) + { + _context.Update(circle); + await _context.SaveChangesAsync(User.GetUserId()); + return RedirectToAction("Index"); + } + return View(circle); + } + + // GET: Circle/Delete/5 + [ActionName("Delete")] + public async Task Delete(long? id) + { + if (id == null) + { + return HttpNotFound(); + } + + Circle circle = await _context.Circle.SingleAsync(m => m.Id == id); + if (circle == null) + { + return HttpNotFound(); + } + + return View(circle); + } + + // POST: Circle/Delete/5 + [HttpPost, ActionName("Delete")] + [ValidateAntiForgeryToken] + public async Task DeleteConfirmed(long id) + { + Circle circle = await _context.Circle.SingleAsync(m => m.Id == id); + _context.Circle.Remove(circle); + await _context.SaveChangesAsync(User.GetUserId()); + return RedirectToAction("Index"); + } + } +} diff --git a/Yavsc/Controllers/CircleMembersController.cs b/Yavsc/Controllers/Communicating/CircleMembersController.cs similarity index 97% rename from Yavsc/Controllers/CircleMembersController.cs rename to Yavsc/Controllers/Communicating/CircleMembersController.cs index 0715dc03..a130d6db 100644 --- a/Yavsc/Controllers/CircleMembersController.cs +++ b/Yavsc/Controllers/Communicating/CircleMembersController.cs @@ -1,135 +1,135 @@ -using System.Linq; -using System.Security.Claims; -using System.Threading.Tasks; -using Microsoft.AspNet.Mvc; -using Microsoft.AspNet.Mvc.Rendering; -using Microsoft.Data.Entity; -using Yavsc.Models; -using Yavsc.Models.Relationship; - -namespace Yavsc.Controllers -{ - public class CircleMembersController : Controller - { - private ApplicationDbContext _context; - - public CircleMembersController(ApplicationDbContext context) - { - _context = context; - } - - // GET: CircleMembers - public async Task Index() - { - var uid = User.GetUserId(); - 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 Details(long id) - { - var uid = User.GetUserId(); - - CircleMember circleMember = await _context.CircleMembers - .Include(m=>m.Circle) - .FirstOrDefaultAsync(c=>c.CircleId == id); - if (circleMember == null) - { - return HttpNotFound(); - } - - return View(circleMember); - } - - // GET: CircleMembers/Create - public IActionResult Create() - { - var uid = User.GetUserId(); - 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 Create(CircleMember circleMember) - { - var uid = User.GetUserId(); - 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 Edit(long id) - { - var uid = User.GetUserId(); - CircleMember circleMember = await _context.CircleMembers - .Include(m=>m.Member) - .SingleOrDefaultAsync(m => m.CircleId == id && m.MemberId == uid); - if (circleMember == null) - { - return HttpNotFound(); - } - return View(circleMember); - } - - // POST: CircleMembers/Edit/5 - [HttpPost] - [ValidateAntiForgeryToken] - public async Task 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 Delete(long id) - { - var uid = User.GetUserId(); - - 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 HttpNotFound(); - } - - return View(circleMember); - } - - // POST: CircleMembers/Delete/5 - [HttpPost, ActionName("Delete")] - [ValidateAntiForgeryToken] - public async Task 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"); - } - } -} +using System.Linq; +using System.Security.Claims; +using System.Threading.Tasks; +using Microsoft.AspNet.Mvc; +using Microsoft.AspNet.Mvc.Rendering; +using Microsoft.Data.Entity; +using Yavsc.Models; +using Yavsc.Models.Relationship; + +namespace Yavsc.Controllers +{ + public class CircleMembersController : Controller + { + private ApplicationDbContext _context; + + public CircleMembersController(ApplicationDbContext context) + { + _context = context; + } + + // GET: CircleMembers + public async Task Index() + { + var uid = User.GetUserId(); + 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 Details(long id) + { + var uid = User.GetUserId(); + + CircleMember circleMember = await _context.CircleMembers + .Include(m=>m.Circle) + .FirstOrDefaultAsync(c=>c.CircleId == id); + if (circleMember == null) + { + return HttpNotFound(); + } + + return View(circleMember); + } + + // GET: CircleMembers/Create + public IActionResult Create() + { + var uid = User.GetUserId(); + 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 Create(CircleMember circleMember) + { + var uid = User.GetUserId(); + 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 Edit(long id) + { + var uid = User.GetUserId(); + CircleMember circleMember = await _context.CircleMembers + .Include(m=>m.Member) + .SingleOrDefaultAsync(m => m.CircleId == id && m.MemberId == uid); + if (circleMember == null) + { + return HttpNotFound(); + } + return View(circleMember); + } + + // POST: CircleMembers/Edit/5 + [HttpPost] + [ValidateAntiForgeryToken] + public async Task 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 Delete(long id) + { + var uid = User.GetUserId(); + + 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 HttpNotFound(); + } + + return View(circleMember); + } + + // POST: CircleMembers/Delete/5 + [HttpPost, ActionName("Delete")] + [ValidateAntiForgeryToken] + public async Task 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"); + } + } +} diff --git a/Yavsc/Controllers/GCMDevicesController.cs b/Yavsc/Controllers/Communicating/GCMDevicesController.cs similarity index 100% rename from Yavsc/Controllers/GCMDevicesController.cs rename to Yavsc/Controllers/Communicating/GCMDevicesController.cs diff --git a/Yavsc/Controllers/ActivityController.cs b/Yavsc/Controllers/Contracting/ActivityController.cs similarity index 100% rename from Yavsc/Controllers/ActivityController.cs rename to Yavsc/Controllers/Contracting/ActivityController.cs diff --git a/Yavsc/Controllers/ClientController.cs b/Yavsc/Controllers/Contracting/ClientController.cs similarity index 96% rename from Yavsc/Controllers/ClientController.cs rename to Yavsc/Controllers/Contracting/ClientController.cs index 5c7e0a63..6c8bfa45 100644 --- a/Yavsc/Controllers/ClientController.cs +++ b/Yavsc/Controllers/Contracting/ClientController.cs @@ -1,139 +1,139 @@ -using System; -using System.Threading.Tasks; -using Microsoft.AspNet.Mvc; -using Microsoft.AspNet.Mvc.Rendering; -using Microsoft.Data.Entity; -using System.Collections.Generic; -using Yavsc.Models; -using Yavsc.Models.Auth; -using System.Security.Claims; - -namespace Yavsc.Controllers -{ - public class ClientController : Controller - { - private ApplicationDbContext _context; - - public ClientController(ApplicationDbContext context) - { - _context = context; - } - - // GET: Client - public async Task Index() - { - return View(await _context.Applications.ToListAsync()); - } - - // GET: Client/Details/5 - public async Task Details(string id) - { - if (id == null) - { - return HttpNotFound(); - } - - Client client = await _context.Applications.SingleAsync(m => m.Id == id); - if (client == null) - { - return HttpNotFound(); - } - return View(client); - } - - // GET: Client/Create - public IActionResult Create() - { - SetAppTypesInputValues(); - return View(); - } - - // POST: Client/Create - [HttpPost] - [ValidateAntiForgeryToken] - public async Task Create(Client client) - { - if (ModelState.IsValid) - { - client.Id = Guid.NewGuid().ToString(); - _context.Applications.Add(client); - await _context.SaveChangesAsync(User.GetUserId()); - return RedirectToAction("Index"); - } - SetAppTypesInputValues(); - return View(client); - } - private void SetAppTypesInputValues() - { - IEnumerable types = new SelectListItem[] { - new SelectListItem { - Text = ApplicationTypes.JavaScript.ToString(), - Value = ((int) ApplicationTypes.JavaScript).ToString() }, - new SelectListItem { - Text = ApplicationTypes.NativeConfidential.ToString(), - Value = ((int) ApplicationTypes.NativeConfidential).ToString() - } - }; - ViewData["Type"] = types; - } - // GET: Client/Edit/5 - public async Task Edit(string id) - { - if (id == null) - { - return HttpNotFound(); - } - - Client client = await _context.Applications.SingleAsync(m => m.Id == id); - if (client == null) - { - return HttpNotFound(); - } - SetAppTypesInputValues(); - return View(client); - } - - // POST: Client/Edit/5 - [HttpPost] - [ValidateAntiForgeryToken] - public async Task Edit(Client client) - { - if (ModelState.IsValid) - { - _context.Update(client); - await _context.SaveChangesAsync(User.GetUserId()); - return RedirectToAction("Index"); - } - return View(client); - } - - // GET: Client/Delete/5 - [ActionName("Delete")] - public async Task Delete(string id) - { - if (id == null) - { - return HttpNotFound(); - } - - Client client = await _context.Applications.SingleAsync(m => m.Id == id); - if (client == null) - { - return HttpNotFound(); - } - - return View(client); - } - - // POST: Client/Delete/5 - [HttpPost, ActionName("Delete")] - [ValidateAntiForgeryToken] - public async Task DeleteConfirmed(string id) - { - Client client = await _context.Applications.SingleAsync(m => m.Id == id); - _context.Applications.Remove(client); - await _context.SaveChangesAsync(User.GetUserId()); - return RedirectToAction("Index"); - } - } -} +using System; +using System.Threading.Tasks; +using Microsoft.AspNet.Mvc; +using Microsoft.AspNet.Mvc.Rendering; +using Microsoft.Data.Entity; +using System.Collections.Generic; +using Yavsc.Models; +using Yavsc.Models.Auth; +using System.Security.Claims; + +namespace Yavsc.Controllers +{ + public class ClientController : Controller + { + private ApplicationDbContext _context; + + public ClientController(ApplicationDbContext context) + { + _context = context; + } + + // GET: Client + public async Task Index() + { + return View(await _context.Applications.ToListAsync()); + } + + // GET: Client/Details/5 + public async Task Details(string id) + { + if (id == null) + { + return HttpNotFound(); + } + + Client client = await _context.Applications.SingleAsync(m => m.Id == id); + if (client == null) + { + return HttpNotFound(); + } + return View(client); + } + + // GET: Client/Create + public IActionResult Create() + { + SetAppTypesInputValues(); + return View(); + } + + // POST: Client/Create + [HttpPost] + [ValidateAntiForgeryToken] + public async Task Create(Client client) + { + if (ModelState.IsValid) + { + client.Id = Guid.NewGuid().ToString(); + _context.Applications.Add(client); + await _context.SaveChangesAsync(User.GetUserId()); + return RedirectToAction("Index"); + } + SetAppTypesInputValues(); + return View(client); + } + private void SetAppTypesInputValues() + { + IEnumerable types = new SelectListItem[] { + new SelectListItem { + Text = ApplicationTypes.JavaScript.ToString(), + Value = ((int) ApplicationTypes.JavaScript).ToString() }, + new SelectListItem { + Text = ApplicationTypes.NativeConfidential.ToString(), + Value = ((int) ApplicationTypes.NativeConfidential).ToString() + } + }; + ViewData["Type"] = types; + } + // GET: Client/Edit/5 + public async Task Edit(string id) + { + if (id == null) + { + return HttpNotFound(); + } + + Client client = await _context.Applications.SingleAsync(m => m.Id == id); + if (client == null) + { + return HttpNotFound(); + } + SetAppTypesInputValues(); + return View(client); + } + + // POST: Client/Edit/5 + [HttpPost] + [ValidateAntiForgeryToken] + public async Task Edit(Client client) + { + if (ModelState.IsValid) + { + _context.Update(client); + await _context.SaveChangesAsync(User.GetUserId()); + return RedirectToAction("Index"); + } + return View(client); + } + + // GET: Client/Delete/5 + [ActionName("Delete")] + public async Task Delete(string id) + { + if (id == null) + { + return HttpNotFound(); + } + + Client client = await _context.Applications.SingleAsync(m => m.Id == id); + if (client == null) + { + return HttpNotFound(); + } + + return View(client); + } + + // POST: Client/Delete/5 + [HttpPost, ActionName("Delete")] + [ValidateAntiForgeryToken] + public async Task DeleteConfirmed(string id) + { + Client client = await _context.Applications.SingleAsync(m => m.Id == id); + _context.Applications.Remove(client); + await _context.SaveChangesAsync(User.GetUserId()); + return RedirectToAction("Index"); + } + } +} diff --git a/Yavsc/Controllers/CoWorkingController.cs b/Yavsc/Controllers/Contracting/CoWorkingController.cs similarity index 97% rename from Yavsc/Controllers/CoWorkingController.cs rename to Yavsc/Controllers/Contracting/CoWorkingController.cs index c1f7bd3e..4af1a6b1 100644 --- a/Yavsc/Controllers/CoWorkingController.cs +++ b/Yavsc/Controllers/Contracting/CoWorkingController.cs @@ -1,132 +1,132 @@ -using System.Linq; -using System.Security.Claims; -using System.Threading.Tasks; -using Microsoft.AspNet.Mvc; -using Microsoft.AspNet.Mvc.Rendering; -using Microsoft.Data.Entity; -using Yavsc.Models; -using Yavsc.Models.Workflow; - -namespace Yavsc.Controllers -{ - public class CoWorkingController : Controller - { - private ApplicationDbContext _context; - - public CoWorkingController(ApplicationDbContext context) - { - _context = context; - } - - // GET: CoWorking - public async Task Index() - { - var applicationDbContext = _context.WorkflowProviders.Include(c => c.Performer).Include(c => c.WorkingFor); - return View(await applicationDbContext.ToListAsync()); - } - - // GET: CoWorking/Details/5 - public async Task Details(long? id) - { - if (id == null) - { - return HttpNotFound(); - } - - CoWorking coWorking = await _context.WorkflowProviders.SingleAsync(m => m.Id == id); - if (coWorking == null) - { - return HttpNotFound(); - } - - return View(coWorking); - } - - // GET: CoWorking/Create - public IActionResult Create() - { - ViewBag.PerformerId = _context.Performers.Select( p=> new SelectListItem { Value = p.PerformerId, Text = p.Performer.UserName}); - ViewBag.WorkingForId = new SelectList(_context.Users, "Id", "UserName"); - return View(); - } - - // POST: CoWorking/Create - [HttpPost] - [ValidateAntiForgeryToken] - public async Task Create(CoWorking coWorking) - { - if (ModelState.IsValid) - { - _context.WorkflowProviders.Add(coWorking); - await _context.SaveChangesAsync(User.GetUserId()); - return RedirectToAction("Index"); - } - ViewData["PerformerId"] = new SelectList(_context.Performers, "PerformerId", "Performer", coWorking.PerformerId); - ViewData["WorkingForId"] = new SelectList(_context.Users, "Id", "WorkingFor", coWorking.WorkingForId); - return View(coWorking); - } - - // GET: CoWorking/Edit/5 - public async Task Edit(long? id) - { - if (id == null) - { - return HttpNotFound(); - } - - CoWorking coWorking = await _context.WorkflowProviders.SingleAsync(m => m.Id == id); - if (coWorking == null) - { - return HttpNotFound(); - } - ViewData["PerformerId"] = new SelectList(_context.Performers, "PerformerId", "Performer", coWorking.PerformerId); - ViewData["WorkingForId"] = new SelectList(_context.Users, "Id", "WorkingFor", coWorking.WorkingForId); - return View(coWorking); - } - - // POST: CoWorking/Edit/5 - [HttpPost] - [ValidateAntiForgeryToken] - public async Task Edit(CoWorking coWorking) - { - if (ModelState.IsValid) - { - _context.Update(coWorking); - await _context.SaveChangesAsync(User.GetUserId()); - return RedirectToAction("Index"); - } - ViewData["PerformerId"] = new SelectList(_context.Performers, "PerformerId", "Performer", coWorking.PerformerId); - ViewData["WorkingForId"] = new SelectList(_context.Users, "Id", "WorkingFor", coWorking.WorkingForId); - return View(coWorking); - } - - // GET: CoWorking/Delete/5 - [ActionName("Delete")] - public async Task Delete(long? id) - { - if (id == null) - { - return HttpNotFound(); - } - - CoWorking coWorking = await _context.WorkflowProviders.SingleAsync(m => m.Id == id); - if (coWorking == null) - { - return HttpNotFound(); - } - - return View(coWorking); - } - - // POST: CoWorking/Delete/5 - [HttpPost, ActionName("Delete")] - [ValidateAntiForgeryToken] - public async Task DeleteConfirmed(long id) - { - CoWorking coWorking = await _context.WorkflowProviders.SingleAsync(m => m.Id == id); - _context.WorkflowProviders.Remove(coWorking); - await _context.SaveChangesAsync(User.GetUserId()); - return RedirectToAction("Index"); - } - } -} +using System.Linq; +using System.Security.Claims; +using System.Threading.Tasks; +using Microsoft.AspNet.Mvc; +using Microsoft.AspNet.Mvc.Rendering; +using Microsoft.Data.Entity; +using Yavsc.Models; +using Yavsc.Models.Workflow; + +namespace Yavsc.Controllers +{ + public class CoWorkingController : Controller + { + private ApplicationDbContext _context; + + public CoWorkingController(ApplicationDbContext context) + { + _context = context; + } + + // GET: CoWorking + public async Task Index() + { + var applicationDbContext = _context.WorkflowProviders.Include(c => c.Performer).Include(c => c.WorkingFor); + return View(await applicationDbContext.ToListAsync()); + } + + // GET: CoWorking/Details/5 + public async Task Details(long? id) + { + if (id == null) + { + return HttpNotFound(); + } + + CoWorking coWorking = await _context.WorkflowProviders.SingleAsync(m => m.Id == id); + if (coWorking == null) + { + return HttpNotFound(); + } + + return View(coWorking); + } + + // GET: CoWorking/Create + public IActionResult Create() + { + ViewBag.PerformerId = _context.Performers.Select( p=> new SelectListItem { Value = p.PerformerId, Text = p.Performer.UserName}); + ViewBag.WorkingForId = new SelectList(_context.Users, "Id", "UserName"); + return View(); + } + + // POST: CoWorking/Create + [HttpPost] + [ValidateAntiForgeryToken] + public async Task Create(CoWorking coWorking) + { + if (ModelState.IsValid) + { + _context.WorkflowProviders.Add(coWorking); + await _context.SaveChangesAsync(User.GetUserId()); + return RedirectToAction("Index"); + } + ViewData["PerformerId"] = new SelectList(_context.Performers, "PerformerId", "Performer", coWorking.PerformerId); + ViewData["WorkingForId"] = new SelectList(_context.Users, "Id", "WorkingFor", coWorking.WorkingForId); + return View(coWorking); + } + + // GET: CoWorking/Edit/5 + public async Task Edit(long? id) + { + if (id == null) + { + return HttpNotFound(); + } + + CoWorking coWorking = await _context.WorkflowProviders.SingleAsync(m => m.Id == id); + if (coWorking == null) + { + return HttpNotFound(); + } + ViewData["PerformerId"] = new SelectList(_context.Performers, "PerformerId", "Performer", coWorking.PerformerId); + ViewData["WorkingForId"] = new SelectList(_context.Users, "Id", "WorkingFor", coWorking.WorkingForId); + return View(coWorking); + } + + // POST: CoWorking/Edit/5 + [HttpPost] + [ValidateAntiForgeryToken] + public async Task Edit(CoWorking coWorking) + { + if (ModelState.IsValid) + { + _context.Update(coWorking); + await _context.SaveChangesAsync(User.GetUserId()); + return RedirectToAction("Index"); + } + ViewData["PerformerId"] = new SelectList(_context.Performers, "PerformerId", "Performer", coWorking.PerformerId); + ViewData["WorkingForId"] = new SelectList(_context.Users, "Id", "WorkingFor", coWorking.WorkingForId); + return View(coWorking); + } + + // GET: CoWorking/Delete/5 + [ActionName("Delete")] + public async Task Delete(long? id) + { + if (id == null) + { + return HttpNotFound(); + } + + CoWorking coWorking = await _context.WorkflowProviders.SingleAsync(m => m.Id == id); + if (coWorking == null) + { + return HttpNotFound(); + } + + return View(coWorking); + } + + // POST: CoWorking/Delete/5 + [HttpPost, ActionName("Delete")] + [ValidateAntiForgeryToken] + public async Task DeleteConfirmed(long id) + { + CoWorking coWorking = await _context.WorkflowProviders.SingleAsync(m => m.Id == id); + _context.WorkflowProviders.Remove(coWorking); + await _context.SaveChangesAsync(User.GetUserId()); + return RedirectToAction("Index"); + } + } +} diff --git a/Yavsc/Controllers/CommandController.cs b/Yavsc/Controllers/Contracting/CommandController.cs similarity index 97% rename from Yavsc/Controllers/CommandController.cs rename to Yavsc/Controllers/Contracting/CommandController.cs index 2e62940c..ebe35ed6 100644 --- a/Yavsc/Controllers/CommandController.cs +++ b/Yavsc/Controllers/Contracting/CommandController.cs @@ -1,262 +1,262 @@ -using System; -using System.Linq; -using System.Security.Claims; -using System.Threading.Tasks; -using Microsoft.AspNet.Authorization; -using Microsoft.AspNet.Identity; -using Microsoft.AspNet.Mvc; -using Microsoft.Data.Entity; -using Microsoft.Extensions.Localization; -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.OptionsModel; - -namespace Yavsc.Controllers -{ - using Helpers; - using Models; - using Models.Google.Messaging; - using Models.Relationship; - using Models.Workflow; - using Services; - - public class CommandController : Controller - { - protected UserManager _userManager; - protected ApplicationDbContext _context; - protected GoogleAuthSettings _googleSettings; - protected IGoogleCloudMessageSender _GCMSender; - protected IEmailSender _emailSender; - protected IStringLocalizer _localizer; - protected SiteSettings _siteSettings; - protected SmtpSettings _smtpSettings; - - protected ICalendarManager _calendarManager; - - protected readonly ILogger _logger; - public CommandController(ApplicationDbContext context, IOptions googleSettings, - IGoogleCloudMessageSender GCMSender, - UserManager userManager, - ICalendarManager calendarManager, - IStringLocalizer localizer, - IEmailSender emailSender, - IOptions smtpSettings, - IOptions siteSettings, - ILoggerFactory loggerFactory) - { - _context = context; - _GCMSender = GCMSender; - _emailSender = emailSender; - _googleSettings = googleSettings.Value; - _userManager = userManager; - _smtpSettings = smtpSettings.Value; - _siteSettings = siteSettings.Value; - _calendarManager = calendarManager; - _localizer = localizer; - _logger = loggerFactory.CreateLogger(); - } - - // GET: Command - [Authorize] - public virtual async Task Index() - { - var uid = User.GetUserId(); - return View(await _context.RdvQueries - .Include(x => x.Client) - .Include(x => x.PerformerProfile) - .Include(x => x.PerformerProfile.Performer) - .Include(x => x.Location) - .Where(x=> x.ClientId == uid || x.PerformerId == uid) - .ToListAsync()); - } - - // GET: Command/Details/5 - public virtual async Task Details(long id) - { - RdvQuery command = await _context.RdvQueries - .Include(x => x.Location) - .Include(x => x.PerformerProfile) - .SingleAsync(m => m.Id == id); - if (command == null) - { - return HttpNotFound(); - } - - return View(command); - } - - /// - /// Gives a view on - /// Creating a command for a specified performer - /// - /// - /// - [HttpGet] - public IActionResult Create(string proId, string activityCode, string billingCode) - { - if (string.IsNullOrWhiteSpace(proId)) - throw new InvalidOperationException( - "This method needs a performer id (from parameter proId)" - ); - if (string.IsNullOrWhiteSpace(activityCode)) - throw new InvalidOperationException( - "This method needs an activity code" - ); - var pro = _context.Performers.Include( - x => x.Performer).FirstOrDefault( - x => x.PerformerId == proId - ); - if (pro == null) - return HttpNotFound(); - ViewBag.Activity = _context.Activities.FirstOrDefault(a=>a.Code == activityCode); - ViewBag.GoogleSettings = _googleSettings; - var userid = User.GetUserId(); - var user = _userManager.FindByIdAsync(userid).Result; - return View("Create",new RdvQuery(activityCode,new Location(),DateTime.Now.AddHours(4)) - { - PerformerProfile = pro, - PerformerId = pro.PerformerId, - ClientId = userid, - Client = user, - ActivityCode = activityCode - }); - } - - // POST: Command/Create - [HttpPost] - [ValidateAntiForgeryToken] - public async Task Create(RdvQuery command) - { - // TODO validate BillingCode value - var uid = User.GetUserId(); - var prid = command.PerformerId; - if (string.IsNullOrWhiteSpace(uid) - || string.IsNullOrWhiteSpace(prid)) - throw new InvalidOperationException( - "This method needs a PerformerId" - ); - var pro = _context.Performers.Include( - u => u.Performer - ).Include(u => u.Performer.Devices) - .FirstOrDefault( - x => x.PerformerId == command.PerformerId - ); - var user = await _userManager.FindByIdAsync(uid); - command.Client = user; - command.ClientId = uid; - command.PerformerProfile = pro; - // FIXME Why!! - // ModelState.ClearValidationState("PerformerProfile.Avatar"); - // ModelState.ClearValidationState("Client.Avatar"); - // ModelState.ClearValidationState("ClientId"); - ModelState.MarkFieldSkipped("ClientId"); - - if (ModelState.IsValid) - { - var existingLocation = _context.Locations.FirstOrDefault( x=>x.Address == command.Location.Address - && x.Longitude == command.Location.Longitude && x.Latitude == command.Location.Latitude ); - - if (existingLocation!=null) { - command.Location=existingLocation; - } - else _context.Attach(command.Location); - _context.RdvQueries.Add(command, GraphBehavior.IncludeDependents); - _context.SaveChanges(User.GetUserId()); - - var yaev = command.CreateEvent(_localizer, "NewCommand"); - - MessageWithPayloadResponse grep = null; - - if (pro.AcceptNotifications - && pro.AcceptPublicContact) - { - if (pro.Performer.Devices.Count > 0) { - var regids = command.PerformerProfile.Performer - .Devices.Select(d => d.GCMRegistrationId); - grep = await _GCMSender.NotifyBookQueryAsync(regids,yaev); - } - - // TODO setup a profile choice to allow notifications - // both on mailbox and mobile - // if (grep==null || grep.success<=0 || grep.failure>0) - ViewBag.GooglePayload=grep; - - ViewBag.EmailSent = await _emailSender.SendEmailAsync( - command.PerformerProfile.Performer.UserName, - command.PerformerProfile.Performer.Email, - $"{command.Client.UserName} (un client) vous demande un rendez-vous", - $"{yaev.CreateBody()}\r\n-- \r\n{yaev.Previsional}\r\n{yaev.EventDate}\r\n" - ); - } - ViewBag.Activity = _context.Activities.FirstOrDefault(a=>a.Code == command.ActivityCode); - ViewBag.GoogleSettings = _googleSettings; - return View("CommandConfirmation",command); - } - ViewBag.Activity = _context.Activities.FirstOrDefault(a=>a.Code == command.ActivityCode); - ViewBag.GoogleSettings = _googleSettings; - return View(command); - } - - // GET: Command/Edit/5 - public IActionResult Edit(long? id) - { - if (id == null) - { - return HttpNotFound(); - } - - RdvQuery command = _context.RdvQueries.Single(m => m.Id == id); - if (command == null) - { - return HttpNotFound(); - } - return View(command); - } - - // POST: Command/Edit/5 - [HttpPost] - [ValidateAntiForgeryToken] - public IActionResult Edit(RdvQuery command) - { - if (ModelState.IsValid) - { - _context.Update(command); - _context.SaveChanges(User.GetUserId()); - return RedirectToAction("Index"); - } - return View(command); - } - - // GET: Command/Delete/5 - [ActionName("Delete")] - public IActionResult Delete(long? id) - { - if (id == null) - { - return HttpNotFound(); - } - - RdvQuery command = _context.RdvQueries.Single(m => m.Id == id); - if (command == null) - { - return HttpNotFound(); - } - - return View(command); - } - - // POST: Command/Delete/5 - [HttpPost, ActionName("Delete")] - [ValidateAntiForgeryToken] - public IActionResult DeleteConfirmed(long id) - { - RdvQuery command = _context.RdvQueries.Single(m => m.Id == id); - _context.RdvQueries.Remove(command); - _context.SaveChanges(User.GetUserId()); - return RedirectToAction("Index"); - } - public IActionResult CGV() - { - return View(); - } - } -} +using System; +using System.Linq; +using System.Security.Claims; +using System.Threading.Tasks; +using Microsoft.AspNet.Authorization; +using Microsoft.AspNet.Identity; +using Microsoft.AspNet.Mvc; +using Microsoft.Data.Entity; +using Microsoft.Extensions.Localization; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.OptionsModel; + +namespace Yavsc.Controllers +{ + using Helpers; + using Models; + using Models.Google.Messaging; + using Models.Relationship; + using Models.Workflow; + using Services; + + public class CommandController : Controller + { + protected UserManager _userManager; + protected ApplicationDbContext _context; + protected GoogleAuthSettings _googleSettings; + protected IGoogleCloudMessageSender _GCMSender; + protected IEmailSender _emailSender; + protected IStringLocalizer _localizer; + protected SiteSettings _siteSettings; + protected SmtpSettings _smtpSettings; + + protected ICalendarManager _calendarManager; + + protected readonly ILogger _logger; + public CommandController(ApplicationDbContext context, IOptions googleSettings, + IGoogleCloudMessageSender GCMSender, + UserManager userManager, + ICalendarManager calendarManager, + IStringLocalizer localizer, + IEmailSender emailSender, + IOptions smtpSettings, + IOptions siteSettings, + ILoggerFactory loggerFactory) + { + _context = context; + _GCMSender = GCMSender; + _emailSender = emailSender; + _googleSettings = googleSettings.Value; + _userManager = userManager; + _smtpSettings = smtpSettings.Value; + _siteSettings = siteSettings.Value; + _calendarManager = calendarManager; + _localizer = localizer; + _logger = loggerFactory.CreateLogger(); + } + + // GET: Command + [Authorize] + public virtual async Task Index() + { + var uid = User.GetUserId(); + return View(await _context.RdvQueries + .Include(x => x.Client) + .Include(x => x.PerformerProfile) + .Include(x => x.PerformerProfile.Performer) + .Include(x => x.Location) + .Where(x=> x.ClientId == uid || x.PerformerId == uid) + .ToListAsync()); + } + + // GET: Command/Details/5 + public virtual async Task Details(long id) + { + RdvQuery command = await _context.RdvQueries + .Include(x => x.Location) + .Include(x => x.PerformerProfile) + .SingleAsync(m => m.Id == id); + if (command == null) + { + return HttpNotFound(); + } + + return View(command); + } + + /// + /// Gives a view on + /// Creating a command for a specified performer + /// + /// + /// + [HttpGet] + public IActionResult Create(string proId, string activityCode, string billingCode) + { + if (string.IsNullOrWhiteSpace(proId)) + throw new InvalidOperationException( + "This method needs a performer id (from parameter proId)" + ); + if (string.IsNullOrWhiteSpace(activityCode)) + throw new InvalidOperationException( + "This method needs an activity code" + ); + var pro = _context.Performers.Include( + x => x.Performer).FirstOrDefault( + x => x.PerformerId == proId + ); + if (pro == null) + return HttpNotFound(); + ViewBag.Activity = _context.Activities.FirstOrDefault(a=>a.Code == activityCode); + ViewBag.GoogleSettings = _googleSettings; + var userid = User.GetUserId(); + var user = _userManager.FindByIdAsync(userid).Result; + return View("Create",new RdvQuery(activityCode,new Location(),DateTime.Now.AddHours(4)) + { + PerformerProfile = pro, + PerformerId = pro.PerformerId, + ClientId = userid, + Client = user, + ActivityCode = activityCode + }); + } + + // POST: Command/Create + [HttpPost] + [ValidateAntiForgeryToken] + public async Task Create(RdvQuery command) + { + // TODO validate BillingCode value + var uid = User.GetUserId(); + var prid = command.PerformerId; + if (string.IsNullOrWhiteSpace(uid) + || string.IsNullOrWhiteSpace(prid)) + throw new InvalidOperationException( + "This method needs a PerformerId" + ); + var pro = _context.Performers.Include( + u => u.Performer + ).Include(u => u.Performer.Devices) + .FirstOrDefault( + x => x.PerformerId == command.PerformerId + ); + var user = await _userManager.FindByIdAsync(uid); + command.Client = user; + command.ClientId = uid; + command.PerformerProfile = pro; + // FIXME Why!! + // ModelState.ClearValidationState("PerformerProfile.Avatar"); + // ModelState.ClearValidationState("Client.Avatar"); + // ModelState.ClearValidationState("ClientId"); + ModelState.MarkFieldSkipped("ClientId"); + + if (ModelState.IsValid) + { + var existingLocation = _context.Locations.FirstOrDefault( x=>x.Address == command.Location.Address + && x.Longitude == command.Location.Longitude && x.Latitude == command.Location.Latitude ); + + if (existingLocation!=null) { + command.Location=existingLocation; + } + else _context.Attach(command.Location); + _context.RdvQueries.Add(command, GraphBehavior.IncludeDependents); + _context.SaveChanges(User.GetUserId()); + + var yaev = command.CreateEvent(_localizer, "NewCommand"); + + MessageWithPayloadResponse grep = null; + + if (pro.AcceptNotifications + && pro.AcceptPublicContact) + { + if (pro.Performer.Devices.Count > 0) { + var regids = command.PerformerProfile.Performer + .Devices.Select(d => d.GCMRegistrationId); + grep = await _GCMSender.NotifyBookQueryAsync(regids,yaev); + } + + // TODO setup a profile choice to allow notifications + // both on mailbox and mobile + // if (grep==null || grep.success<=0 || grep.failure>0) + ViewBag.GooglePayload=grep; + + ViewBag.EmailSent = await _emailSender.SendEmailAsync( + command.PerformerProfile.Performer.UserName, + command.PerformerProfile.Performer.Email, + $"{command.Client.UserName} (un client) vous demande un rendez-vous", + $"{yaev.CreateBody()}\r\n-- \r\n{yaev.Previsional}\r\n{yaev.EventDate}\r\n" + ); + } + ViewBag.Activity = _context.Activities.FirstOrDefault(a=>a.Code == command.ActivityCode); + ViewBag.GoogleSettings = _googleSettings; + return View("CommandConfirmation",command); + } + ViewBag.Activity = _context.Activities.FirstOrDefault(a=>a.Code == command.ActivityCode); + ViewBag.GoogleSettings = _googleSettings; + return View(command); + } + + // GET: Command/Edit/5 + public IActionResult Edit(long? id) + { + if (id == null) + { + return HttpNotFound(); + } + + RdvQuery command = _context.RdvQueries.Single(m => m.Id == id); + if (command == null) + { + return HttpNotFound(); + } + return View(command); + } + + // POST: Command/Edit/5 + [HttpPost] + [ValidateAntiForgeryToken] + public IActionResult Edit(RdvQuery command) + { + if (ModelState.IsValid) + { + _context.Update(command); + _context.SaveChanges(User.GetUserId()); + return RedirectToAction("Index"); + } + return View(command); + } + + // GET: Command/Delete/5 + [ActionName("Delete")] + public IActionResult Delete(long? id) + { + if (id == null) + { + return HttpNotFound(); + } + + RdvQuery command = _context.RdvQueries.Single(m => m.Id == id); + if (command == null) + { + return HttpNotFound(); + } + + return View(command); + } + + // POST: Command/Delete/5 + [HttpPost, ActionName("Delete")] + [ValidateAntiForgeryToken] + public IActionResult DeleteConfirmed(long id) + { + RdvQuery command = _context.RdvQueries.Single(m => m.Id == id); + _context.RdvQueries.Remove(command); + _context.SaveChanges(User.GetUserId()); + return RedirectToAction("Index"); + } + public IActionResult CGV() + { + return View(); + } + } +} diff --git a/Yavsc/Controllers/CommandFormsController.cs b/Yavsc/Controllers/Contracting/CommandFormsController.cs similarity index 96% rename from Yavsc/Controllers/CommandFormsController.cs rename to Yavsc/Controllers/Contracting/CommandFormsController.cs index 2f24fcce..e0d14cba 100644 --- a/Yavsc/Controllers/CommandFormsController.cs +++ b/Yavsc/Controllers/Contracting/CommandFormsController.cs @@ -1,131 +1,131 @@ -using System.Linq; -using System.Security.Claims; -using System.Threading.Tasks; -using Microsoft.AspNet.Mvc; -using Microsoft.AspNet.Mvc.Rendering; -using Microsoft.Data.Entity; -using Yavsc.Models; -using Yavsc.Models.Workflow; - -namespace Yavsc.Controllers -{ - public class CommandFormsController : Controller - { - private ApplicationDbContext _context; - - public CommandFormsController(ApplicationDbContext context) - { - _context = context; - } - - // GET: CommandForms - public async Task Index() - { - var applicationDbContext = _context.CommandForm.Include(c => c.Context); - return View(await applicationDbContext.ToListAsync()); - } - - // GET: CommandForms/Details/5 - public async Task Details(long? id) - { - if (id == null) - { - return HttpNotFound(); - } - - CommandForm commandForm = await _context.CommandForm.SingleAsync(m => m.Id == id); - if (commandForm == null) - { - return HttpNotFound(); - } - - return View(commandForm); - } - - // GET: CommandForms/Create - public IActionResult Create() - { - SetViewBag(); - return View(); - } - private void SetViewBag(CommandForm commandForm=null) { - ViewBag.ActivityCode = new SelectList(_context.Activities, "Code", "Name", commandForm?.ActivityCode); - ViewBag.ActionName = Startup.Forms.Select( c => new SelectListItem { Value = c, Text = c, Selected = (commandForm?.ActionName == c) } ); - } - // POST: CommandForms/Create - [HttpPost] - [ValidateAntiForgeryToken] - public async Task Create(CommandForm commandForm) - { - if (ModelState.IsValid) - { - _context.CommandForm.Add(commandForm); - await _context.SaveChangesAsync(User.GetUserId()); - return RedirectToAction("Index"); - } - SetViewBag(commandForm); - return View(commandForm); - } - - // GET: CommandForms/Edit/5 - public async Task Edit(long? id) - { - if (id == null) - { - return HttpNotFound(); - } - - CommandForm commandForm = await _context.CommandForm.SingleAsync(m => m.Id == id); - if (commandForm == null) - { - return HttpNotFound(); - } - SetViewBag(commandForm); - return View(commandForm); - } - - // POST: CommandForms/Edit/5 - [HttpPost] - [ValidateAntiForgeryToken] - public async Task Edit(CommandForm commandForm) - { - if (ModelState.IsValid) - { - _context.Update(commandForm); - await _context.SaveChangesAsync(User.GetUserId()); - return RedirectToAction("Index"); - } - SetViewBag(commandForm); - return View(commandForm); - } - - // GET: CommandForms/Delete/5 - [ActionName("Delete")] - public async Task Delete(long? id) - { - if (id == null) - { - return HttpNotFound(); - } - - CommandForm commandForm = await _context.CommandForm.SingleAsync(m => m.Id == id); - if (commandForm == null) - { - return HttpNotFound(); - } - - return View(commandForm); - } - - // POST: CommandForms/Delete/5 - [HttpPost, ActionName("Delete")] - [ValidateAntiForgeryToken] - public async Task DeleteConfirmed(long id) - { - CommandForm commandForm = await _context.CommandForm.SingleAsync(m => m.Id == id); - _context.CommandForm.Remove(commandForm); - await _context.SaveChangesAsync(User.GetUserId()); - return RedirectToAction("Index"); - } - } -} +using System.Linq; +using System.Security.Claims; +using System.Threading.Tasks; +using Microsoft.AspNet.Mvc; +using Microsoft.AspNet.Mvc.Rendering; +using Microsoft.Data.Entity; +using Yavsc.Models; +using Yavsc.Models.Workflow; + +namespace Yavsc.Controllers +{ + public class CommandFormsController : Controller + { + private ApplicationDbContext _context; + + public CommandFormsController(ApplicationDbContext context) + { + _context = context; + } + + // GET: CommandForms + public async Task Index() + { + var applicationDbContext = _context.CommandForm.Include(c => c.Context); + return View(await applicationDbContext.ToListAsync()); + } + + // GET: CommandForms/Details/5 + public async Task Details(long? id) + { + if (id == null) + { + return HttpNotFound(); + } + + CommandForm commandForm = await _context.CommandForm.SingleAsync(m => m.Id == id); + if (commandForm == null) + { + return HttpNotFound(); + } + + return View(commandForm); + } + + // GET: CommandForms/Create + public IActionResult Create() + { + SetViewBag(); + return View(); + } + private void SetViewBag(CommandForm commandForm=null) { + ViewBag.ActivityCode = new SelectList(_context.Activities, "Code", "Name", commandForm?.ActivityCode); + ViewBag.ActionName = Startup.Forms.Select( c => new SelectListItem { Value = c, Text = c, Selected = (commandForm?.ActionName == c) } ); + } + // POST: CommandForms/Create + [HttpPost] + [ValidateAntiForgeryToken] + public async Task Create(CommandForm commandForm) + { + if (ModelState.IsValid) + { + _context.CommandForm.Add(commandForm); + await _context.SaveChangesAsync(User.GetUserId()); + return RedirectToAction("Index"); + } + SetViewBag(commandForm); + return View(commandForm); + } + + // GET: CommandForms/Edit/5 + public async Task Edit(long? id) + { + if (id == null) + { + return HttpNotFound(); + } + + CommandForm commandForm = await _context.CommandForm.SingleAsync(m => m.Id == id); + if (commandForm == null) + { + return HttpNotFound(); + } + SetViewBag(commandForm); + return View(commandForm); + } + + // POST: CommandForms/Edit/5 + [HttpPost] + [ValidateAntiForgeryToken] + public async Task Edit(CommandForm commandForm) + { + if (ModelState.IsValid) + { + _context.Update(commandForm); + await _context.SaveChangesAsync(User.GetUserId()); + return RedirectToAction("Index"); + } + SetViewBag(commandForm); + return View(commandForm); + } + + // GET: CommandForms/Delete/5 + [ActionName("Delete")] + public async Task Delete(long? id) + { + if (id == null) + { + return HttpNotFound(); + } + + CommandForm commandForm = await _context.CommandForm.SingleAsync(m => m.Id == id); + if (commandForm == null) + { + return HttpNotFound(); + } + + return View(commandForm); + } + + // POST: CommandForms/Delete/5 + [HttpPost, ActionName("Delete")] + [ValidateAntiForgeryToken] + public async Task DeleteConfirmed(long id) + { + CommandForm commandForm = await _context.CommandForm.SingleAsync(m => m.Id == id); + _context.CommandForm.Remove(commandForm); + await _context.SaveChangesAsync(User.GetUserId()); + return RedirectToAction("Index"); + } + } +} diff --git a/Yavsc/Controllers/DjSettingsController.cs b/Yavsc/Controllers/Contracting/DjSettingsController.cs similarity index 96% rename from Yavsc/Controllers/DjSettingsController.cs rename to Yavsc/Controllers/Contracting/DjSettingsController.cs index 8ee90a17..8d424aa2 100644 --- a/Yavsc/Controllers/DjSettingsController.cs +++ b/Yavsc/Controllers/Contracting/DjSettingsController.cs @@ -1,120 +1,120 @@ -using System.Threading.Tasks; -using Microsoft.AspNet.Mvc; -using Microsoft.Data.Entity; -using Yavsc.Models; -using Yavsc.Models.Musical.Profiles; - -namespace Yavsc.Controllers -{ - public class DjSettingsController : Controller - { - private ApplicationDbContext _context; - - public DjSettingsController(ApplicationDbContext context) - { - _context = context; - } - - // GET: DjSettings - public async Task Index() - { - return View(await _context.DjSettings.ToListAsync()); - } - - // GET: DjSettings/Details/5 - public async Task Details(string id) - { - if (id == null) - { - return HttpNotFound(); - } - - DjSettings djSettings = await _context.DjSettings.SingleAsync(m => m.UserId == id); - if (djSettings == null) - { - return HttpNotFound(); - } - - return View(djSettings); - } - - // GET: DjSettings/Create - public IActionResult Create() - { - return View(); - } - - // POST: DjSettings/Create - [HttpPost] - [ValidateAntiForgeryToken] - public async Task Create(DjSettings djSettings) - { - if (ModelState.IsValid) - { - _context.DjSettings.Add(djSettings); - await _context.SaveChangesAsync(); - return RedirectToAction("Index"); - } - return View(djSettings); - } - - // GET: DjSettings/Edit/5 - public async Task Edit(string id) - { - if (id == null) - { - return HttpNotFound(); - } - - DjSettings djSettings = await _context.DjSettings.SingleAsync(m => m.UserId == id); - if (djSettings == null) - { - return HttpNotFound(); - } - return View(djSettings); - } - - // POST: DjSettings/Edit/5 - [HttpPost] - [ValidateAntiForgeryToken] - public async Task Edit(DjSettings djSettings) - { - if (ModelState.IsValid) - { - _context.Update(djSettings); - await _context.SaveChangesAsync(); - return RedirectToAction("Index"); - } - return View(djSettings); - } - - // GET: DjSettings/Delete/5 - [ActionName("Delete")] - public async Task Delete(string id) - { - if (id == null) - { - return HttpNotFound(); - } - - DjSettings djSettings = await _context.DjSettings.SingleAsync(m => m.UserId == id); - if (djSettings == null) - { - return HttpNotFound(); - } - - return View(djSettings); - } - - // POST: DjSettings/Delete/5 - [HttpPost, ActionName("Delete")] - [ValidateAntiForgeryToken] - public async Task DeleteConfirmed(string id) - { - DjSettings djSettings = await _context.DjSettings.SingleAsync(m => m.UserId == id); - _context.DjSettings.Remove(djSettings); - await _context.SaveChangesAsync(); - return RedirectToAction("Index"); - } - } -} +using System.Threading.Tasks; +using Microsoft.AspNet.Mvc; +using Microsoft.Data.Entity; +using Yavsc.Models; +using Yavsc.Models.Musical.Profiles; + +namespace Yavsc.Controllers +{ + public class DjSettingsController : Controller + { + private ApplicationDbContext _context; + + public DjSettingsController(ApplicationDbContext context) + { + _context = context; + } + + // GET: DjSettings + public async Task Index() + { + return View(await _context.DjSettings.ToListAsync()); + } + + // GET: DjSettings/Details/5 + public async Task Details(string id) + { + if (id == null) + { + return HttpNotFound(); + } + + DjSettings djSettings = await _context.DjSettings.SingleAsync(m => m.UserId == id); + if (djSettings == null) + { + return HttpNotFound(); + } + + return View(djSettings); + } + + // GET: DjSettings/Create + public IActionResult Create() + { + return View(); + } + + // POST: DjSettings/Create + [HttpPost] + [ValidateAntiForgeryToken] + public async Task Create(DjSettings djSettings) + { + if (ModelState.IsValid) + { + _context.DjSettings.Add(djSettings); + await _context.SaveChangesAsync(); + return RedirectToAction("Index"); + } + return View(djSettings); + } + + // GET: DjSettings/Edit/5 + public async Task Edit(string id) + { + if (id == null) + { + return HttpNotFound(); + } + + DjSettings djSettings = await _context.DjSettings.SingleAsync(m => m.UserId == id); + if (djSettings == null) + { + return HttpNotFound(); + } + return View(djSettings); + } + + // POST: DjSettings/Edit/5 + [HttpPost] + [ValidateAntiForgeryToken] + public async Task Edit(DjSettings djSettings) + { + if (ModelState.IsValid) + { + _context.Update(djSettings); + await _context.SaveChangesAsync(); + return RedirectToAction("Index"); + } + return View(djSettings); + } + + // GET: DjSettings/Delete/5 + [ActionName("Delete")] + public async Task Delete(string id) + { + if (id == null) + { + return HttpNotFound(); + } + + DjSettings djSettings = await _context.DjSettings.SingleAsync(m => m.UserId == id); + if (djSettings == null) + { + return HttpNotFound(); + } + + return View(djSettings); + } + + // POST: DjSettings/Delete/5 + [HttpPost, ActionName("Delete")] + [ValidateAntiForgeryToken] + public async Task DeleteConfirmed(string id) + { + DjSettings djSettings = await _context.DjSettings.SingleAsync(m => m.UserId == id); + _context.DjSettings.Remove(djSettings); + await _context.SaveChangesAsync(); + return RedirectToAction("Index"); + } + } +} diff --git a/Yavsc/Controllers/DoController.cs b/Yavsc/Controllers/Contracting/DoController.cs similarity index 97% rename from Yavsc/Controllers/DoController.cs rename to Yavsc/Controllers/Contracting/DoController.cs index 67373391..61ef2480 100644 --- a/Yavsc/Controllers/DoController.cs +++ b/Yavsc/Controllers/Contracting/DoController.cs @@ -1,189 +1,189 @@ -using System.Linq; -using System.Security.Claims; -using Microsoft.AspNet.Authorization; -using Microsoft.AspNet.Mvc; -using Microsoft.AspNet.Mvc.Rendering; -using Microsoft.Data.Entity; - -namespace Yavsc.Controllers -{ - using Microsoft.Extensions.Logging; - using Models; - using Models.Workflow; - using Yavsc.ViewModels.Workflow; - using Yavsc.Services; - using System.Threading.Tasks; - using Newtonsoft.Json; - - [Authorize] - public class DoController : Controller - { - private ApplicationDbContext dbContext; - ILogger logger; - IBillingService billing; - public DoController( - ApplicationDbContext context, - IBillingService billing, - ILogger logger) - { - dbContext = context; - this.billing = billing; - this.logger = logger; - } - - // GET: /Do/Index - [HttpGet] - public IActionResult Index(string id) - { - if (id == null) - id = User.GetUserId(); - - var userActivities = dbContext.UserActivities.Include(u => u.Does) - .Include(u => u.User).Where(u=> u.UserId == id) - .OrderByDescending(u => u.Weight); - return View(userActivities.ToList()); - } - - // GET: Do/Details/5 - public async Task Details(string id, string activityCode) - { - - if (id == null || activityCode == null) - { - return HttpNotFound(); - } - - UserActivity userActivity = dbContext.UserActivities.Include(m=>m.Does) - .Include(m=>m.User).Single(m => m.DoesCode == activityCode && m.UserId == id); - if (userActivity == null) - { - return HttpNotFound(); - } - bool hasConfigurableSettings = (userActivity.Does.SettingsClassName != null); - var settings = await billing.GetPerformerSettingsAsync(activityCode,id); - ViewBag.ProfileType = Startup.ProfileTypes.Single(t=>t.FullName==userActivity.Does.SettingsClassName); - - var gift = new UserActivityViewModel { - Declaration = userActivity, - Settings = settings, - NeedsSettings = hasConfigurableSettings - }; - logger.LogInformation(JsonConvert.SerializeObject(gift.Settings)); - return View (gift); - } - - // GET: Do/Create - [ActionName("Create"),Authorize] - public IActionResult Create(string userId) - { - if (userId==null) - userId = User.GetUserId(); - var model = new UserActivity { UserId = userId }; - ViewBag.DoesCode = new SelectList(dbContext.Activities, "Code", "Name"); - //ViewData["UserId"] = userId; - ViewBag.UserId = new SelectList(dbContext.Performers.Include(p=>p.Performer), "PerformerId", "Performer", userId); - return View(model); - } - - // POST: Do/Create - [HttpPost(),ActionName("Create"),Authorize] - [ValidateAntiForgeryToken] - public IActionResult Create(UserActivity userActivity) - { - var uid = User.GetUserId(); - if (!User.IsInRole("Administrator")) - if (uid != userActivity.UserId) - ModelState.AddModelError("User","You're not admin."); - if (userActivity.UserId == null) userActivity.UserId = uid; - if (ModelState.IsValid) - { - dbContext.UserActivities.Add(userActivity); - dbContext.SaveChanges(User.GetUserId()); - return RedirectToAction("Index"); - } - ViewBag.DoesCode = new SelectList(dbContext.Activities, "Code", "Name", userActivity.DoesCode); - ViewBag.UserId = new SelectList(dbContext.Performers.Include(p=>p.Performer), "PerformerId", "User", userActivity.UserId); - return View(userActivity); - } - - // GET: Do/Edit/5 - [Authorize] - public IActionResult Edit(string id, string activityCode) - { - if (id == null) - { - return HttpNotFound(); - } - - UserActivity userActivity = dbContext.UserActivities.Include( - u=>u.Does - ).Include( - u=>u.User - ).Single(m => m.DoesCode == activityCode && m.UserId == id); - if (userActivity == null) - { - return HttpNotFound(); - } - ViewData["DoesCode"] = new SelectList(dbContext.Activities, "Code", "Does", userActivity.DoesCode); - ViewData["UserId"] = new SelectList(dbContext.Performers, "PerformerId", "User", userActivity.UserId); - return View(userActivity); - } - - // POST: Do/Edit/5 - [HttpPost,Authorize] - [ValidateAntiForgeryToken] - public IActionResult Edit(UserActivity userActivity) - { - if (!User.IsInRole("Administrator")) - if (User.GetUserId() != userActivity.UserId) - ModelState.AddModelError("User","You're not admin."); - if (ModelState.IsValid) - { - dbContext.Update(userActivity); - dbContext.SaveChanges(User.GetUserId()); - return RedirectToAction("Index"); - } - ViewData["DoesCode"] = new SelectList(dbContext.Activities, "Code", "Does", userActivity.DoesCode); - ViewData["UserId"] = new SelectList(dbContext.Performers, "PerformerId", "User", userActivity.UserId); - return View(userActivity); - } - - // GET: Do/Delete/5 - [ActionName("Delete"),Authorize] - public IActionResult Delete(string id, string activityCode) - { - if (id == null) - { - return HttpNotFound(); - } - - UserActivity userActivity = dbContext.UserActivities.Single(m => m.UserId == id && m.DoesCode == activityCode); - - if (userActivity == null) - { - return HttpNotFound(); - } - if (!User.IsInRole("Administrator")) - if (User.GetUserId() != userActivity.UserId) - ModelState.AddModelError("User","You're not admin."); - return View(userActivity); - } - - // POST: Do/Delete/5 - [HttpPost, ActionName("Delete"),Authorize] - [ValidateAntiForgeryToken] - public IActionResult DeleteConfirmed(UserActivity userActivity) - { - if (!ModelState.IsValid) - return new BadRequestObjectResult(ModelState); - if (!User.IsInRole("Administrator")) - if (User.GetUserId() != userActivity.UserId) { - ModelState.AddModelError("User","You're not admin."); - return RedirectToAction("Index"); - } - dbContext.UserActivities.Remove(userActivity); - dbContext.SaveChanges(User.GetUserId()); - return RedirectToAction("Index"); - } - } -} +using System.Linq; +using System.Security.Claims; +using Microsoft.AspNet.Authorization; +using Microsoft.AspNet.Mvc; +using Microsoft.AspNet.Mvc.Rendering; +using Microsoft.Data.Entity; + +namespace Yavsc.Controllers +{ + using Microsoft.Extensions.Logging; + using Models; + using Models.Workflow; + using Yavsc.ViewModels.Workflow; + using Yavsc.Services; + using System.Threading.Tasks; + using Newtonsoft.Json; + + [Authorize] + public class DoController : Controller + { + private ApplicationDbContext dbContext; + ILogger logger; + IBillingService billing; + public DoController( + ApplicationDbContext context, + IBillingService billing, + ILogger logger) + { + dbContext = context; + this.billing = billing; + this.logger = logger; + } + + // GET: /Do/Index + [HttpGet] + public IActionResult Index(string id) + { + if (id == null) + id = User.GetUserId(); + + var userActivities = dbContext.UserActivities.Include(u => u.Does) + .Include(u => u.User).Where(u=> u.UserId == id) + .OrderByDescending(u => u.Weight); + return View(userActivities.ToList()); + } + + // GET: Do/Details/5 + public async Task Details(string id, string activityCode) + { + + if (id == null || activityCode == null) + { + return HttpNotFound(); + } + + UserActivity userActivity = dbContext.UserActivities.Include(m=>m.Does) + .Include(m=>m.User).Single(m => m.DoesCode == activityCode && m.UserId == id); + if (userActivity == null) + { + return HttpNotFound(); + } + bool hasConfigurableSettings = (userActivity.Does.SettingsClassName != null); + var settings = await billing.GetPerformerSettingsAsync(activityCode,id); + ViewBag.ProfileType = Startup.ProfileTypes.Single(t=>t.FullName==userActivity.Does.SettingsClassName); + + var gift = new UserActivityViewModel { + Declaration = userActivity, + Settings = settings, + NeedsSettings = hasConfigurableSettings + }; + logger.LogInformation(JsonConvert.SerializeObject(gift.Settings)); + return View (gift); + } + + // GET: Do/Create + [ActionName("Create"),Authorize] + public IActionResult Create(string userId) + { + if (userId==null) + userId = User.GetUserId(); + var model = new UserActivity { UserId = userId }; + ViewBag.DoesCode = new SelectList(dbContext.Activities, "Code", "Name"); + //ViewData["UserId"] = userId; + ViewBag.UserId = new SelectList(dbContext.Performers.Include(p=>p.Performer), "PerformerId", "Performer", userId); + return View(model); + } + + // POST: Do/Create + [HttpPost(),ActionName("Create"),Authorize] + [ValidateAntiForgeryToken] + public IActionResult Create(UserActivity userActivity) + { + var uid = User.GetUserId(); + if (!User.IsInRole("Administrator")) + if (uid != userActivity.UserId) + ModelState.AddModelError("User","You're not admin."); + if (userActivity.UserId == null) userActivity.UserId = uid; + if (ModelState.IsValid) + { + dbContext.UserActivities.Add(userActivity); + dbContext.SaveChanges(User.GetUserId()); + return RedirectToAction("Index"); + } + ViewBag.DoesCode = new SelectList(dbContext.Activities, "Code", "Name", userActivity.DoesCode); + ViewBag.UserId = new SelectList(dbContext.Performers.Include(p=>p.Performer), "PerformerId", "User", userActivity.UserId); + return View(userActivity); + } + + // GET: Do/Edit/5 + [Authorize] + public IActionResult Edit(string id, string activityCode) + { + if (id == null) + { + return HttpNotFound(); + } + + UserActivity userActivity = dbContext.UserActivities.Include( + u=>u.Does + ).Include( + u=>u.User + ).Single(m => m.DoesCode == activityCode && m.UserId == id); + if (userActivity == null) + { + return HttpNotFound(); + } + ViewData["DoesCode"] = new SelectList(dbContext.Activities, "Code", "Does", userActivity.DoesCode); + ViewData["UserId"] = new SelectList(dbContext.Performers, "PerformerId", "User", userActivity.UserId); + return View(userActivity); + } + + // POST: Do/Edit/5 + [HttpPost,Authorize] + [ValidateAntiForgeryToken] + public IActionResult Edit(UserActivity userActivity) + { + if (!User.IsInRole("Administrator")) + if (User.GetUserId() != userActivity.UserId) + ModelState.AddModelError("User","You're not admin."); + if (ModelState.IsValid) + { + dbContext.Update(userActivity); + dbContext.SaveChanges(User.GetUserId()); + return RedirectToAction("Index"); + } + ViewData["DoesCode"] = new SelectList(dbContext.Activities, "Code", "Does", userActivity.DoesCode); + ViewData["UserId"] = new SelectList(dbContext.Performers, "PerformerId", "User", userActivity.UserId); + return View(userActivity); + } + + // GET: Do/Delete/5 + [ActionName("Delete"),Authorize] + public IActionResult Delete(string id, string activityCode) + { + if (id == null) + { + return HttpNotFound(); + } + + UserActivity userActivity = dbContext.UserActivities.Single(m => m.UserId == id && m.DoesCode == activityCode); + + if (userActivity == null) + { + return HttpNotFound(); + } + if (!User.IsInRole("Administrator")) + if (User.GetUserId() != userActivity.UserId) + ModelState.AddModelError("User","You're not admin."); + return View(userActivity); + } + + // POST: Do/Delete/5 + [HttpPost, ActionName("Delete"),Authorize] + [ValidateAntiForgeryToken] + public IActionResult DeleteConfirmed(UserActivity userActivity) + { + if (!ModelState.IsValid) + return new BadRequestObjectResult(ModelState); + if (!User.IsInRole("Administrator")) + if (User.GetUserId() != userActivity.UserId) { + ModelState.AddModelError("User","You're not admin."); + return RedirectToAction("Index"); + } + dbContext.UserActivities.Remove(userActivity); + dbContext.SaveChanges(User.GetUserId()); + return RedirectToAction("Index"); + } + } +} diff --git a/Yavsc/Controllers/EstimateController.cs b/Yavsc/Controllers/Contracting/EstimateController.cs similarity index 97% rename from Yavsc/Controllers/EstimateController.cs rename to Yavsc/Controllers/Contracting/EstimateController.cs index e9205313..a6c05101 100644 --- a/Yavsc/Controllers/EstimateController.cs +++ b/Yavsc/Controllers/Contracting/EstimateController.cs @@ -1,220 +1,220 @@ -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Net.Mime; -using System.Security.Claims; -using System.Threading.Tasks; -using Microsoft.AspNet.Authorization; -using Microsoft.AspNet.Http; -using Microsoft.AspNet.Mvc; -using Microsoft.Data.Entity; -using Microsoft.Extensions.OptionsModel; - -namespace Yavsc.Controllers -{ - using Helpers; - using Models; - using Models.Billing; - using Models.Workflow; - using ViewModels.Auth; - using Yavsc.Abstract.FileSystem; - - [Authorize] - public class EstimateController : Controller - { - private ApplicationDbContext _context; - private SiteSettings _site; - - IAuthorizationService authorizationService; - - public EstimateController(ApplicationDbContext context, IAuthorizationService authorizationService, IOptions siteSettings) - { - _context = context; - _site = siteSettings.Value; - this.authorizationService = authorizationService; - } - - // GET: Estimate - - public IActionResult Index() - { - var uid = User.GetUserId(); - return View(_context.Estimates.Include(e=>e.Query) - .Include(e=>e.Query.PerformerProfile) - .Include(e=>e.Query.PerformerProfile.Performer) - .Where( - e=>e.OwnerId == uid || e.ClientId == uid - ).OrderByDescending(e=>e.ProviderValidationDate) - .ToList()); - } - - // GET: Estimate/Details/5 - public async Task Details(long? id) - { - var uid = User.GetUserId(); - if (id == null) - { - return HttpNotFound(); - } - - Estimate estimate = _context.Estimates - .Include(e => e.Query) - .Include(e => e.Query.PerformerProfile) - .Include(e => e.Query.PerformerProfile.Performer) - .Include(e=> e.Bill) - .Where( - e=>e.OwnerId == uid || e.ClientId == uid - ) - .Single(m => m.Id == id); - if (estimate == null) - { - return HttpNotFound(); - } - if (!await authorizationService.AuthorizeAsync(User, estimate, new ViewRequirement())) - { - return new ChallengeResult(); - } - return View(estimate); - } - - - // GET: Estimate/Create - [Authorize] - public IActionResult Create() - { - var uid = User.GetUserId(); - IQueryable queries = _context.RdvQueries.Include(q=>q.Location).Where(bq=>bq.PerformerId == uid); - //.Select(bq=>new SelectListItem{ Text = bq.Client.UserName, Value = bq.Client.Id }); - ViewBag.Clients = queries.Select(q=>q.Client).Distinct(); - ViewBag.Queries = queries; - - return View(); - } - - // POST: Estimate/Create - [HttpPost] - [ValidateAntiForgeryToken] - public IActionResult Create(Estimate estimate, - ICollection newGraphics, - ICollection newFiles - ) - { - estimate.OwnerId = User.GetUserId(); - if (ModelState.IsValid) - { - _context.Estimates - .Add(estimate); - _context.SaveChanges(User.GetUserId()); - var query = _context.RdvQueries.FirstOrDefault( - q=>q.Id == estimate.CommandId - ); - var perfomerProfile = _context.Performers - .Include( - perpr => perpr.Performer).FirstOrDefault( - x=>x.PerformerId == query.PerformerId - ); - var command = _context.RdvQueries.FirstOrDefault( - cmd => cmd.Id == estimate.CommandId - ); - - var billsdir = Path.Combine( - _site.UserFiles.Bills, - perfomerProfile.Performer.UserName - ); - - foreach (var gr in newGraphics) - { - ContentDisposition contentDisposition = new ContentDisposition(gr.ContentDisposition); - gr.SaveAs( - Path.Combine( - Path.Combine(billsdir, estimate.Id.ToString()), - contentDisposition.FileName)); - } - foreach (var formFile in newFiles) - { - ContentDisposition contentDisposition = new ContentDisposition(formFile.ContentDisposition); - formFile.SaveAs( - Path.Combine( - Path.Combine(billsdir, estimate.Id.ToString()), - contentDisposition.FileName)); - } - return RedirectToAction("Index"); - } - return View(estimate); - } - - - private void Save(ICollection newGraphics, - ICollection newFiles) { - - } - // GET: Estimate/Edit/5 - public IActionResult Edit(long? id) - { - if (id == null) - { - return HttpNotFound(); - } - var uid = User.GetUserId(); - - Estimate estimate = _context.Estimates - .Where(e=>e.OwnerId==uid||e.ClientId==uid).Single(m => m.Id == id); - if (estimate == null) - { - return HttpNotFound(); - } - - ViewBag.Files = User.GetUserFiles(null); - - return View(estimate); - } - - // POST: Estimate/Edit/5 - [HttpPost] - [ValidateAntiForgeryToken] - public IActionResult Edit(Estimate estimate) - { - var uid = User.GetUserId(); - if (estimate.OwnerId!=uid&&estimate.ClientId!=uid - ) return new HttpNotFoundResult(); - if (ModelState.IsValid) - { - _context.Update(estimate); - _context.SaveChanges(User.GetUserId()); - return RedirectToAction("Index"); - } - return View(estimate); - } - - // GET: Estimate/Delete/5 - [ActionName("Delete")] - public IActionResult Delete(long? id) - { - if (id == null) - { - return HttpNotFound(); - } - var uid = User.GetUserId(); - - Estimate estimate = _context.Estimates - .Where(e=>e.OwnerId==uid||e.ClientId==uid) .Single(m => m.Id == id); - if (estimate == null) - { - return HttpNotFound(); - } - - return View(estimate); - } - - // POST: Estimate/Delete/5 - [HttpPost, ActionName("Delete")] - [ValidateAntiForgeryToken] - public IActionResult DeleteConfirmed(long id) - { - Estimate estimate = _context.Estimates.Single(m => m.Id == id); - _context.Estimates.Remove(estimate); - _context.SaveChanges(User.GetUserId()); - return RedirectToAction("Index"); - } - } -} +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Net.Mime; +using System.Security.Claims; +using System.Threading.Tasks; +using Microsoft.AspNet.Authorization; +using Microsoft.AspNet.Http; +using Microsoft.AspNet.Mvc; +using Microsoft.Data.Entity; +using Microsoft.Extensions.OptionsModel; + +namespace Yavsc.Controllers +{ + using Helpers; + using Models; + using Models.Billing; + using Models.Workflow; + using ViewModels.Auth; + using Yavsc.Abstract.FileSystem; + + [Authorize] + public class EstimateController : Controller + { + private ApplicationDbContext _context; + private SiteSettings _site; + + IAuthorizationService authorizationService; + + public EstimateController(ApplicationDbContext context, IAuthorizationService authorizationService, IOptions siteSettings) + { + _context = context; + _site = siteSettings.Value; + this.authorizationService = authorizationService; + } + + // GET: Estimate + + public IActionResult Index() + { + var uid = User.GetUserId(); + return View(_context.Estimates.Include(e=>e.Query) + .Include(e=>e.Query.PerformerProfile) + .Include(e=>e.Query.PerformerProfile.Performer) + .Where( + e=>e.OwnerId == uid || e.ClientId == uid + ).OrderByDescending(e=>e.ProviderValidationDate) + .ToList()); + } + + // GET: Estimate/Details/5 + public async Task Details(long? id) + { + var uid = User.GetUserId(); + if (id == null) + { + return HttpNotFound(); + } + + Estimate estimate = _context.Estimates + .Include(e => e.Query) + .Include(e => e.Query.PerformerProfile) + .Include(e => e.Query.PerformerProfile.Performer) + .Include(e=> e.Bill) + .Where( + e=>e.OwnerId == uid || e.ClientId == uid + ) + .Single(m => m.Id == id); + if (estimate == null) + { + return HttpNotFound(); + } + if (!await authorizationService.AuthorizeAsync(User, estimate, new ViewRequirement())) + { + return new ChallengeResult(); + } + return View(estimate); + } + + + // GET: Estimate/Create + [Authorize] + public IActionResult Create() + { + var uid = User.GetUserId(); + IQueryable queries = _context.RdvQueries.Include(q=>q.Location).Where(bq=>bq.PerformerId == uid); + //.Select(bq=>new SelectListItem{ Text = bq.Client.UserName, Value = bq.Client.Id }); + ViewBag.Clients = queries.Select(q=>q.Client).Distinct(); + ViewBag.Queries = queries; + + return View(); + } + + // POST: Estimate/Create + [HttpPost] + [ValidateAntiForgeryToken] + public IActionResult Create(Estimate estimate, + ICollection newGraphics, + ICollection newFiles + ) + { + estimate.OwnerId = User.GetUserId(); + if (ModelState.IsValid) + { + _context.Estimates + .Add(estimate); + _context.SaveChanges(User.GetUserId()); + var query = _context.RdvQueries.FirstOrDefault( + q=>q.Id == estimate.CommandId + ); + var perfomerProfile = _context.Performers + .Include( + perpr => perpr.Performer).FirstOrDefault( + x=>x.PerformerId == query.PerformerId + ); + var command = _context.RdvQueries.FirstOrDefault( + cmd => cmd.Id == estimate.CommandId + ); + + var billsdir = Path.Combine( + _site.UserFiles.Bills, + perfomerProfile.Performer.UserName + ); + + foreach (var gr in newGraphics) + { + ContentDisposition contentDisposition = new ContentDisposition(gr.ContentDisposition); + gr.SaveAs( + Path.Combine( + Path.Combine(billsdir, estimate.Id.ToString()), + contentDisposition.FileName)); + } + foreach (var formFile in newFiles) + { + ContentDisposition contentDisposition = new ContentDisposition(formFile.ContentDisposition); + formFile.SaveAs( + Path.Combine( + Path.Combine(billsdir, estimate.Id.ToString()), + contentDisposition.FileName)); + } + return RedirectToAction("Index"); + } + return View(estimate); + } + + + private void Save(ICollection newGraphics, + ICollection newFiles) { + + } + // GET: Estimate/Edit/5 + public IActionResult Edit(long? id) + { + if (id == null) + { + return HttpNotFound(); + } + var uid = User.GetUserId(); + + Estimate estimate = _context.Estimates + .Where(e=>e.OwnerId==uid||e.ClientId==uid).Single(m => m.Id == id); + if (estimate == null) + { + return HttpNotFound(); + } + + ViewBag.Files = User.GetUserFiles(null); + + return View(estimate); + } + + // POST: Estimate/Edit/5 + [HttpPost] + [ValidateAntiForgeryToken] + public IActionResult Edit(Estimate estimate) + { + var uid = User.GetUserId(); + if (estimate.OwnerId!=uid&&estimate.ClientId!=uid + ) return new HttpNotFoundResult(); + if (ModelState.IsValid) + { + _context.Update(estimate); + _context.SaveChanges(User.GetUserId()); + return RedirectToAction("Index"); + } + return View(estimate); + } + + // GET: Estimate/Delete/5 + [ActionName("Delete")] + public IActionResult Delete(long? id) + { + if (id == null) + { + return HttpNotFound(); + } + var uid = User.GetUserId(); + + Estimate estimate = _context.Estimates + .Where(e=>e.OwnerId==uid||e.ClientId==uid) .Single(m => m.Id == id); + if (estimate == null) + { + return HttpNotFound(); + } + + return View(estimate); + } + + // POST: Estimate/Delete/5 + [HttpPost, ActionName("Delete")] + [ValidateAntiForgeryToken] + public IActionResult DeleteConfirmed(long id) + { + Estimate estimate = _context.Estimates.Single(m => m.Id == id); + _context.Estimates.Remove(estimate); + _context.SaveChanges(User.GetUserId()); + return RedirectToAction("Index"); + } + } +} diff --git a/Yavsc/Controllers/FormationSettingsController.cs b/Yavsc/Controllers/Contracting/FormationSettingsController.cs similarity index 95% rename from Yavsc/Controllers/FormationSettingsController.cs rename to Yavsc/Controllers/Contracting/FormationSettingsController.cs index 7df2a455..bece3484 100644 --- a/Yavsc/Controllers/FormationSettingsController.cs +++ b/Yavsc/Controllers/Contracting/FormationSettingsController.cs @@ -1,15 +1,15 @@ -using Yavsc.Controllers.Generic; -using Yavsc.Models; -using Yavsc.Models.Workflow.Profiles; - -namespace Yavsc.Controllers -{ - public class FormationSettingsController : SettingsController - { - - public FormationSettingsController(ApplicationDbContext context) : base(context) - { - } - - } -} +using Yavsc.Controllers.Generic; +using Yavsc.Models; +using Yavsc.Models.Workflow.Profiles; + +namespace Yavsc.Controllers +{ + public class FormationSettingsController : SettingsController + { + + public FormationSettingsController(ApplicationDbContext context) : base(context) + { + } + + } +} diff --git a/Yavsc/Controllers/FormsController.cs b/Yavsc/Controllers/Contracting/FormsController.cs similarity index 96% rename from Yavsc/Controllers/FormsController.cs rename to Yavsc/Controllers/Contracting/FormsController.cs index b1898821..2c2ffde6 100644 --- a/Yavsc/Controllers/FormsController.cs +++ b/Yavsc/Controllers/Contracting/FormsController.cs @@ -1,121 +1,121 @@ -using System.Security.Claims; -using System.Threading.Tasks; -using Microsoft.AspNet.Mvc; -using Microsoft.Data.Entity; -using Yavsc.Models; -using Yavsc.Models.Forms; - -namespace Yavsc.Controllers -{ - public class FormsController : Controller - { - private ApplicationDbContext _context; - - public FormsController(ApplicationDbContext context) - { - _context = context; - } - - // GET: Forms - public async Task Index() - { - return View(await _context.Form.ToListAsync()); - } - - // GET: Forms/Details/5 - public async Task Details(string id) - { - if (id == null) - { - return HttpNotFound(); - } - - Form form = await _context.Form.SingleAsync(m => m.Id == id); - if (form == null) - { - return HttpNotFound(); - } - - return View(form); - } - - // GET: Forms/Create - public IActionResult Create() - { - return View(); - } - - // POST: Forms/Create - [HttpPost] - [ValidateAntiForgeryToken] - public async Task Create(Form form) - { - if (ModelState.IsValid) - { - _context.Form.Add(form); - await _context.SaveChangesAsync(User.GetUserId()); - return RedirectToAction("Index"); - } - return View(form); - } - - // GET: Forms/Edit/5 - public async Task Edit(string id) - { - if (id == null) - { - return HttpNotFound(); - } - - Form form = await _context.Form.SingleAsync(m => m.Id == id); - if (form == null) - { - return HttpNotFound(); - } - return View(form); - } - - // POST: Forms/Edit/5 - [HttpPost] - [ValidateAntiForgeryToken] - public async Task Edit(Form form) - { - if (ModelState.IsValid) - { - _context.Update(form); - await _context.SaveChangesAsync(User.GetUserId()); - return RedirectToAction("Index"); - } - return View(form); - } - - // GET: Forms/Delete/5 - [ActionName("Delete")] - public async Task Delete(string id) - { - if (id == null) - { - return HttpNotFound(); - } - - Form form = await _context.Form.SingleAsync(m => m.Id == id); - if (form == null) - { - return HttpNotFound(); - } - - return View(form); - } - - // POST: Forms/Delete/5 - [HttpPost, ActionName("Delete")] - [ValidateAntiForgeryToken] - public async Task DeleteConfirmed(string id) - { - Form form = await _context.Form.SingleAsync(m => m.Id == id); - _context.Form.Remove(form); - await _context.SaveChangesAsync(User.GetUserId()); - return RedirectToAction("Index"); - } - } -} +using System.Security.Claims; +using System.Threading.Tasks; +using Microsoft.AspNet.Mvc; +using Microsoft.Data.Entity; +using Yavsc.Models; +using Yavsc.Models.Forms; + +namespace Yavsc.Controllers +{ + public class FormsController : Controller + { + private ApplicationDbContext _context; + + public FormsController(ApplicationDbContext context) + { + _context = context; + } + + // GET: Forms + public async Task Index() + { + return View(await _context.Form.ToListAsync()); + } + + // GET: Forms/Details/5 + public async Task Details(string id) + { + if (id == null) + { + return HttpNotFound(); + } + + Form form = await _context.Form.SingleAsync(m => m.Id == id); + if (form == null) + { + return HttpNotFound(); + } + + return View(form); + } + + // GET: Forms/Create + public IActionResult Create() + { + return View(); + } + + // POST: Forms/Create + [HttpPost] + [ValidateAntiForgeryToken] + public async Task Create(Form form) + { + if (ModelState.IsValid) + { + _context.Form.Add(form); + await _context.SaveChangesAsync(User.GetUserId()); + return RedirectToAction("Index"); + } + return View(form); + } + + // GET: Forms/Edit/5 + public async Task Edit(string id) + { + if (id == null) + { + return HttpNotFound(); + } + + Form form = await _context.Form.SingleAsync(m => m.Id == id); + if (form == null) + { + return HttpNotFound(); + } + return View(form); + } + + // POST: Forms/Edit/5 + [HttpPost] + [ValidateAntiForgeryToken] + public async Task Edit(Form form) + { + if (ModelState.IsValid) + { + _context.Update(form); + await _context.SaveChangesAsync(User.GetUserId()); + return RedirectToAction("Index"); + } + return View(form); + } + + // GET: Forms/Delete/5 + [ActionName("Delete")] + public async Task Delete(string id) + { + if (id == null) + { + return HttpNotFound(); + } + + Form form = await _context.Form.SingleAsync(m => m.Id == id); + if (form == null) + { + return HttpNotFound(); + } + + return View(form); + } + + // POST: Forms/Delete/5 + [HttpPost, ActionName("Delete")] + [ValidateAntiForgeryToken] + public async Task DeleteConfirmed(string id) + { + Form form = await _context.Form.SingleAsync(m => m.Id == id); + _context.Form.Remove(form); + await _context.SaveChangesAsync(User.GetUserId()); + return RedirectToAction("Index"); + } + } +} diff --git a/Yavsc/Controllers/FrontOfficeController.cs b/Yavsc/Controllers/Contracting/FrontOfficeController.cs similarity index 100% rename from Yavsc/Controllers/FrontOfficeController.cs rename to Yavsc/Controllers/Contracting/FrontOfficeController.cs diff --git a/Yavsc/Controllers/GeneralSettingsController.cs b/Yavsc/Controllers/Contracting/GeneralSettingsController.cs similarity index 96% rename from Yavsc/Controllers/GeneralSettingsController.cs rename to Yavsc/Controllers/Contracting/GeneralSettingsController.cs index 502b1003..ef7da395 100644 --- a/Yavsc/Controllers/GeneralSettingsController.cs +++ b/Yavsc/Controllers/Contracting/GeneralSettingsController.cs @@ -1,120 +1,120 @@ -using System.Threading.Tasks; -using Microsoft.AspNet.Mvc; -using Microsoft.Data.Entity; -using Yavsc.Models; -using Yavsc.Models.Musical.Profiles; - -namespace Yavsc.Controllers -{ - public class GeneralSettingsController : Controller - { - private ApplicationDbContext _context; - - public GeneralSettingsController(ApplicationDbContext context) - { - _context = context; - } - - // GET: GeneralSettings - public async Task Index() - { - return View(await _context.GeneralSettings.ToListAsync()); - } - - // GET: GeneralSettings/Details/5 - public async Task Details(string id) - { - if (id == null) - { - return HttpNotFound(); - } - - GeneralSettings generalSettings = await _context.GeneralSettings.SingleAsync(m => m.UserId == id); - if (generalSettings == null) - { - return HttpNotFound(); - } - - return View(generalSettings); - } - - // GET: GeneralSettings/Create - public IActionResult Create() - { - return View(); - } - - // POST: GeneralSettings/Create - [HttpPost] - [ValidateAntiForgeryToken] - public async Task Create(GeneralSettings generalSettings) - { - if (ModelState.IsValid) - { - _context.GeneralSettings.Add(generalSettings); - await _context.SaveChangesAsync(); - return RedirectToAction("Index"); - } - return View(generalSettings); - } - - // GET: GeneralSettings/Edit/5 - public async Task Edit(string id) - { - if (id == null) - { - return HttpNotFound(); - } - - GeneralSettings generalSettings = await _context.GeneralSettings.SingleAsync(m => m.UserId == id); - if (generalSettings == null) - { - return HttpNotFound(); - } - return View(generalSettings); - } - - // POST: GeneralSettings/Edit/5 - [HttpPost] - [ValidateAntiForgeryToken] - public async Task Edit(GeneralSettings generalSettings) - { - if (ModelState.IsValid) - { - _context.Update(generalSettings); - await _context.SaveChangesAsync(); - return RedirectToAction("Index"); - } - return View(generalSettings); - } - - // GET: GeneralSettings/Delete/5 - [ActionName("Delete")] - public async Task Delete(string id) - { - if (id == null) - { - return HttpNotFound(); - } - - GeneralSettings generalSettings = await _context.GeneralSettings.SingleAsync(m => m.UserId == id); - if (generalSettings == null) - { - return HttpNotFound(); - } - - return View(generalSettings); - } - - // POST: GeneralSettings/Delete/5 - [HttpPost, ActionName("Delete")] - [ValidateAntiForgeryToken] - public async Task DeleteConfirmed(string id) - { - GeneralSettings generalSettings = await _context.GeneralSettings.SingleAsync(m => m.UserId == id); - _context.GeneralSettings.Remove(generalSettings); - await _context.SaveChangesAsync(); - return RedirectToAction("Index"); - } - } -} +using System.Threading.Tasks; +using Microsoft.AspNet.Mvc; +using Microsoft.Data.Entity; +using Yavsc.Models; +using Yavsc.Models.Musical.Profiles; + +namespace Yavsc.Controllers +{ + public class GeneralSettingsController : Controller + { + private ApplicationDbContext _context; + + public GeneralSettingsController(ApplicationDbContext context) + { + _context = context; + } + + // GET: GeneralSettings + public async Task Index() + { + return View(await _context.GeneralSettings.ToListAsync()); + } + + // GET: GeneralSettings/Details/5 + public async Task Details(string id) + { + if (id == null) + { + return HttpNotFound(); + } + + GeneralSettings generalSettings = await _context.GeneralSettings.SingleAsync(m => m.UserId == id); + if (generalSettings == null) + { + return HttpNotFound(); + } + + return View(generalSettings); + } + + // GET: GeneralSettings/Create + public IActionResult Create() + { + return View(); + } + + // POST: GeneralSettings/Create + [HttpPost] + [ValidateAntiForgeryToken] + public async Task Create(GeneralSettings generalSettings) + { + if (ModelState.IsValid) + { + _context.GeneralSettings.Add(generalSettings); + await _context.SaveChangesAsync(); + return RedirectToAction("Index"); + } + return View(generalSettings); + } + + // GET: GeneralSettings/Edit/5 + public async Task Edit(string id) + { + if (id == null) + { + return HttpNotFound(); + } + + GeneralSettings generalSettings = await _context.GeneralSettings.SingleAsync(m => m.UserId == id); + if (generalSettings == null) + { + return HttpNotFound(); + } + return View(generalSettings); + } + + // POST: GeneralSettings/Edit/5 + [HttpPost] + [ValidateAntiForgeryToken] + public async Task Edit(GeneralSettings generalSettings) + { + if (ModelState.IsValid) + { + _context.Update(generalSettings); + await _context.SaveChangesAsync(); + return RedirectToAction("Index"); + } + return View(generalSettings); + } + + // GET: GeneralSettings/Delete/5 + [ActionName("Delete")] + public async Task Delete(string id) + { + if (id == null) + { + return HttpNotFound(); + } + + GeneralSettings generalSettings = await _context.GeneralSettings.SingleAsync(m => m.UserId == id); + if (generalSettings == null) + { + return HttpNotFound(); + } + + return View(generalSettings); + } + + // POST: GeneralSettings/Delete/5 + [HttpPost, ActionName("Delete")] + [ValidateAntiForgeryToken] + public async Task DeleteConfirmed(string id) + { + GeneralSettings generalSettings = await _context.GeneralSettings.SingleAsync(m => m.UserId == id); + _context.GeneralSettings.Remove(generalSettings); + await _context.SaveChangesAsync(); + return RedirectToAction("Index"); + } + } +} diff --git a/Yavsc/Controllers/Haircut/BrusherProfileController.cs b/Yavsc/Controllers/Contracting/Haircut/BrusherProfileController.cs similarity index 95% rename from Yavsc/Controllers/Haircut/BrusherProfileController.cs rename to Yavsc/Controllers/Contracting/Haircut/BrusherProfileController.cs index a6729dd3..d8874cc8 100644 --- a/Yavsc/Controllers/Haircut/BrusherProfileController.cs +++ b/Yavsc/Controllers/Contracting/Haircut/BrusherProfileController.cs @@ -1,17 +1,17 @@ -using Yavsc.Models; -using Yavsc.Models.Haircut; -using Microsoft.AspNet.Authorization; -using Yavsc.Controllers.Generic; - -namespace Yavsc.Controllers -{ - [Authorize(Roles="Performer")] - public class BrusherProfileController : SettingsController - { - public BrusherProfileController(ApplicationDbContext context) : base(context) - { - - } - - } -} +using Yavsc.Models; +using Yavsc.Models.Haircut; +using Microsoft.AspNet.Authorization; +using Yavsc.Controllers.Generic; + +namespace Yavsc.Controllers +{ + [Authorize(Roles="Performer")] + public class BrusherProfileController : SettingsController + { + public BrusherProfileController(ApplicationDbContext context) : base(context) + { + + } + + } +} diff --git a/Yavsc/Controllers/ColorsController.cs b/Yavsc/Controllers/Contracting/Haircut/ColorsController.cs similarity index 96% rename from Yavsc/Controllers/ColorsController.cs rename to Yavsc/Controllers/Contracting/Haircut/ColorsController.cs index a97dba84..914a5930 100644 --- a/Yavsc/Controllers/ColorsController.cs +++ b/Yavsc/Controllers/Contracting/Haircut/ColorsController.cs @@ -1,121 +1,121 @@ -using System.Security.Claims; -using System.Threading.Tasks; -using Microsoft.AspNet.Mvc; -using Microsoft.Data.Entity; -using Yavsc.Models; -using Yavsc.Models.Drawing; - -namespace Yavsc.Controllers -{ - public class ColorsController : Controller - { - private ApplicationDbContext _context; - - public ColorsController(ApplicationDbContext context) - { - _context = context; - } - - // GET: Colors - public async Task Index() - { - return View(await _context.Color.ToListAsync()); - } - - // GET: Colors/Details/5 - public async Task Details(long? id) - { - if (id == null) - { - return HttpNotFound(); - } - - Color color = await _context.Color.SingleAsync(m => m.Id == id); - if (color == null) - { - return HttpNotFound(); - } - - return View(color); - } - - // GET: Colors/Create - public IActionResult Create() - { - return View(new Color()); - } - - // POST: Colors/Create - [HttpPost] - [ValidateAntiForgeryToken] - public async Task Create(Color color) - { - if (ModelState.IsValid) - { - _context.Color.Add(color); - await _context.SaveChangesAsync(User.GetUserId()); - return RedirectToAction("Index"); - } - return View(color); - } - - // GET: Colors/Edit/5 - public async Task Edit(long? id) - { - if (id == null) - { - return HttpNotFound(); - } - - Color color = await _context.Color.SingleAsync(m => m.Id == id); - if (color == null) - { - return HttpNotFound(); - } - return View(color); - } - - // POST: Colors/Edit/5 - [HttpPost] - [ValidateAntiForgeryToken] - public async Task Edit(Color color) - { - if (ModelState.IsValid) - { - _context.Update(color); - await _context.SaveChangesAsync(User.GetUserId()); - return RedirectToAction("Index"); - } - return View(color); - } - - // GET: Colors/Delete/5 - [ActionName("Delete")] - public async Task Delete(long? id) - { - if (id == null) - { - return HttpNotFound(); - } - - Color color = await _context.Color.SingleAsync(m => m.Id == id); - if (color == null) - { - return HttpNotFound(); - } - - return View(color); - } - - // POST: Colors/Delete/5 - [HttpPost, ActionName("Delete")] - [ValidateAntiForgeryToken] - public async Task DeleteConfirmed(long id) - { - Color color = await _context.Color.SingleAsync(m => m.Id == id); - _context.Color.Remove(color); - await _context.SaveChangesAsync(User.GetUserId()); - return RedirectToAction("Index"); - } - } -} +using System.Security.Claims; +using System.Threading.Tasks; +using Microsoft.AspNet.Mvc; +using Microsoft.Data.Entity; +using Yavsc.Models; +using Yavsc.Models.Drawing; + +namespace Yavsc.Controllers +{ + public class ColorsController : Controller + { + private ApplicationDbContext _context; + + public ColorsController(ApplicationDbContext context) + { + _context = context; + } + + // GET: Colors + public async Task Index() + { + return View(await _context.Color.ToListAsync()); + } + + // GET: Colors/Details/5 + public async Task Details(long? id) + { + if (id == null) + { + return HttpNotFound(); + } + + Color color = await _context.Color.SingleAsync(m => m.Id == id); + if (color == null) + { + return HttpNotFound(); + } + + return View(color); + } + + // GET: Colors/Create + public IActionResult Create() + { + return View(new Color()); + } + + // POST: Colors/Create + [HttpPost] + [ValidateAntiForgeryToken] + public async Task Create(Color color) + { + if (ModelState.IsValid) + { + _context.Color.Add(color); + await _context.SaveChangesAsync(User.GetUserId()); + return RedirectToAction("Index"); + } + return View(color); + } + + // GET: Colors/Edit/5 + public async Task Edit(long? id) + { + if (id == null) + { + return HttpNotFound(); + } + + Color color = await _context.Color.SingleAsync(m => m.Id == id); + if (color == null) + { + return HttpNotFound(); + } + return View(color); + } + + // POST: Colors/Edit/5 + [HttpPost] + [ValidateAntiForgeryToken] + public async Task Edit(Color color) + { + if (ModelState.IsValid) + { + _context.Update(color); + await _context.SaveChangesAsync(User.GetUserId()); + return RedirectToAction("Index"); + } + return View(color); + } + + // GET: Colors/Delete/5 + [ActionName("Delete")] + public async Task Delete(long? id) + { + if (id == null) + { + return HttpNotFound(); + } + + Color color = await _context.Color.SingleAsync(m => m.Id == id); + if (color == null) + { + return HttpNotFound(); + } + + return View(color); + } + + // POST: Colors/Delete/5 + [HttpPost, ActionName("Delete")] + [ValidateAntiForgeryToken] + public async Task DeleteConfirmed(long id) + { + Color color = await _context.Color.SingleAsync(m => m.Id == id); + _context.Color.Remove(color); + await _context.SaveChangesAsync(User.GetUserId()); + return RedirectToAction("Index"); + } + } +} diff --git a/Yavsc/Controllers/Haircut/HairCutCommandController.cs b/Yavsc/Controllers/Contracting/Haircut/HairCutCommandController.cs similarity index 100% rename from Yavsc/Controllers/Haircut/HairCutCommandController.cs rename to Yavsc/Controllers/Contracting/Haircut/HairCutCommandController.cs diff --git a/Yavsc/Controllers/Haircut/HairPrestationsController.cs b/Yavsc/Controllers/Contracting/Haircut/HairPrestationsController.cs similarity index 96% rename from Yavsc/Controllers/Haircut/HairPrestationsController.cs rename to Yavsc/Controllers/Contracting/Haircut/HairPrestationsController.cs index f77fcd2c..4294a686 100644 --- a/Yavsc/Controllers/Haircut/HairPrestationsController.cs +++ b/Yavsc/Controllers/Contracting/Haircut/HairPrestationsController.cs @@ -1,120 +1,120 @@ -using System.Threading.Tasks; -using Microsoft.AspNet.Mvc; -using Microsoft.Data.Entity; -using Yavsc.Models; -using Yavsc.Models.Haircut; - -namespace Yavsc.Controllers -{ - public class HairPrestationsController : Controller - { - private ApplicationDbContext _context; - - public HairPrestationsController(ApplicationDbContext context) - { - _context = context; - } - - // GET: HairPrestations - public async Task Index() - { - return View(await _context.HairPrestation.ToListAsync()); - } - - // GET: HairPrestations/Details/5 - public async Task Details(long? id) - { - if (id == null) - { - return HttpNotFound(); - } - - HairPrestation hairPrestation = await _context.HairPrestation.SingleAsync(m => m.Id == id); - if (hairPrestation == null) - { - return HttpNotFound(); - } - - return View(hairPrestation); - } - - // GET: HairPrestations/Create - public IActionResult Create() - { - return View(); - } - - // POST: HairPrestations/Create - [HttpPost] - [ValidateAntiForgeryToken] - public async Task Create(HairPrestation hairPrestation) - { - if (ModelState.IsValid) - { - _context.HairPrestation.Add(hairPrestation); - await _context.SaveChangesAsync(); - return RedirectToAction("Index"); - } - return View(hairPrestation); - } - - // GET: HairPrestations/Edit/5 - public async Task Edit(long? id) - { - if (id == null) - { - return HttpNotFound(); - } - - HairPrestation hairPrestation = await _context.HairPrestation.SingleAsync(m => m.Id == id); - if (hairPrestation == null) - { - return HttpNotFound(); - } - return View(hairPrestation); - } - - // POST: HairPrestations/Edit/5 - [HttpPost] - [ValidateAntiForgeryToken] - public async Task Edit(HairPrestation hairPrestation) - { - if (ModelState.IsValid) - { - _context.Update(hairPrestation); - await _context.SaveChangesAsync(); - return RedirectToAction("Index"); - } - return View(hairPrestation); - } - - // GET: HairPrestations/Delete/5 - [ActionName("Delete")] - public async Task Delete(long? id) - { - if (id == null) - { - return HttpNotFound(); - } - - HairPrestation hairPrestation = await _context.HairPrestation.SingleAsync(m => m.Id == id); - if (hairPrestation == null) - { - return HttpNotFound(); - } - - return View(hairPrestation); - } - - // POST: HairPrestations/Delete/5 - [HttpPost, ActionName("Delete")] - [ValidateAntiForgeryToken] - public async Task DeleteConfirmed(long id) - { - HairPrestation hairPrestation = await _context.HairPrestation.SingleAsync(m => m.Id == id); - _context.HairPrestation.Remove(hairPrestation); - await _context.SaveChangesAsync(); - return RedirectToAction("Index"); - } - } -} +using System.Threading.Tasks; +using Microsoft.AspNet.Mvc; +using Microsoft.Data.Entity; +using Yavsc.Models; +using Yavsc.Models.Haircut; + +namespace Yavsc.Controllers +{ + public class HairPrestationsController : Controller + { + private ApplicationDbContext _context; + + public HairPrestationsController(ApplicationDbContext context) + { + _context = context; + } + + // GET: HairPrestations + public async Task Index() + { + return View(await _context.HairPrestation.ToListAsync()); + } + + // GET: HairPrestations/Details/5 + public async Task Details(long? id) + { + if (id == null) + { + return HttpNotFound(); + } + + HairPrestation hairPrestation = await _context.HairPrestation.SingleAsync(m => m.Id == id); + if (hairPrestation == null) + { + return HttpNotFound(); + } + + return View(hairPrestation); + } + + // GET: HairPrestations/Create + public IActionResult Create() + { + return View(); + } + + // POST: HairPrestations/Create + [HttpPost] + [ValidateAntiForgeryToken] + public async Task Create(HairPrestation hairPrestation) + { + if (ModelState.IsValid) + { + _context.HairPrestation.Add(hairPrestation); + await _context.SaveChangesAsync(); + return RedirectToAction("Index"); + } + return View(hairPrestation); + } + + // GET: HairPrestations/Edit/5 + public async Task Edit(long? id) + { + if (id == null) + { + return HttpNotFound(); + } + + HairPrestation hairPrestation = await _context.HairPrestation.SingleAsync(m => m.Id == id); + if (hairPrestation == null) + { + return HttpNotFound(); + } + return View(hairPrestation); + } + + // POST: HairPrestations/Edit/5 + [HttpPost] + [ValidateAntiForgeryToken] + public async Task Edit(HairPrestation hairPrestation) + { + if (ModelState.IsValid) + { + _context.Update(hairPrestation); + await _context.SaveChangesAsync(); + return RedirectToAction("Index"); + } + return View(hairPrestation); + } + + // GET: HairPrestations/Delete/5 + [ActionName("Delete")] + public async Task Delete(long? id) + { + if (id == null) + { + return HttpNotFound(); + } + + HairPrestation hairPrestation = await _context.HairPrestation.SingleAsync(m => m.Id == id); + if (hairPrestation == null) + { + return HttpNotFound(); + } + + return View(hairPrestation); + } + + // POST: HairPrestations/Delete/5 + [HttpPost, ActionName("Delete")] + [ValidateAntiForgeryToken] + public async Task DeleteConfirmed(long id) + { + HairPrestation hairPrestation = await _context.HairPrestation.SingleAsync(m => m.Id == id); + _context.HairPrestation.Remove(hairPrestation); + await _context.SaveChangesAsync(); + return RedirectToAction("Index"); + } + } +} diff --git a/Yavsc/Controllers/Haircut/HairTaintsController.cs b/Yavsc/Controllers/Contracting/Haircut/HairTaintsController.cs similarity index 96% rename from Yavsc/Controllers/Haircut/HairTaintsController.cs rename to Yavsc/Controllers/Contracting/Haircut/HairTaintsController.cs index 6fca488c..9384d110 100644 --- a/Yavsc/Controllers/Haircut/HairTaintsController.cs +++ b/Yavsc/Controllers/Contracting/Haircut/HairTaintsController.cs @@ -1,129 +1,129 @@ -using System.Security.Claims; -using System.Threading.Tasks; -using Microsoft.AspNet.Authorization; -using Microsoft.AspNet.Mvc; -using Microsoft.AspNet.Mvc.Rendering; -using Microsoft.Data.Entity; -using Yavsc.Models; -using Yavsc.Models.Haircut; - -namespace Yavsc.Controllers -{ - [Authorize("AdministratorOnly")] - public class HairTaintsController : Controller - { - private ApplicationDbContext _context; - - public HairTaintsController(ApplicationDbContext context) - { - _context = context; - } - - // GET: HairTaints - public async Task Index() - { - var applicationDbContext = _context.HairTaint.Include(h => h.Color); - return View(await applicationDbContext.ToListAsync()); - } - - // GET: HairTaints/Details/5 - public async Task Details(long? id) - { - if (id == null) - { - return HttpNotFound(); - } - - HairTaint hairTaint = await _context.HairTaint.SingleAsync(m => m.Id == id); - if (hairTaint == null) - { - return HttpNotFound(); - } - - return View(hairTaint); - } - - // GET: HairTaints/Create - public IActionResult Create() - { - ViewBag.ColorId = new SelectList(_context.Color, "Id", "Name"); - return View(); - } - - // POST: HairTaints/Create - [HttpPost] - [ValidateAntiForgeryToken] - public async Task Create(HairTaint hairTaint) - { - if (ModelState.IsValid) - { - _context.HairTaint.Add(hairTaint); - await _context.SaveChangesAsync(User.GetUserId()); - return RedirectToAction("Index"); - } - ViewBag.ColorId = new SelectList(_context.Color, "Id", "Name", hairTaint.ColorId); - return View(hairTaint); - } - - // GET: HairTaints/Edit/5 - public async Task Edit(long? id) - { - if (id == null) - { - return HttpNotFound(); - } - - HairTaint hairTaint = await _context.HairTaint.SingleAsync(m => m.Id == id); - if (hairTaint == null) - { - return HttpNotFound(); - } - ViewBag.ColorId = new SelectList(_context.Color, "Id", "Name",hairTaint.ColorId); - return View(hairTaint); - } - - // POST: HairTaints/Edit/5 - [HttpPost] - [ValidateAntiForgeryToken] - public async Task Edit(HairTaint hairTaint) - { - if (ModelState.IsValid) - { - _context.Update(hairTaint); - await _context.SaveChangesAsync(User.GetUserId()); - return RedirectToAction("Index"); - } - ViewBag.ColorId = new SelectList(_context.Color, "Id", "Name", hairTaint.ColorId); - return View(hairTaint); - } - - // GET: HairTaints/Delete/5 - [ActionName("Delete")] - public async Task Delete(long? id) - { - if (id == null) - { - return HttpNotFound(); - } - - HairTaint hairTaint = await _context.HairTaint.SingleAsync(m => m.Id == id); - if (hairTaint == null) - { - return HttpNotFound(); - } - - return View(hairTaint); - } - - // POST: HairTaints/Delete/5 - [HttpPost, ActionName("Delete")] - [ValidateAntiForgeryToken] - public async Task DeleteConfirmed(long id) - { - HairTaint hairTaint = await _context.HairTaint.SingleAsync(m => m.Id == id); - _context.HairTaint.Remove(hairTaint); - await _context.SaveChangesAsync(User.GetUserId()); - return RedirectToAction("Index"); - } - } -} +using System.Security.Claims; +using System.Threading.Tasks; +using Microsoft.AspNet.Authorization; +using Microsoft.AspNet.Mvc; +using Microsoft.AspNet.Mvc.Rendering; +using Microsoft.Data.Entity; +using Yavsc.Models; +using Yavsc.Models.Haircut; + +namespace Yavsc.Controllers +{ + [Authorize("AdministratorOnly")] + public class HairTaintsController : Controller + { + private ApplicationDbContext _context; + + public HairTaintsController(ApplicationDbContext context) + { + _context = context; + } + + // GET: HairTaints + public async Task Index() + { + var applicationDbContext = _context.HairTaint.Include(h => h.Color); + return View(await applicationDbContext.ToListAsync()); + } + + // GET: HairTaints/Details/5 + public async Task Details(long? id) + { + if (id == null) + { + return HttpNotFound(); + } + + HairTaint hairTaint = await _context.HairTaint.SingleAsync(m => m.Id == id); + if (hairTaint == null) + { + return HttpNotFound(); + } + + return View(hairTaint); + } + + // GET: HairTaints/Create + public IActionResult Create() + { + ViewBag.ColorId = new SelectList(_context.Color, "Id", "Name"); + return View(); + } + + // POST: HairTaints/Create + [HttpPost] + [ValidateAntiForgeryToken] + public async Task Create(HairTaint hairTaint) + { + if (ModelState.IsValid) + { + _context.HairTaint.Add(hairTaint); + await _context.SaveChangesAsync(User.GetUserId()); + return RedirectToAction("Index"); + } + ViewBag.ColorId = new SelectList(_context.Color, "Id", "Name", hairTaint.ColorId); + return View(hairTaint); + } + + // GET: HairTaints/Edit/5 + public async Task Edit(long? id) + { + if (id == null) + { + return HttpNotFound(); + } + + HairTaint hairTaint = await _context.HairTaint.SingleAsync(m => m.Id == id); + if (hairTaint == null) + { + return HttpNotFound(); + } + ViewBag.ColorId = new SelectList(_context.Color, "Id", "Name",hairTaint.ColorId); + return View(hairTaint); + } + + // POST: HairTaints/Edit/5 + [HttpPost] + [ValidateAntiForgeryToken] + public async Task Edit(HairTaint hairTaint) + { + if (ModelState.IsValid) + { + _context.Update(hairTaint); + await _context.SaveChangesAsync(User.GetUserId()); + return RedirectToAction("Index"); + } + ViewBag.ColorId = new SelectList(_context.Color, "Id", "Name", hairTaint.ColorId); + return View(hairTaint); + } + + // GET: HairTaints/Delete/5 + [ActionName("Delete")] + public async Task Delete(long? id) + { + if (id == null) + { + return HttpNotFound(); + } + + HairTaint hairTaint = await _context.HairTaint.SingleAsync(m => m.Id == id); + if (hairTaint == null) + { + return HttpNotFound(); + } + + return View(hairTaint); + } + + // POST: HairTaints/Delete/5 + [HttpPost, ActionName("Delete")] + [ValidateAntiForgeryToken] + public async Task DeleteConfirmed(long id) + { + HairTaint hairTaint = await _context.HairTaint.SingleAsync(m => m.Id == id); + _context.HairTaint.Remove(hairTaint); + await _context.SaveChangesAsync(User.GetUserId()); + return RedirectToAction("Index"); + } + } +} diff --git a/Yavsc/Controllers/InstrumentationController.cs b/Yavsc/Controllers/Contracting/InstrumentationController.cs similarity index 97% rename from Yavsc/Controllers/InstrumentationController.cs rename to Yavsc/Controllers/Contracting/InstrumentationController.cs index 3bde85b0..e5f321e5 100644 --- a/Yavsc/Controllers/InstrumentationController.cs +++ b/Yavsc/Controllers/Contracting/InstrumentationController.cs @@ -1,149 +1,149 @@ -using System.Linq; -using System.Security.Claims; -using System.Threading.Tasks; -using Microsoft.AspNet.Authorization; -using Microsoft.AspNet.Mvc; -using Microsoft.AspNet.Mvc.Rendering; -using Microsoft.Data.Entity; -using Yavsc.Models; -using Yavsc.Models.Musical.Profiles; - -namespace Yavsc.Controllers -{ - [Authorize] - public class InstrumentationController : Controller - { - private ApplicationDbContext _context; - - public InstrumentationController(ApplicationDbContext context) - { - _context = context; - } - - // GET: Instrumentation - public async Task Index() - { - return View(await _context.Instrumentation.ToListAsync()); - } - - // GET: Instrumentation/Details/5 - public async Task Details(string id) - { - if (id == null) - { - return HttpNotFound(); - } - - Instrumentation musicianSettings = await _context.Instrumentation.SingleAsync(m => m.UserId == id); - if (musicianSettings == null) - { - return HttpNotFound(); - } - - return View(musicianSettings); - } - - // GET: Instrumentation/Create - public IActionResult Create() - { - var uid = User.GetUserId(); - var owned = _context.Instrumentation.Include(i=>i.Tool).Where(i=>i.UserId==uid).Select(i=>i.InstrumentId); - var ownedArray = owned.ToArray(); - - ViewBag.YetAvailableInstruments = _context.Instrument.Select(k=>new SelectListItem - { Text = k.Name, Value = k.Id.ToString(), Disabled = ownedArray.Contains(k.Id) }); - - return View(new Instrumentation { UserId = uid }); - } - - // POST: Instrumentation/Create - [HttpPost] - [ValidateAntiForgeryToken] - public async Task Create(Instrumentation model) - { - var uid = User.GetUserId(); - if (ModelState.IsValid) - { - if (model.UserId != uid) if (!User.IsInRole(Constants.AdminGroupName)) - return new ChallengeResult(); - - _context.Instrumentation.Add(model); - await _context.SaveChangesAsync(User.GetUserId()); - return RedirectToAction("Index"); - } - return View(model); - } - - // GET: Instrumentation/Edit/5 - public async Task Edit(string id) - { - var uid = User.GetUserId(); - if (id == null) - { - return HttpNotFound(); - } - if (id != uid) if (!User.IsInRole(Constants.AdminGroupName)) - return new ChallengeResult(); - Instrumentation musicianSettings = await _context.Instrumentation.SingleAsync(m => m.UserId == id); - if (musicianSettings == null) - { - return HttpNotFound(); - } - return View(musicianSettings); - } - - // POST: Instrumentation/Edit/5 - [HttpPost] - [ValidateAntiForgeryToken] - public async Task Edit(Instrumentation musicianSettings) - { - var uid = User.GetUserId(); - if (musicianSettings.UserId != uid) if (!User.IsInRole(Constants.AdminGroupName)) - return new ChallengeResult(); - if (ModelState.IsValid) - { - _context.Update(musicianSettings); - await _context.SaveChangesAsync(User.GetUserId()); - return RedirectToAction("Index"); - } - return View(musicianSettings); - } - - // GET: Instrumentation/Delete/5 - [ActionName("Delete")] - public async Task Delete(string id) - { - if (id == null) - { - return HttpNotFound(); - } - - Instrumentation musicianSettings = await _context.Instrumentation.SingleAsync(m => m.UserId == id); - if (musicianSettings == null) - { - return HttpNotFound(); - } - var uid = User.GetUserId(); - if (musicianSettings.UserId != uid) if (!User.IsInRole(Constants.AdminGroupName)) - return new ChallengeResult(); - return View(musicianSettings); - } - - // POST: Instrumentation/Delete/5 - [HttpPost, ActionName("Delete")] - [ValidateAntiForgeryToken] - public async Task DeleteConfirmed(string id) - { - Instrumentation musicianSettings = await _context.Instrumentation.SingleAsync(m => m.UserId == id); - - var uid = User.GetUserId(); - if (musicianSettings.UserId != uid) if (!User.IsInRole(Constants.AdminGroupName)) - return new ChallengeResult(); - - - _context.Instrumentation.Remove(musicianSettings); - await _context.SaveChangesAsync(User.GetUserId()); - return RedirectToAction("Index"); - } - } -} +using System.Linq; +using System.Security.Claims; +using System.Threading.Tasks; +using Microsoft.AspNet.Authorization; +using Microsoft.AspNet.Mvc; +using Microsoft.AspNet.Mvc.Rendering; +using Microsoft.Data.Entity; +using Yavsc.Models; +using Yavsc.Models.Musical.Profiles; + +namespace Yavsc.Controllers +{ + [Authorize] + public class InstrumentationController : Controller + { + private ApplicationDbContext _context; + + public InstrumentationController(ApplicationDbContext context) + { + _context = context; + } + + // GET: Instrumentation + public async Task Index() + { + return View(await _context.Instrumentation.ToListAsync()); + } + + // GET: Instrumentation/Details/5 + public async Task Details(string id) + { + if (id == null) + { + return HttpNotFound(); + } + + Instrumentation musicianSettings = await _context.Instrumentation.SingleAsync(m => m.UserId == id); + if (musicianSettings == null) + { + return HttpNotFound(); + } + + return View(musicianSettings); + } + + // GET: Instrumentation/Create + public IActionResult Create() + { + var uid = User.GetUserId(); + var owned = _context.Instrumentation.Include(i=>i.Tool).Where(i=>i.UserId==uid).Select(i=>i.InstrumentId); + var ownedArray = owned.ToArray(); + + ViewBag.YetAvailableInstruments = _context.Instrument.Select(k=>new SelectListItem + { Text = k.Name, Value = k.Id.ToString(), Disabled = ownedArray.Contains(k.Id) }); + + return View(new Instrumentation { UserId = uid }); + } + + // POST: Instrumentation/Create + [HttpPost] + [ValidateAntiForgeryToken] + public async Task Create(Instrumentation model) + { + var uid = User.GetUserId(); + if (ModelState.IsValid) + { + if (model.UserId != uid) if (!User.IsInRole(Constants.AdminGroupName)) + return new ChallengeResult(); + + _context.Instrumentation.Add(model); + await _context.SaveChangesAsync(User.GetUserId()); + return RedirectToAction("Index"); + } + return View(model); + } + + // GET: Instrumentation/Edit/5 + public async Task Edit(string id) + { + var uid = User.GetUserId(); + if (id == null) + { + return HttpNotFound(); + } + if (id != uid) if (!User.IsInRole(Constants.AdminGroupName)) + return new ChallengeResult(); + Instrumentation musicianSettings = await _context.Instrumentation.SingleAsync(m => m.UserId == id); + if (musicianSettings == null) + { + return HttpNotFound(); + } + return View(musicianSettings); + } + + // POST: Instrumentation/Edit/5 + [HttpPost] + [ValidateAntiForgeryToken] + public async Task Edit(Instrumentation musicianSettings) + { + var uid = User.GetUserId(); + if (musicianSettings.UserId != uid) if (!User.IsInRole(Constants.AdminGroupName)) + return new ChallengeResult(); + if (ModelState.IsValid) + { + _context.Update(musicianSettings); + await _context.SaveChangesAsync(User.GetUserId()); + return RedirectToAction("Index"); + } + return View(musicianSettings); + } + + // GET: Instrumentation/Delete/5 + [ActionName("Delete")] + public async Task Delete(string id) + { + if (id == null) + { + return HttpNotFound(); + } + + Instrumentation musicianSettings = await _context.Instrumentation.SingleAsync(m => m.UserId == id); + if (musicianSettings == null) + { + return HttpNotFound(); + } + var uid = User.GetUserId(); + if (musicianSettings.UserId != uid) if (!User.IsInRole(Constants.AdminGroupName)) + return new ChallengeResult(); + return View(musicianSettings); + } + + // POST: Instrumentation/Delete/5 + [HttpPost, ActionName("Delete")] + [ValidateAntiForgeryToken] + public async Task DeleteConfirmed(string id) + { + Instrumentation musicianSettings = await _context.Instrumentation.SingleAsync(m => m.UserId == id); + + var uid = User.GetUserId(); + if (musicianSettings.UserId != uid) if (!User.IsInRole(Constants.AdminGroupName)) + return new ChallengeResult(); + + + _context.Instrumentation.Remove(musicianSettings); + await _context.SaveChangesAsync(User.GetUserId()); + return RedirectToAction("Index"); + } + } +} diff --git a/Yavsc/Controllers/InstrumentsController.cs b/Yavsc/Controllers/Contracting/InstrumentsController.cs similarity index 96% rename from Yavsc/Controllers/InstrumentsController.cs rename to Yavsc/Controllers/Contracting/InstrumentsController.cs index 354a7bc4..2a9e018b 100644 --- a/Yavsc/Controllers/InstrumentsController.cs +++ b/Yavsc/Controllers/Contracting/InstrumentsController.cs @@ -1,120 +1,120 @@ -using System.Linq; -using Microsoft.AspNet.Mvc; - -namespace Yavsc.Controllers -{ - using System.Security.Claims; - using Models; - using Models.Musical; - public class InstrumentsController : Controller - { - private ApplicationDbContext _context; - - public InstrumentsController(ApplicationDbContext context) - { - _context = context; - } - - // GET: Instruments - public IActionResult Index() - { - return View(_context.Instrument.ToList()); - } - - // GET: Instruments/Details/5 - public IActionResult Details(long? id) - { - if (id == null) - { - return HttpNotFound(); - } - - Instrument instrument = _context.Instrument.Single(m => m.Id == id); - if (instrument == null) - { - return HttpNotFound(); - } - - return View(instrument); - } - - // GET: Instruments/Create - public IActionResult Create() - { - return View(); - } - - // POST: Instruments/Create - [HttpPost] - [ValidateAntiForgeryToken] - public IActionResult Create(Instrument instrument) - { - if (ModelState.IsValid) - { - _context.Instrument.Add(instrument); - _context.SaveChanges(User.GetUserId()); - return RedirectToAction("Index"); - } - return View(instrument); - } - - // GET: Instruments/Edit/5 - public IActionResult Edit(long? id) - { - if (id == null) - { - return HttpNotFound(); - } - - Instrument instrument = _context.Instrument.Single(m => m.Id == id); - if (instrument == null) - { - return HttpNotFound(); - } - return View(instrument); - } - - // POST: Instruments/Edit/5 - [HttpPost] - [ValidateAntiForgeryToken] - public IActionResult Edit(Instrument instrument) - { - if (ModelState.IsValid) - { - _context.Update(instrument); - _context.SaveChanges(User.GetUserId()); - return RedirectToAction("Index"); - } - return View(instrument); - } - - // GET: Instruments/Delete/5 - [ActionName("Delete")] - public IActionResult Delete(long? id) - { - if (id == null) - { - return HttpNotFound(); - } - - Instrument instrument = _context.Instrument.Single(m => m.Id == id); - if (instrument == null) - { - return HttpNotFound(); - } - - return View(instrument); - } - - // POST: Instruments/Delete/5 - [HttpPost, ActionName("Delete")] - [ValidateAntiForgeryToken] - public IActionResult DeleteConfirmed(long id) - { - Instrument instrument = _context.Instrument.Single(m => m.Id == id); - _context.Instrument.Remove(instrument); - _context.SaveChanges(User.GetUserId()); - return RedirectToAction("Index"); - } - } -} +using System.Linq; +using Microsoft.AspNet.Mvc; + +namespace Yavsc.Controllers +{ + using System.Security.Claims; + using Models; + using Models.Musical; + public class InstrumentsController : Controller + { + private ApplicationDbContext _context; + + public InstrumentsController(ApplicationDbContext context) + { + _context = context; + } + + // GET: Instruments + public IActionResult Index() + { + return View(_context.Instrument.ToList()); + } + + // GET: Instruments/Details/5 + public IActionResult Details(long? id) + { + if (id == null) + { + return HttpNotFound(); + } + + Instrument instrument = _context.Instrument.Single(m => m.Id == id); + if (instrument == null) + { + return HttpNotFound(); + } + + return View(instrument); + } + + // GET: Instruments/Create + public IActionResult Create() + { + return View(); + } + + // POST: Instruments/Create + [HttpPost] + [ValidateAntiForgeryToken] + public IActionResult Create(Instrument instrument) + { + if (ModelState.IsValid) + { + _context.Instrument.Add(instrument); + _context.SaveChanges(User.GetUserId()); + return RedirectToAction("Index"); + } + return View(instrument); + } + + // GET: Instruments/Edit/5 + public IActionResult Edit(long? id) + { + if (id == null) + { + return HttpNotFound(); + } + + Instrument instrument = _context.Instrument.Single(m => m.Id == id); + if (instrument == null) + { + return HttpNotFound(); + } + return View(instrument); + } + + // POST: Instruments/Edit/5 + [HttpPost] + [ValidateAntiForgeryToken] + public IActionResult Edit(Instrument instrument) + { + if (ModelState.IsValid) + { + _context.Update(instrument); + _context.SaveChanges(User.GetUserId()); + return RedirectToAction("Index"); + } + return View(instrument); + } + + // GET: Instruments/Delete/5 + [ActionName("Delete")] + public IActionResult Delete(long? id) + { + if (id == null) + { + return HttpNotFound(); + } + + Instrument instrument = _context.Instrument.Single(m => m.Id == id); + if (instrument == null) + { + return HttpNotFound(); + } + + return View(instrument); + } + + // POST: Instruments/Delete/5 + [HttpPost, ActionName("Delete")] + [ValidateAntiForgeryToken] + public IActionResult DeleteConfirmed(long id) + { + Instrument instrument = _context.Instrument.Single(m => m.Id == id); + _context.Instrument.Remove(instrument); + _context.SaveChanges(User.GetUserId()); + return RedirectToAction("Index"); + } + } +} diff --git a/Yavsc/Controllers/MusicalTendenciesController.cs b/Yavsc/Controllers/Contracting/MusicalTendenciesController.cs similarity index 96% rename from Yavsc/Controllers/MusicalTendenciesController.cs rename to Yavsc/Controllers/Contracting/MusicalTendenciesController.cs index 75b07f2c..6c8421ea 100644 --- a/Yavsc/Controllers/MusicalTendenciesController.cs +++ b/Yavsc/Controllers/Contracting/MusicalTendenciesController.cs @@ -1,120 +1,120 @@ -using System.Linq; -using Microsoft.AspNet.Mvc; - -namespace Yavsc.Controllers -{ - using System.Security.Claims; - using Models; - using Models.Musical; - public class MusicalTendenciesController : Controller - { - private ApplicationDbContext _context; - - public MusicalTendenciesController(ApplicationDbContext context) - { - _context = context; - } - - // GET: MusicalTendencies - public IActionResult Index() - { - return View(_context.MusicalTendency.ToList()); - } - - // GET: MusicalTendencies/Details/5 - public IActionResult Details(long? id) - { - if (id == null) - { - return HttpNotFound(); - } - - MusicalTendency musicalTendency = _context.MusicalTendency.Single(m => m.Id == id); - if (musicalTendency == null) - { - return HttpNotFound(); - } - - return View(musicalTendency); - } - - // GET: MusicalTendencies/Create - public IActionResult Create() - { - return View(); - } - - // POST: MusicalTendencies/Create - [HttpPost] - [ValidateAntiForgeryToken] - public IActionResult Create(MusicalTendency musicalTendency) - { - if (ModelState.IsValid) - { - _context.MusicalTendency.Add(musicalTendency); - _context.SaveChanges(User.GetUserId()); - return RedirectToAction("Index"); - } - return View(musicalTendency); - } - - // GET: MusicalTendencies/Edit/5 - public IActionResult Edit(long? id) - { - if (id == null) - { - return HttpNotFound(); - } - - MusicalTendency musicalTendency = _context.MusicalTendency.Single(m => m.Id == id); - if (musicalTendency == null) - { - return HttpNotFound(); - } - return View(musicalTendency); - } - - // POST: MusicalTendencies/Edit/5 - [HttpPost] - [ValidateAntiForgeryToken] - public IActionResult Edit(MusicalTendency musicalTendency) - { - if (ModelState.IsValid) - { - _context.Update(musicalTendency); - _context.SaveChanges(User.GetUserId()); - return RedirectToAction("Index"); - } - return View(musicalTendency); - } - - // GET: MusicalTendencies/Delete/5 - [ActionName("Delete")] - public IActionResult Delete(long? id) - { - if (id == null) - { - return HttpNotFound(); - } - - MusicalTendency musicalTendency = _context.MusicalTendency.Single(m => m.Id == id); - if (musicalTendency == null) - { - return HttpNotFound(); - } - - return View(musicalTendency); - } - - // POST: MusicalTendencies/Delete/5 - [HttpPost, ActionName("Delete")] - [ValidateAntiForgeryToken] - public IActionResult DeleteConfirmed(long id) - { - MusicalTendency musicalTendency = _context.MusicalTendency.Single(m => m.Id == id); - _context.MusicalTendency.Remove(musicalTendency); - _context.SaveChanges(User.GetUserId()); - return RedirectToAction("Index"); - } - } -} +using System.Linq; +using Microsoft.AspNet.Mvc; + +namespace Yavsc.Controllers +{ + using System.Security.Claims; + using Models; + using Models.Musical; + public class MusicalTendenciesController : Controller + { + private ApplicationDbContext _context; + + public MusicalTendenciesController(ApplicationDbContext context) + { + _context = context; + } + + // GET: MusicalTendencies + public IActionResult Index() + { + return View(_context.MusicalTendency.ToList()); + } + + // GET: MusicalTendencies/Details/5 + public IActionResult Details(long? id) + { + if (id == null) + { + return HttpNotFound(); + } + + MusicalTendency musicalTendency = _context.MusicalTendency.Single(m => m.Id == id); + if (musicalTendency == null) + { + return HttpNotFound(); + } + + return View(musicalTendency); + } + + // GET: MusicalTendencies/Create + public IActionResult Create() + { + return View(); + } + + // POST: MusicalTendencies/Create + [HttpPost] + [ValidateAntiForgeryToken] + public IActionResult Create(MusicalTendency musicalTendency) + { + if (ModelState.IsValid) + { + _context.MusicalTendency.Add(musicalTendency); + _context.SaveChanges(User.GetUserId()); + return RedirectToAction("Index"); + } + return View(musicalTendency); + } + + // GET: MusicalTendencies/Edit/5 + public IActionResult Edit(long? id) + { + if (id == null) + { + return HttpNotFound(); + } + + MusicalTendency musicalTendency = _context.MusicalTendency.Single(m => m.Id == id); + if (musicalTendency == null) + { + return HttpNotFound(); + } + return View(musicalTendency); + } + + // POST: MusicalTendencies/Edit/5 + [HttpPost] + [ValidateAntiForgeryToken] + public IActionResult Edit(MusicalTendency musicalTendency) + { + if (ModelState.IsValid) + { + _context.Update(musicalTendency); + _context.SaveChanges(User.GetUserId()); + return RedirectToAction("Index"); + } + return View(musicalTendency); + } + + // GET: MusicalTendencies/Delete/5 + [ActionName("Delete")] + public IActionResult Delete(long? id) + { + if (id == null) + { + return HttpNotFound(); + } + + MusicalTendency musicalTendency = _context.MusicalTendency.Single(m => m.Id == id); + if (musicalTendency == null) + { + return HttpNotFound(); + } + + return View(musicalTendency); + } + + // POST: MusicalTendencies/Delete/5 + [HttpPost, ActionName("Delete")] + [ValidateAntiForgeryToken] + public IActionResult DeleteConfirmed(long id) + { + MusicalTendency musicalTendency = _context.MusicalTendency.Single(m => m.Id == id); + _context.MusicalTendency.Remove(musicalTendency); + _context.SaveChanges(User.GetUserId()); + return RedirectToAction("Index"); + } + } +} diff --git a/Yavsc/Controllers/SIRENExceptionsController.cs b/Yavsc/Controllers/Contracting/SIRENExceptionsController.cs similarity index 100% rename from Yavsc/Controllers/SIRENExceptionsController.cs rename to Yavsc/Controllers/Contracting/SIRENExceptionsController.cs diff --git a/Yavsc/Controllers/BlogspotController.cs b/Yavsc/Controllers/Deliver/BlogspotController.cs similarity index 97% rename from Yavsc/Controllers/BlogspotController.cs rename to Yavsc/Controllers/Deliver/BlogspotController.cs index ac4a31bd..395d7ccc 100644 --- a/Yavsc/Controllers/BlogspotController.cs +++ b/Yavsc/Controllers/Deliver/BlogspotController.cs @@ -1,259 +1,259 @@ - -using System.Linq; -using System.Security.Claims; -using System.Threading.Tasks; -using Microsoft.AspNet.Identity; -using Microsoft.AspNet.Mvc; -using Microsoft.Extensions.Logging; -using Microsoft.AspNet.Authorization; -using Microsoft.Data.Entity; -using Microsoft.Extensions.OptionsModel; -using Yavsc.Models; -using Yavsc.ViewModels.Auth; -using Microsoft.AspNet.Mvc.Rendering; -using Yavsc.ViewModels.Blogspot; -using Yavsc.Models.Blog; -// 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 - { - ILogger _logger; - private ApplicationDbContext _context; - - private SiteSettings _siteSettings; - private IAuthorizationService _authorizationService; - public BlogspotController( - ApplicationDbContext context, - UserManager userManager, - ILoggerFactory loggerFactory, - IAuthorizationService authorizationService, - IOptions siteSettings) - { - _context = context; - _logger = loggerFactory.CreateLogger(); - _authorizationService = authorizationService; - _siteSettings = siteSettings.Value; - } - - // GET: Blog - [AllowAnonymous] - public IActionResult Index(string id, int skip=0, int maxLen=25) - { - if (!string.IsNullOrEmpty(id)) - return UserPosts(id); - string uid = User.GetUserId(); - long[] usercircles = _context.Circle.Include(c=>c.Members).Where(c=>c.Members.Any(m=>m.MemberId == uid)) - .Select(c=>c.Id).ToArray(); - IQueryable posts ; - var allposts = _context.Blogspot - .Include(b => b.Author) - .Include(p=>p.ACL) - .Include(p=>p.Tags) - .Include(p=>p.Comments) - .Where(p=>p.AuthorId == uid || p.Visible); - - if (usercircles != null) { - posts = allposts.Where(p=> p.ACL.Count==0 || p.ACL.Any(a=> usercircles.Contains(a.CircleId))) - ; - } - else { - posts = allposts.Where(p => p.ACL.Count == 0); - } - - var data = posts.OrderByDescending( p=> p.DateCreated).ToArray(); - var grouped = data.GroupBy(p=> p.Title).Skip(skip).Take(maxLen); - - return View(grouped); - } - - [Route("/Title/{id?}")] - [AllowAnonymous] - public IActionResult Title(string id) - { - var uid = User.GetUserId(); - ViewData["Title"] = id; - return View("Title", _context.Blogspot.Include( - b => b.Author - ).Where(x => x.Title == id && (x.Visible || x.AuthorId == uid )).OrderByDescending( - x => x.DateCreated - ).ToList()); - } - - [Route("/Blog/{id?}")] - [AllowAnonymous] - public IActionResult UserPosts(string id) - { - - if (string.IsNullOrEmpty(id)) return Index(null); - var uid = User.GetUserId(); - long[] usercircles = _context.Circle.Include(c=>c.Members).Where(c=>c.Members.Any(m=>m.MemberId == uid)) - .Select(c=>c.Id).ToArray(); - var result = (User.IsSignedIn())? - _context.Blogspot.Include( - b => b.Author - ).Include(p=>p.ACL).Where(x => x.Author.UserName == id && (x.Visible && (x.ACL.Count==0 || x.ACL.Any(a=> usercircles.Contains(a.CircleId))))): - _context.Blogspot.Include( - b => b.Author - ).Where(x => x.Author.UserName == id && x.Visible); - // BlogIndexKey - return View("Index", result.OrderByDescending(p => p.DateCreated).ToList().GroupBy(p=> p.Title )); - } - // GET: Blog/Details/5 - [AllowAnonymous] - public async Task Details(long? id) - { - if (id == null) - { - return HttpNotFound(); - } - - BlogPost blog = _context.Blogspot - .Include(p => p.Author) - .Include(p => p.Tags) - .Include(p => p.Comments) - .Include(p => p.ACL) - .Single(m => m.Id == id); - if (blog == null) - { - return HttpNotFound(); - } - if (!await _authorizationService.AuthorizeAsync(User, blog, new ViewRequirement())) - { - return new ChallengeResult(); - } - foreach (var c in blog.Comments) { - c.Author = _context.Users.First(u=>u.Id==c.AuthorId); - } - ViewData["apicmtctlr"] = "/api/blogcomments"; - ViewData["moderatoFlag"] = User.IsInRole(Constants.BlogModeratorGroupName); - return View(blog); - } - - // GET: Blog/Create - [Authorize()] - public IActionResult Create(string title) - { - var result = new BlogPost{Title=title}; - ViewData["PostTarget"]="Create"; - return View("Edit",result); - } - - // POST: Blog/Create - [HttpPost, Authorize, ValidateAntiForgeryToken] - public IActionResult Create(Models.Blog.BlogPost blog) - { - blog.Rate = 0; - blog.AuthorId = User.GetUserId(); - blog.Id=0; - if (ModelState.IsValid) - { - - _context.Blogspot.Add(blog); - _context.SaveChanges(User.GetUserId()); - return RedirectToAction("Index"); - } - ModelState.AddModelError("Unknown","Invalid Blog posted ..."); - ViewData["PostTarget"]="Create"; - return View("Edit",blog); - } - [Authorize()] - // GET: Blog/Edit/5 - public async Task Edit(long? id) - { - if (id == null) - { - return HttpNotFound(); - } - - ViewData["PostTarget"]="Edit"; - BlogPost blog = _context.Blogspot.Include(x => x.Author).Include(x => x.ACL).Single(m => m.Id == id); - - - if (blog == null) - { - return HttpNotFound(); - } - if (await _authorizationService.AuthorizeAsync(User, blog, new EditRequirement())) - { - ViewBag.ACL = _context.Circle.Where( - c=>c.OwnerId == blog.AuthorId) - .Select( - c => new SelectListItem - { - Text = c.Name, - Value = c.Id.ToString(), - Selected = blog.AuthorizeCircle(c.Id) - }  - ); - return View(blog); - } - else - { - return new ChallengeResult(); - } - } - - // POST: Blog/Edit/5 - [HttpPost] - [ValidateAntiForgeryToken,Authorize()] - public IActionResult Edit(BlogPost blog) - { - if (ModelState.IsValid) - { - var auth = _authorizationService.AuthorizeAsync(User, blog, new EditRequirement()); - if (auth.Result) - { - // saves the change - _context.Update(blog); - _context.SaveChanges(User.GetUserId()); - ViewData["StatusMessage"] = "Post modified"; - return RedirectToAction("Index"); - } - else - { - ViewData["StatusMessage"] = "Accès restreint"; - return new ChallengeResult(); - } - } - ViewData["PostTarget"]="Edit"; - return View(blog); - } - - // GET: Blog/Delete/5 - [ActionName("Delete"),Authorize()] - public IActionResult Delete(long? id) - { - if (id == null) - { - return HttpNotFound(); - } - - BlogPost blog = _context.Blogspot.Include( - b => b.Author - ).Single(m => m.Id == id); - if (blog == null) - { - return HttpNotFound(); - } - - return View(blog); - } - - // POST: Blog/Delete/5 - [HttpPost, ActionName("Delete"), Authorize()] - [ValidateAntiForgeryToken] - public IActionResult DeleteConfirmed(long id) - { - BlogPost blog = _context.Blogspot.Single(m => m.Id == id); - var auth = _authorizationService.AuthorizeAsync(User, blog, new EditRequirement()); - if (auth.Result) - { - _context.Blogspot.Remove(blog); - _context.SaveChanges(User.GetUserId()); - } - return RedirectToAction("Index"); - } - } -} + +using System.Linq; +using System.Security.Claims; +using System.Threading.Tasks; +using Microsoft.AspNet.Identity; +using Microsoft.AspNet.Mvc; +using Microsoft.Extensions.Logging; +using Microsoft.AspNet.Authorization; +using Microsoft.Data.Entity; +using Microsoft.Extensions.OptionsModel; +using Yavsc.Models; +using Yavsc.ViewModels.Auth; +using Microsoft.AspNet.Mvc.Rendering; +using Yavsc.ViewModels.Blogspot; +using Yavsc.Models.Blog; +// 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 + { + ILogger _logger; + private ApplicationDbContext _context; + + private SiteSettings _siteSettings; + private IAuthorizationService _authorizationService; + public BlogspotController( + ApplicationDbContext context, + UserManager userManager, + ILoggerFactory loggerFactory, + IAuthorizationService authorizationService, + IOptions siteSettings) + { + _context = context; + _logger = loggerFactory.CreateLogger(); + _authorizationService = authorizationService; + _siteSettings = siteSettings.Value; + } + + // GET: Blog + [AllowAnonymous] + public IActionResult Index(string id, int skip=0, int maxLen=25) + { + if (!string.IsNullOrEmpty(id)) + return UserPosts(id); + string uid = User.GetUserId(); + long[] usercircles = _context.Circle.Include(c=>c.Members).Where(c=>c.Members.Any(m=>m.MemberId == uid)) + .Select(c=>c.Id).ToArray(); + IQueryable posts ; + var allposts = _context.Blogspot + .Include(b => b.Author) + .Include(p=>p.ACL) + .Include(p=>p.Tags) + .Include(p=>p.Comments) + .Where(p=>p.AuthorId == uid || p.Visible); + + if (usercircles != null) { + posts = allposts.Where(p=> p.ACL.Count==0 || p.ACL.Any(a=> usercircles.Contains(a.CircleId))) + ; + } + else { + posts = allposts.Where(p => p.ACL.Count == 0); + } + + var data = posts.OrderByDescending( p=> p.DateCreated).ToArray(); + var grouped = data.GroupBy(p=> p.Title).Skip(skip).Take(maxLen); + + return View(grouped); + } + + [Route("/Title/{id?}")] + [AllowAnonymous] + public IActionResult Title(string id) + { + var uid = User.GetUserId(); + ViewData["Title"] = id; + return View("Title", _context.Blogspot.Include( + b => b.Author + ).Where(x => x.Title == id && (x.Visible || x.AuthorId == uid )).OrderByDescending( + x => x.DateCreated + ).ToList()); + } + + [Route("/Blog/{id?}")] + [AllowAnonymous] + public IActionResult UserPosts(string id) + { + + if (string.IsNullOrEmpty(id)) return Index(null); + var uid = User.GetUserId(); + long[] usercircles = _context.Circle.Include(c=>c.Members).Where(c=>c.Members.Any(m=>m.MemberId == uid)) + .Select(c=>c.Id).ToArray(); + var result = (User.IsSignedIn())? + _context.Blogspot.Include( + b => b.Author + ).Include(p=>p.ACL).Where(x => x.Author.UserName == id && (x.Visible && (x.ACL.Count==0 || x.ACL.Any(a=> usercircles.Contains(a.CircleId))))): + _context.Blogspot.Include( + b => b.Author + ).Where(x => x.Author.UserName == id && x.Visible); + // BlogIndexKey + return View("Index", result.OrderByDescending(p => p.DateCreated).ToList().GroupBy(p=> p.Title )); + } + // GET: Blog/Details/5 + [AllowAnonymous] + public async Task Details(long? id) + { + if (id == null) + { + return HttpNotFound(); + } + + BlogPost blog = _context.Blogspot + .Include(p => p.Author) + .Include(p => p.Tags) + .Include(p => p.Comments) + .Include(p => p.ACL) + .Single(m => m.Id == id); + if (blog == null) + { + return HttpNotFound(); + } + if (!await _authorizationService.AuthorizeAsync(User, blog, new ViewRequirement())) + { + return new ChallengeResult(); + } + foreach (var c in blog.Comments) { + c.Author = _context.Users.First(u=>u.Id==c.AuthorId); + } + ViewData["apicmtctlr"] = "/api/blogcomments"; + ViewData["moderatoFlag"] = User.IsInRole(Constants.BlogModeratorGroupName); + return View(blog); + } + + // GET: Blog/Create + [Authorize()] + public IActionResult Create(string title) + { + var result = new BlogPost{Title=title}; + ViewData["PostTarget"]="Create"; + return View("Edit",result); + } + + // POST: Blog/Create + [HttpPost, Authorize, ValidateAntiForgeryToken] + public IActionResult Create(Models.Blog.BlogPost blog) + { + blog.Rate = 0; + blog.AuthorId = User.GetUserId(); + blog.Id=0; + if (ModelState.IsValid) + { + + _context.Blogspot.Add(blog); + _context.SaveChanges(User.GetUserId()); + return RedirectToAction("Index"); + } + ModelState.AddModelError("Unknown","Invalid Blog posted ..."); + ViewData["PostTarget"]="Create"; + return View("Edit",blog); + } + [Authorize()] + // GET: Blog/Edit/5 + public async Task Edit(long? id) + { + if (id == null) + { + return HttpNotFound(); + } + + ViewData["PostTarget"]="Edit"; + BlogPost blog = _context.Blogspot.Include(x => x.Author).Include(x => x.ACL).Single(m => m.Id == id); + + + if (blog == null) + { + return HttpNotFound(); + } + if (await _authorizationService.AuthorizeAsync(User, blog, new EditRequirement())) + { + ViewBag.ACL = _context.Circle.Where( + c=>c.OwnerId == blog.AuthorId) + .Select( + c => new SelectListItem + { + Text = c.Name, + Value = c.Id.ToString(), + Selected = blog.AuthorizeCircle(c.Id) + }  + ); + return View(blog); + } + else + { + return new ChallengeResult(); + } + } + + // POST: Blog/Edit/5 + [HttpPost] + [ValidateAntiForgeryToken,Authorize()] + public IActionResult Edit(BlogPost blog) + { + if (ModelState.IsValid) + { + var auth = _authorizationService.AuthorizeAsync(User, blog, new EditRequirement()); + if (auth.Result) + { + // saves the change + _context.Update(blog); + _context.SaveChanges(User.GetUserId()); + ViewData["StatusMessage"] = "Post modified"; + return RedirectToAction("Index"); + } + else + { + ViewData["StatusMessage"] = "Accès restreint"; + return new ChallengeResult(); + } + } + ViewData["PostTarget"]="Edit"; + return View(blog); + } + + // GET: Blog/Delete/5 + [ActionName("Delete"),Authorize()] + public IActionResult Delete(long? id) + { + if (id == null) + { + return HttpNotFound(); + } + + BlogPost blog = _context.Blogspot.Include( + b => b.Author + ).Single(m => m.Id == id); + if (blog == null) + { + return HttpNotFound(); + } + + return View(blog); + } + + // POST: Blog/Delete/5 + [HttpPost, ActionName("Delete"), Authorize()] + [ValidateAntiForgeryToken] + public IActionResult DeleteConfirmed(long id) + { + BlogPost blog = _context.Blogspot.Single(m => m.Id == id); + var auth = _authorizationService.AuthorizeAsync(User, blog, new EditRequirement()); + if (auth.Result) + { + _context.Blogspot.Remove(blog); + _context.SaveChanges(User.GetUserId()); + } + return RedirectToAction("Index"); + } + } +} diff --git a/Yavsc/Controllers/CommentsController.cs b/Yavsc/Controllers/Deliver/CommentsController.cs similarity index 100% rename from Yavsc/Controllers/CommentsController.cs rename to Yavsc/Controllers/Deliver/CommentsController.cs diff --git a/Yavsc/Controllers/NotificationsController.cs b/Yavsc/Controllers/Deliver/NotificationsController.cs similarity index 96% rename from Yavsc/Controllers/NotificationsController.cs rename to Yavsc/Controllers/Deliver/NotificationsController.cs index 53c4b76c..37e551b6 100644 --- a/Yavsc/Controllers/NotificationsController.cs +++ b/Yavsc/Controllers/Deliver/NotificationsController.cs @@ -1,121 +1,121 @@ -using System.Security.Claims; -using System.Threading.Tasks; -using Microsoft.AspNet.Mvc; -using Microsoft.Data.Entity; -using Yavsc.Models; -using Yavsc.Models.Messaging; - -namespace Yavsc.Controllers -{ - public class NotificationsController : Controller - { - private ApplicationDbContext _context; - - public NotificationsController(ApplicationDbContext context) - { - _context = context; - } - - // GET: Notifications - public async Task Index() - { - return View(await _context.Notification.ToListAsync()); - } - - // GET: Notifications/Details/5 - public async Task Details(long? id) - { - if (id == null) - { - return HttpNotFound(); - } - - Notification notification = await _context.Notification.SingleAsync(m => m.Id == id); - if (notification == null) - { - return HttpNotFound(); - } - - return View(notification); - } - - // GET: Notifications/Create - public IActionResult Create() - { - return View(); - } - - // POST: Notifications/Create - [HttpPost] - [ValidateAntiForgeryToken] - public async Task 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 Edit(long? id) - { - if (id == null) - { - return HttpNotFound(); - } - - Notification notification = await _context.Notification.SingleAsync(m => m.Id == id); - if (notification == null) - { - return HttpNotFound(); - } - return View(notification); - } - - // POST: Notifications/Edit/5 - [HttpPost] - [ValidateAntiForgeryToken] - public async Task 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 Delete(long? id) - { - if (id == null) - { - return HttpNotFound(); - } - - Notification notification = await _context.Notification.SingleAsync(m => m.Id == id); - if (notification == null) - { - return HttpNotFound(); - } - - return View(notification); - } - - // POST: Notifications/Delete/5 - [HttpPost, ActionName("Delete")] - [ValidateAntiForgeryToken] - public async Task 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"); - } - } -} +using System.Security.Claims; +using System.Threading.Tasks; +using Microsoft.AspNet.Mvc; +using Microsoft.Data.Entity; +using Yavsc.Models; +using Yavsc.Models.Messaging; + +namespace Yavsc.Controllers +{ + public class NotificationsController : Controller + { + private ApplicationDbContext _context; + + public NotificationsController(ApplicationDbContext context) + { + _context = context; + } + + // GET: Notifications + public async Task Index() + { + return View(await _context.Notification.ToListAsync()); + } + + // GET: Notifications/Details/5 + public async Task Details(long? id) + { + if (id == null) + { + return HttpNotFound(); + } + + Notification notification = await _context.Notification.SingleAsync(m => m.Id == id); + if (notification == null) + { + return HttpNotFound(); + } + + return View(notification); + } + + // GET: Notifications/Create + public IActionResult Create() + { + return View(); + } + + // POST: Notifications/Create + [HttpPost] + [ValidateAntiForgeryToken] + public async Task 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 Edit(long? id) + { + if (id == null) + { + return HttpNotFound(); + } + + Notification notification = await _context.Notification.SingleAsync(m => m.Id == id); + if (notification == null) + { + return HttpNotFound(); + } + return View(notification); + } + + // POST: Notifications/Edit/5 + [HttpPost] + [ValidateAntiForgeryToken] + public async Task 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 Delete(long? id) + { + if (id == null) + { + return HttpNotFound(); + } + + Notification notification = await _context.Notification.SingleAsync(m => m.Id == id); + if (notification == null) + { + return HttpNotFound(); + } + + return View(notification); + } + + // POST: Notifications/Delete/5 + [HttpPost, ActionName("Delete")] + [ValidateAntiForgeryToken] + public async Task 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"); + } + } +} diff --git a/Yavsc/Controllers/BugController.cs b/Yavsc/Controllers/Survey/BugController.cs similarity index 100% rename from Yavsc/Controllers/BugController.cs rename to Yavsc/Controllers/Survey/BugController.cs diff --git a/Yavsc/Controllers/FeatureController.cs b/Yavsc/Controllers/Survey/FeatureController.cs similarity index 100% rename from Yavsc/Controllers/FeatureController.cs rename to Yavsc/Controllers/Survey/FeatureController.cs diff --git a/Yavsc/Controllers/TestController.cs b/Yavsc/Controllers/Survey/TestController.cs similarity index 100% rename from Yavsc/Controllers/TestController.cs rename to Yavsc/Controllers/Survey/TestController.cs