yavsc/Yavsc/ViewComponents/CirclesControlViewComponent.cs

46 lines
1.3 KiB
C#

This file contains invisible Unicode characters!

This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.

using System.Linq;
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Mvc.Rendering;
namespace Yavsc.ViewComponents
{
using Models;
using ViewModels.Controls;
using ViewModels.Relationship;
public class CirclesControlViewComponent : ViewComponent
{
ApplicationDbContext dbContext;
public CirclesControlViewComponent(ApplicationDbContext dbContext)
{
this.dbContext = dbContext;
}
public IViewComponentResult Invoke (ICircleAuthorized target)
{
var oid = target.GetOwnerId();
ViewBag.ACL = dbContext.Circle.Where(
c=>c.OwnerId == oid)
.Select(
c => new SelectListItem
{
Text = c.Name,
Value = c.Id.ToString(),
Selected = target.AuthorizeCircle(c.Id)
} 
);
ViewBag.Access = dbContext.Circle.Where(
c=>c.OwnerId == oid)
.Select( c=>
new AjaxCheckBoxInfo
{
Text = c.Name,
Checked = target.AuthorizeCircle(c.Id),
Value = c.Id.ToString()
});
return View(new CirclesViewModel(target));
}
}
}