profiles dj, musicien, formation
This commit is contained in:
@ -1,18 +1,24 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNet.Authorization;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
using Microsoft.AspNet.Mvc.Rendering;
|
||||
using Microsoft.Data.Entity;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Yavsc.Models;
|
||||
|
||||
namespace Yavsc.Controllers
|
||||
{
|
||||
[ServiceFilter(typeof(LanguageActionFilter)),Authorize("AdministratorOnly")]
|
||||
[ServiceFilter(typeof(LanguageActionFilter)), Authorize("AdministratorOnly")]
|
||||
public class ActivityController : Controller
|
||||
{
|
||||
private ApplicationDbContext _context;
|
||||
IStringLocalizer<Yavsc.Resources.YavscLocalisation> SR;
|
||||
|
||||
public ActivityController(ApplicationDbContext context)
|
||||
public ActivityController(ApplicationDbContext context, IStringLocalizer<Yavsc.Resources.YavscLocalisation> SR)
|
||||
{
|
||||
_context = context;
|
||||
this.SR = SR;
|
||||
}
|
||||
|
||||
// GET: Activity
|
||||
@ -21,6 +27,53 @@ namespace Yavsc.Controllers
|
||||
return View(_context.Activities.ToList());
|
||||
}
|
||||
|
||||
private List<SelectListItem> GetEligibleParent(string code)
|
||||
{
|
||||
// eligibles are those
|
||||
// who are not in descendants
|
||||
|
||||
//
|
||||
var acts = _context.Activities.Where(
|
||||
a=> a.Code != code
|
||||
).Select(a => new SelectListItem
|
||||
{
|
||||
Text = a.Name,
|
||||
Value = a.Code
|
||||
}).ToList();
|
||||
acts.Add(new SelectListItem { Text=SR["aucun"], Value=null } );
|
||||
if (code == null) return acts;
|
||||
var existing = _context.Activities.Include(a => a.Children).FirstOrDefault(a => a.Code == code);
|
||||
if (existing == null) return acts;
|
||||
var pi = acts.FirstOrDefault(i=>i.Value==existing.ParentCode);
|
||||
// Assert(pi!=null)
|
||||
pi.Selected=true;
|
||||
RecFilterChild(acts, existing);
|
||||
return acts;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Filters a activity selection list
|
||||
/// in order to exculde any descendant
|
||||
/// from the eligible list at the <c>Parent</c> property.
|
||||
/// WARN! results in a infinite loop when
|
||||
/// data is corrupted and there is a circularity
|
||||
/// in the activity hierarchy graph (Parent/Children)
|
||||
/// </summary>
|
||||
/// <param name="list"></param>
|
||||
/// <param name="activity"></param>
|
||||
private static void RecFilterChild(List<SelectListItem> list, Activity activity)
|
||||
{
|
||||
if (activity == null) return;
|
||||
if (activity.Children == null) return;
|
||||
if (list.Count==0) return;
|
||||
foreach (var child in activity.Children)
|
||||
{
|
||||
RecFilterChild(list, child);
|
||||
var rem = list.FirstOrDefault(i => i.Value == child.Code);
|
||||
if (rem != null) list.Remove(rem);
|
||||
}
|
||||
}
|
||||
|
||||
// GET: Activity/Details/5
|
||||
public IActionResult Details(string id)
|
||||
{
|
||||
@ -41,6 +94,7 @@ namespace Yavsc.Controllers
|
||||
// GET: Activity/Create
|
||||
public IActionResult Create()
|
||||
{
|
||||
ViewBag.ParentCode = GetEligibleParent(null);
|
||||
return View();
|
||||
}
|
||||
|
||||
@ -71,6 +125,7 @@ namespace Yavsc.Controllers
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
ViewBag.ParentCode = GetEligibleParent(id);
|
||||
return View(activity);
|
||||
}
|
||||
|
||||
|
121
Yavsc/Controllers/InstrumentsController.cs
Normal file
121
Yavsc/Controllers/InstrumentsController.cs
Normal file
@ -0,0 +1,121 @@
|
||||
using System.Linq;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
using Microsoft.AspNet.Mvc.Rendering;
|
||||
using Microsoft.Data.Entity;
|
||||
using Yavsc.Models;
|
||||
using Yavsc.Models.Booking;
|
||||
|
||||
namespace Yavsc.Controllers
|
||||
{
|
||||
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();
|
||||
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();
|
||||
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();
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user