public IActionResult UserItems() { int userId = 0; if (HttpContext.Session.IsAvailable) { userId = (int)(HttpContext.Session.GetInt32("UserId")); } var userItems = _context.UserItems.Where(x => x.UserId == userId).ToList(); List <Item> items = new List <Item>(); foreach (var id in userItems) { var tempItem = _context.Items.Find(id.ItemId); items.Add(tempItem); } List <UserItemViewModel> itemsToView = new List <UserItemViewModel>(); foreach (var item in items) { var model = new UserItemViewModel() { Id = item.Id, Name = item.Name, Description = item.Description, Price = item.Price }; itemsToView.Add(model); } return(View(itemsToView)); }
public ActionResult Edit(UserItemViewModel model) { try { if (ModelState.IsValid) { var data = Mapper.Map <USER>(model.Detail); _bll.SaveUser(data); AddMessageInfo("User data updated", Enums.MessageInfoType.Success); } else { var errorsStates = ModelState.Values.Where(x => x.Errors.Count > 0).ToList(); var errorMessages = (from errorState in errorsStates from error in errorState.Errors select error.ErrorMessage).ToList(); AddMessageInfo(errorMessages, Enums.MessageInfoType.Error); } } catch (Exception ex) { AddMessageInfo(ex.Message, Enums.MessageInfoType.Error); } var user = _bll.GetUserById(model.Detail.USER_ID); var changeHistoryList = _changesHistoryBll.GetByFormTypeId(Enums.MenuList.USER); var returnModel = new UserItemViewModel() { MainMenu = _mainMenu, CurrentMenu = PageInfo, Detail = Mapper.Map <UserItem>(user), ChangesHistoryList = Mapper.Map <List <ChangesHistoryItemModel> >(changeHistoryList) }; return(View("Edit", returnModel)); }
public void CommandCreated() { var UserItemViewModel = new UserItemViewModel(69, "testName", "testLastName"); var updateCommand = UserItemViewModel.UpdateCommand; Assert.IsNotNull(updateCommand); }
public void ConstructorTestOrSth() { var UserItemViewModel = new UserItemViewModel(69, "testName", "testLastName"); Assert.AreEqual(69, UserItemViewModel.Id); Assert.AreEqual("testName", UserItemViewModel.FirstName); Assert.AreEqual("testLastName", UserItemViewModel.LastName); }
//AppUser public UserItemView(AppUser appUser = null) { InitializeComponent(); BindingContext = ViewModel = new UserItemViewModel(appUser) { Navigation = Navigation }; }
public UserItemPage(Models.User user = null) { InitializeComponent(); BindingContext = viewModel = new UserItemViewModel(user) { Navigation = Navigation }; }
public IActionResult Items(int userId) { var model = new UserItemViewModel { User = _userService.Items(userId), Items = _itemService.GetItems() }; return(View(model)); }
public void UpdateValidationTest() { var UserItemViewModel = new UserItemViewModel(69, "testName", "testLastName"); var updateCommand = UserItemViewModel.UpdateCommand; UserItemViewModel.FirstName = null; UserItemViewModel.LastName = null; bool canBeExecuted = UserItemViewModel.CanUpdate; Assert.IsFalse(updateCommand.CanExecute(canBeExecuted)); }
protected override async Task Load(ReactiveList <UserItemViewModel> users) { var members = await _applicationService.Client.Groups.GetMembers(_owner, _slug); var memberUsers = members.Select(x => { var username = x.Username; var avatar = new Avatar(x.Avatar); var displayName = string.Join(" ", x.FirstName, x.LastName); var vm = new UserItemViewModel(username, displayName, avatar); vm.GoToCommand.Select(__ => new UserViewModel(username)).Subscribe(NavigateTo); return(vm); }); users.Reset(memberUsers); }
public async Task <IActionResult> CreateUser([FromBody] UserItemViewModel model) { try { using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { DbUser dbUser = new DbUser { Email = model.Email, Age = model.Age, Image = model.Image, Description = model.Description, Phone = model.Phone, UserName = model.Email }; var result = await _userManager.CreateAsync(dbUser, "Qwerty1-"); if (!result.Succeeded) { throw new Exception("Problem create user"); } foreach (var role in model.Roles) { var roleresult = await _roleManager.CreateAsync(new DbRole { Name = role.Name }); if (!roleresult.Succeeded) { throw new Exception("Problem create role"); } } throw new Exception("my exception crash"); scope.Complete(); return(Ok(dbUser.Id)); } } catch (Exception ex) { return(BadRequest(new { message = ex.Message })); } }
public ActionResult Edit(string id) { if (string.IsNullOrEmpty(id)) { return(RedirectToAction("Index")); } var user = _bll.GetUserById(id); var changeHistoryList = _changesHistoryBll.GetByFormTypeId(Enums.MenuList.USER); var model = new UserItemViewModel() { MainMenu = _mainMenu, CurrentMenu = PageInfo, Detail = Mapper.Map <UserItem>(user), ChangesHistoryList = Mapper.Map <List <ChangesHistoryItemModel> >(changeHistoryList) }; return(View("Edit", model)); }
public UserElement(UserItemViewModel viewModel) { _viewModel = viewModel; }
public PullRequestViewModel( string username, string repository, int pullRequestId, IMarkdownService markdownService = null, IApplicationService applicationService = null, IActionMenuService actionMenuService = null) { _applicationService = applicationService = applicationService ?? Locator.Current.GetService <IApplicationService>(); markdownService = markdownService ?? Locator.Current.GetService <IMarkdownService>(); actionMenuService = actionMenuService ?? Locator.Current.GetService <IActionMenuService>(); Title = $"Pull Request #{pullRequestId}"; Username = username; Repository = repository; PullRequestId = pullRequestId; Comments = _comments.CreateDerivedCollection(x => { var name = x.User.DisplayName ?? x.User.Username ?? "Unknown"; var avatar = new Avatar(x.User.Links?.Avatar?.Href); return(new CommentItemViewModel(name, avatar, x.CreatedOn.Humanize(), x.Content.Html)); }); Comments.Changed.Subscribe(_ => CommentCount = Comments.Count); LoadCommand = ReactiveCommand.CreateFromTask(async _ => { PullRequest = await applicationService.Client.PullRequests.Get(username, repository, pullRequestId); _comments.Clear(); await applicationService .Client.ForAllItems( x => x.PullRequests.GetComments(username, repository, pullRequestId), y => { var items = y.Where(x => !string.IsNullOrEmpty(x.Content.Raw) && x.Inline == null) .OrderBy(x => (x.CreatedOn)); _comments.Reset(items); }); }); GoToCommitsCommand = ReactiveCommand.CreateFromTask(t => { if (PullRequest?.Source?.Repository == null) { throw new Exception("The author has deleted the source repository for this pull request."); } var viewModel = new PullRequestCommitsViewModel(username, repository, pullRequestId); NavigateTo(viewModel); return(Task.FromResult(Unit.Default)); }); var canMerge = this.WhenAnyValue(x => x.PullRequest) .Select(x => string.Equals(x?.State, "open", StringComparison.OrdinalIgnoreCase)); canMerge.ToProperty(this, x => x.IsOpen, out _open); MergeCommand = ReactiveCommand.Create(() => { }, canMerge); RejectCommand = ReactiveCommand.CreateFromTask( t => applicationService.Client.PullRequests.Decline(username, repository, pullRequestId), canMerge); RejectCommand.Subscribe(x => PullRequest = x); GoToUserCommand = ReactiveCommand.Create <string>(user => NavigateTo(new UserViewModel(user))); ToggleApproveButton = ReactiveCommand.CreateFromTask(async _ => { if (Approved) { await applicationService.Client.PullRequests.Unapprove(username, repository, pullRequestId); } else { await applicationService.Client.PullRequests.Approve(username, repository, pullRequestId); } PullRequest = await applicationService.Client.PullRequests.Get(username, repository, pullRequestId); }); //ToggleApproveButton.ThrownExceptions // .Subscribe(x => DisplayAlert("Unable to approve commit: " + x.Message).ToBackground()); var participantObs = this.WhenAnyValue(x => x.PullRequest.Participants) .Select(x => x ?? Enumerable.Empty <PullRequestParticipant>()); var currentUsername = applicationService.Account.Username; participantObs .Select(x => x.FirstOrDefault(y => string.Equals(y.User.Username, currentUsername, StringComparison.OrdinalIgnoreCase))?.Approved ?? false) .ToProperty(this, x => x.Approved, out _approved); participantObs .Select(x => new int?(x.Count())) .ToProperty(this, x => x.ParticipantCount, out _participants); participantObs .Select(x => new int?(x.Count(y => y.Approved))) .ToProperty(this, x => x.ApprovalCount, out _approvalCount); this.WhenAnyValue(x => x.PullRequest.Description) .Select(x => string.IsNullOrEmpty(x) ? null : markdownService.ConvertMarkdown(x)) .ToProperty(this, x => x.Description, out _description); this.WhenAnyValue(x => x.PullRequest.Participants) .Select(participants => { return((participants ?? Enumerable.Empty <PullRequestParticipant>()) .Where(x => x.Approved) .Select(x => { var avatar = new Avatar(x.User?.Links?.Avatar?.Href); var vm = new UserItemViewModel(x.User?.Username, x.User?.DisplayName, avatar); vm.GoToCommand .Select(_ => new UserViewModel(x.User)) .Subscribe(NavigateTo); return vm; })); }) .Select(x => x.ToArray()) .ToProperty(this, x => x.Approvals, out _approvals, new UserItemViewModel[0]); ShowMenuCommand = ReactiveCommand.CreateFromTask(sender => { var menu = actionMenuService.Create(); menu.AddButton("Show in Bitbucket", _ => { NavigateTo(new WebBrowserViewModel(PullRequest?.Links?.Html?.Href)); }); return(menu.Show(sender)); }); }
public CommitViewModel( string username, string repository, string node, bool showRepository = false, IApplicationService applicationService = null, IActionMenuService actionMenuService = null, IAlertDialogService alertDialogService = null) { _applicationService = applicationService = applicationService ?? Locator.Current.GetService <IApplicationService>(); actionMenuService = actionMenuService ?? Locator.Current.GetService <IActionMenuService>(); alertDialogService = alertDialogService ?? Locator.Current.GetService <IAlertDialogService>(); Username = username; Repository = repository; Node = node; ShowRepository = showRepository; var shortNode = node.Substring(0, node.Length > 7 ? 7 : node.Length); Title = $"Commit {shortNode}"; var changesetFiles = this.WhenAnyValue(x => x.Changeset) .Where(x => x != null) .Select(x => x.Files ?? Enumerable.Empty <Client.V1.ChangesetFile>()); changesetFiles .Select(x => x.Count(y => y.Type == "added")) .ToProperty(this, x => x.DiffAdditions, out _diffAdditions); changesetFiles .Select(x => x.Count(y => y.Type == "removed")) .ToProperty(this, x => x.DiffDeletions, out _diffDeletions); changesetFiles .Select(x => x.Count(y => y.Type != "added" && y.Type != "removed")) .ToProperty(this, x => x.DiffModifications, out _diffModifications); Comments = _comments.CreateDerivedCollection(comment => { var name = comment.User.DisplayName ?? comment.User.Username; var avatar = new Avatar(comment.User.Links?.Avatar?.Href); return(new CommentItemViewModel(name, avatar, comment.CreatedOn.Humanize(), comment.Content.Raw)); }, x => x.Inline == null); GoToUserCommand = ReactiveCommand.Create <string>(user => NavigateTo(new UserViewModel(user))); GoToRepositoryCommand .Select(_ => new RepositoryViewModel(username, repository)) .Subscribe(NavigateTo); GoToAddedFiles = ReactiveCommand.Create( () => { }, this.WhenAnyValue(x => x.DiffAdditions).Select(x => x > 0)); GoToRemovedFiles = ReactiveCommand.Create( () => { }, this.WhenAnyValue(x => x.DiffDeletions).Select(x => x > 0)); GoToModifiedFiles = ReactiveCommand.Create( () => { }, this.WhenAnyValue(x => x.DiffModifications).Select(x => x > 0)); var canShowMenu = this.WhenAnyValue(x => x.Commit).Select(x => x != null); ShowMenuCommand = ReactiveCommand.Create <object>(sender => { var uri = new Uri($"https://bitbucket.org/{username}/{repository}/commits/{node}"); var menu = actionMenuService.Create(); menu.AddButton("Add Comment", _ => AddCommentCommand.ExecuteNow()); menu.AddButton("Copy SHA", _ => actionMenuService.SendToPasteBoard(node)); menu.AddButton("Share", x => actionMenuService.ShareUrl(x, uri)); menu.AddButton("Show In Bitbucket", _ => NavigateTo(new WebBrowserViewModel(uri.AbsoluteUri))); menu.Show(sender); }, canShowMenu); ToggleApproveButton = ReactiveCommand.CreateFromTask(async _ => { if (Approved) { await applicationService.Client.Commits.Unapprove(username, repository, node); } else { await applicationService.Client.Commits.Approve(username, repository, node); } var shouldBe = !Approved; var commit = await applicationService.Client.Commits.Get(username, repository, node); var currentUsername = applicationService.Account.Username; var me = commit.Participants.FirstOrDefault( y => string.Equals(currentUsername, y?.User?.Username, StringComparison.OrdinalIgnoreCase)); if (me != null) { me.Approved = shouldBe; } Commit = commit; }); ToggleApproveButton .ThrownExceptions .Subscribe(x => alertDialogService.Alert("Error", "Unable to approve commit: " + x.Message).ToBackground()); var commitFiles = new ReactiveList <Client.V1.ChangesetFile>(); CommitFiles = commitFiles.CreateDerivedCollection(x => { var vm = new CommitFileItemViewModel(username, repository, node, Changeset.Parents.FirstOrDefault(), x); vm.GoToCommand .Select(_ => new ChangesetDiffViewModel(username, repository, node, x)) .Subscribe(NavigateTo); return(vm); }); this.WhenAnyValue(x => x.Commit.Participants) .Select(participants => { return((participants ?? Enumerable.Empty <CommitParticipant>()) .Where(x => x.Approved) .Select(x => { var avatar = new Avatar(x.User?.Links?.Avatar?.Href); var vm = new UserItemViewModel(x.User?.Username, x.User?.DisplayName, avatar); vm.GoToCommand .Select(_ => new UserViewModel(x.User)) .Subscribe(NavigateTo); return vm; })); }) .Select(x => x.ToArray()) .ToProperty(this, x => x.Approvals, out _approvals, new UserItemViewModel[0]); this.WhenAnyValue(x => x.Changeset) .Subscribe(x => commitFiles.Reset(x?.Files ?? Enumerable.Empty <Client.V1.ChangesetFile>())); this.WhenAnyValue(x => x.Commit) .Subscribe(x => { var currentUsername = applicationService.Account.Username; Approved = x?.Participants ?.FirstOrDefault(y => string.Equals(currentUsername, y?.User?.Username, StringComparison.OrdinalIgnoreCase)) ?.Approved ?? false; }); LoadCommand = ReactiveCommand.CreateFromTask(_ => { var commit = applicationService.Client.Commits.Get(username, repository, node) .OnSuccess(x => Commit = x); var changeset = applicationService.Client.Commits.GetChangeset(username, repository, node) .OnSuccess(x => Changeset = x); applicationService.Client.AllItems(x => x.Commits.GetComments(username, repository, node)) .ToBackground(_comments.Reset); return(Task.WhenAll(commit, changeset)); }); }
public ActionResult Index(int?role, string username, UserIndexOptions options, PagerParameters pagerParameters) { var pager = new Pager(_siteService.GetSiteSettings(), pagerParameters); var userItems = new List <UserItemViewModel>(); int userTotal; var skip = pager.Page > 0 ? (pager.Page - 1) * pager.PageSize : 0; var take = pager.PageSize == 0 ? int.MaxValue : pager.PageSize; using (var connection = new SqlConnection(_shellSettings.DataConnectionString)) { connection.Open(); using (var transaction = connection.BeginTransaction()) { using (var command = connection.CreateCommand()) { command.Transaction = transaction; command.CommandType = CommandType.StoredProcedure; command.CommandText = "GetUsers"; if (role.HasValue) { var roleIdParameter = new SqlParameter("@RoleId", SqlDbType.Int) { Value = role.Value }; command.Parameters.Add(roleIdParameter); } if (!string.IsNullOrWhiteSpace(username)) { var usernameParameter = new SqlParameter("@UserName", SqlDbType.NVarChar) { Value = username }; command.Parameters.Add(usernameParameter); } var skipParameter = new SqlParameter("@Skip", SqlDbType.Int) { Value = skip }; var takeParameter = new SqlParameter("@Take", SqlDbType.Int) { Value = take }; command.Parameters.Add(skipParameter); command.Parameters.Add(takeParameter); using (var reader = command.ExecuteReader()) { while (reader.Read()) { var userItemViewModel = new UserItemViewModel { Email = (!(reader["UserName"] is DBNull)) ? (string)reader["UserName"] : "", UserId = (!(reader["UserId"] is DBNull)) ? (int)reader["UserId"] : 0, IsTeeyootUser = (!(reader["IsTeeyootUser"] is DBNull)) ? (bool)reader["IsTeeyootUser"] : false }; if (reader["CurrencyName"] != DBNull.Value) { userItemViewModel.Currency = (reader["CurrencyName"] is DBNull) ? (string)reader["CurrencyName"] : ""; } userItems.Add(userItemViewModel); } } } using (var command = connection.CreateCommand()) { command.Transaction = transaction; command.CommandType = CommandType.StoredProcedure; command.CommandText = "GetUsersCount"; if (role.HasValue) { var roleIdParameter = new SqlParameter("@RoleId", SqlDbType.Int) { Value = role.Value }; command.Parameters.Add(roleIdParameter); } userTotal = (int)command.ExecuteScalar(); } FillUsersWithRoles(userItems, transaction); transaction.Commit(); } } var pagerShape = Shape.Pager(pager).TotalItemCount(userTotal); var roles = _roleRepository.Table .Select(r => new RoleItemViewModel { Id = r.Id, Name = r.Name }) .ToList(); var viewModel = new AdminUserIndexViewModel { Roles = roles, SelectedRoleId = role, Users = userItems, Pager = pagerShape }; return(View(viewModel)); }
/// <summary> /// /// </summary> /// <param name="users"></param> /// <param name="userId"></param> /// <returns></returns> public static List <UserItemViewModel> ListUserToListUserItem(List <User> users, int userId) { List <UserItemViewModel> result = new List <UserItemViewModel>(); foreach (User u in users) { UserItemViewModel model = new UserItemViewModel(); model.User = u; model.FollowStatus = u.Followers.Count(t => t.Id == userId) > 0; UserFriendship friendship1 = u.PassiveRelationship.Where(r => r.UserId == userId).FirstOrDefault(); UserFriendship friendship2 = u.ActiveRelationships.Where(r => r.TargetUserId == userId).FirstOrDefault(); if (friendship1 != default(UserFriendship)) { switch (friendship1.Status) { case RelationshipEnum.Requesting: model.RequestStatus = FriendStatusEnum.ActiveRequesting; break; case RelationshipEnum.Friend: model.RequestStatus = FriendStatusEnum.Friend; break; case RelationshipEnum.Blocked: model.RequestStatus = FriendStatusEnum.Blocked; break; default: model.RequestStatus = FriendStatusEnum.Stranger; break; } } else if (friendship2 != default(UserFriendship)) { switch (friendship2.Status) { case RelationshipEnum.Requesting: model.RequestStatus = FriendStatusEnum.PasssiveRequesting; break; case RelationshipEnum.Friend: model.RequestStatus = FriendStatusEnum.Friend; break; case RelationshipEnum.Blocked: model.RequestStatus = FriendStatusEnum.Blocked; break; default: model.RequestStatus = FriendStatusEnum.Stranger; break; } } else { model.RequestStatus = FriendStatusEnum.Stranger; } result.Add(model); } return(result); }