yavsc/Yavsc/ViewComponents/AvatarViewComponent.cs

30 lines
782 B
C#
Raw Normal View History

2017-10-05 11:58:51 +02:00
using System.Linq;
2017-02-01 19:53:10 +01:00
using Microsoft.AspNet.Mvc;
using Yavsc.Helpers;
using Yavsc.Models;
2017-10-05 11:58:51 +02:00
using Yavsc.ViewModels.Account;
2017-02-01 19:53:10 +01:00
namespace Yavsc.ViewComponents
{
public class AvatarViewComponent : ViewComponent
{
ApplicationDbContext dbContext;
public AvatarViewComponent(ApplicationDbContext dbContext)
{
this.dbContext = dbContext;
}
2017-02-02 13:49:47 +01:00
public IViewComponentResult Invoke ( string userId, string imgFmt )
2017-02-01 19:53:10 +01:00
{
2017-10-05 11:58:51 +02:00
var user = dbContext.Users.Single(u=>u.Id == userId);
return View ( "Default", new ShortUserInfo
{
Avatar = dbContext.AvatarUri(userId, imgFmt),
UserName = user.UserName,
UserId = userId
} );
2017-02-01 19:53:10 +01:00
}
}
}