public async Task <IHttpActionResult> Put(PrivateUserViewModel user) { if (user.UserId != LoggedInUserId) { return(StatusCode(HttpStatusCode.Forbidden)); } var profile = await db.Profiles.FirstOrDefaultAsync(p => p.UserId == user.UserId); if (profile == null) { return(NotFound()); } profile.Gender = user.Gender; profile.FamilyName = user.FamilyName; profile.GivenName = user.GivenName; profile.NickName = user.NickName; profile.Picture = user.Picture; profile.Brief = user.Brief; profile.UpdatedAt = DateTime.Now; db.Entry(profile).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { throw; } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IHttpActionResult> GetPrivateProfile(string userId, int joinedAmount, int launchedAmount) { if (userId != LoggedInUserId) { return(Content(HttpStatusCode.Forbidden, "Trying to get forbidden info -- Meet.u")); } var user = await db .Users .FirstOrDefaultAsync(u => u.Id == userId); var profile = await db .Profiles .FirstOrDefaultAsync(p => p.UserId == userId); // if neither presented if (user == null && profile == null) { return(NotFound()); } // if only one presents, reply 500, indicating that the two tables doesn't match if (user == null || profile == null) { return(StatusCode(HttpStatusCode.InternalServerError)); } var privateUserView = new PrivateUserViewModel() { UserId = user.Id, Email = user.Email, UserName = user.UserName, Number = user.Number, NickName = profile.NickName, Picture = profile.Picture, Gender = profile.Gender, Brief = profile.Brief, CreatedAt = profile.CreatedAt, UpdatedAt = profile.UpdatedAt, //private part FamilyName = profile.FamilyName, GivenName = profile.GivenName, LoginCount = profile.LoginCount }; var JoinedMeetupIds = db.Joins.Where(j => j.UserId == user.Id); privateUserView.JoinedMeetupsTotal = db .Meetups .Where(m => JoinedMeetupIds.Count(j => j.MeetupId == m.Id) > 0) .Count(); privateUserView.LaunchedMeetupsTotal = db .Meetups .Where(m => m.Sponsor == user.Id) .Count(); return(Ok(privateUserView)); }
public ArticleViewModelFactory( PrivateUserViewModel userVm, IImageApiClient imageApiClient, IEntityHomeViewModelFactory entityHomeViewModelFactory, IArticleHomeViewModelFactory articleHomeViewModelFactory) { _userVm = userVm; _imageApiClient = imageApiClient; _entityHomeViewModelFactory = entityHomeViewModelFactory; _articleHomeViewModelFactory = articleHomeViewModelFactory; }
public MainWindowVmFactory(IEventAggregator ea, IViewManager viewManager, PrivateUserViewModel userVm, MainWindowEntityViewModel entityVm, MainWindowFullscreenViewModel fullscreenVm, IBoardCreationViewModelFactory boardCreationViewModelFactory) { _ea = ea; _viewManager = viewManager; _userVm = userVm; _entityVm = entityVm; _fullscreenVm = fullscreenVm; _boardCreationViewModelFactory = boardCreationViewModelFactory; }
public ProfileViewModel(IEventAggregator ea, PrivateUserViewModel privateUserViewModel, IBoardListViewModelFactory boardListViewModelFactory, IArticleListViewModelFactory articleListViewModelFactory, ICommentListViewModelFactory commentListViewModelFactory) { _ea = ea; PrivateUserViewModel = privateUserViewModel; BoardsModeratingListViewModel = boardListViewModelFactory.Create(LoadEntityListEnum.LoadByIds); BoardsSubscribedListViewModel = boardListViewModelFactory.Create(LoadEntityListEnum.LoadByIds); ArticlesWrittenListViewModel = articleListViewModelFactory.Create(LoadEntityListEnum.LoadByIds); ArticlesSavedListViewModel = articleListViewModelFactory.Create(LoadEntityListEnum.LoadByIds); CommentsWrittenListViewModel = commentListViewModelFactory.Create(LoadEntityListEnum.LoadByIds); CommentsSavedListViewModel = commentListViewModelFactory.Create(LoadEntityListEnum.LoadByIds); LogoutCommand = new DelegateCommand(Logout); LoadProfileCommand = new AsyncDelegateCommand(LoadProfileAsync); }
private async Task LoadProfileAsync(object parameter = null) { await PrivateUserViewModel.LoadUserAsync(); await LoadOwnedViewModelsAsync(); }
public ArticleViewModel Create(PrivateUserViewModel userVm) => new ArticleViewModel(articleViewModelFactory: this, _articleHomeViewModelFactory, _imageApiClient, _entityHomeViewModelFactory, userVm);