public AttackRouteListElementViewModel(UserParty party, Action <UserParty> onUnSelect) { Id = party.Id; Party = party; PartyUnits = new ReactiveCollection <UserUnitViewModel>(); Tags = new ReactiveCollection <TagViewModel>(); IsExpandComment.Subscribe(x => { if (x) { Comment.Value = party.Comment; } else { Comment.Value = party.Comment?.GetFirstLine() ?? string.Empty; } }); OnUnSelect.Subscribe(() => { onUnSelect?.Invoke(party); }); UpdateParty(party); }
private Boolean MapRatingToModel(UserPartyRating partyRating, ref UserParty userParty) { Boolean hasChanged = false; //Value mapping if (userParty.GeneralRating != partyRating.GeneralRating) { userParty.GeneralRating = partyRating.GeneralRating; hasChanged = true; } if (userParty.PriceRating != partyRating.PriceRating) { userParty.PriceRating = partyRating.PriceRating; hasChanged = true; } if (userParty.LocationRating != partyRating.LocationRating) { userParty.LocationRating = partyRating.LocationRating; hasChanged = true; } if (userParty.MoodRating != partyRating.MoodRating) { userParty.MoodRating = partyRating.MoodRating; hasChanged = true; } return(hasChanged); }
private void OnUnSelectAttackRoute(UserParty party) { var target = AttackParties.SingleOrDefault(x => x.Id == party.Id); var userParty = UserParties.SingleOrDefault(x => x.Party.Value.Id == party.Id); //凸ルート編成後にユーザーパーティを消す場合があるので必ずチェックする if (userParty != null) { userParty.IsSelectedRoute.Value = false; } if (userParty == null) { var result = MessageBox.Show("マイパーティ一覧から既にこの編成が消えています。\nこの編成をマイパーティに追加して凸ルートから削除しますか?", "警告", MessageBoxButton.YesNoCancel); if (result == MessageBoxResult.Yes) { var newParty = new UserParty(party.UserUnits, party.Comment, party.EstimateDamage); Database.I.AddParty(newParty); } else if (result == MessageBoxResult.Cancel) { return; } } AttackParties.Remove(target); CheckDoubling(); }
private void OnAddUserParty(UserParty party) { UserParties.Add(new PartyListElementViewModel(party, OnSelectAttackRoute)); var parties = UserParties.ToArray(); UserParties.Clear(); UserParties.AddRange(parties.OrderByDescending(x => x.Party.Value.CreateTime)); }
private void OnRemoveUserParty(UserParty party) { var userPartyIndex = UserParties.ToList().FindIndex(x => x.Id == party.Id); if (userPartyIndex >= 0) { UserParties.RemoveAt(userPartyIndex); } }
private void DeleteParty(UserParty party) { var result = MessageBox.Show("パーティーを削除します。よろしいですか?", "確認", MessageBoxButton.YesNo); if (result == MessageBoxResult.Yes) { Database.I.RemoveParty(party); } }
public EditPartyViewModel(Unit[] units, UserParty party = null) { m_UnitsCollection = new ObservableCollection <Unit>(units); UnitList = m_UnitsCollection.ToReadOnlyReactiveCollection(x => new UnitViewModel(x)); m_PartyUnitsCollection = new ObservableCollection <UserUnit>(); PartyUnits = m_PartyUnitsCollection.ToReadOnlyReactiveCollection(x => new UserUnitViewModel(x, () => UnselectUserUnit(x))); OnCancel.Subscribe(x => CloseWindow((Window)x)); OnSubmit.Subscribe(x => SaveParty((Window)x)); OnSearchTextChanged.Subscribe(() => { SearchUnit(SearchText.Value); }); ShowUnitType.Subscribe(OnChangeShowUnitType); OnChangeSelected.Subscribe(OnChangeSelectedUnit); OnAddTag.Subscribe(() => { var window = new AddTagWindow(tag => { Tags.Add(new TagViewModel(tag, OnRemoveTag)); }); window.ShowDialog(); }); if (party != null) { m_Party = party; m_PartUnits = party.UserUnits.ToList(); foreach (var unitViewModel in UnitList) { if (m_PartUnits.Any(x => x.UnitId == unitViewModel.Unit.Id)) { unitViewModel.SetSelect(true); } } m_PartyUnitsCollection.Clear(); foreach (var unit in m_PartUnits) { m_PartyUnitsCollection.Add(unit); } IsFullParty.Value = true; IsVisibleSelected.Value = Visibility.Visible; PartyComment.Value = party.Comment; EstimateDamage.Value = party.EstimateDamage; Tags.Clear(); if (party.Tags?.Length > 0) { var vms = party.Tags .Select(x => Database.I.Tags.SingleOrDefault(db => db.Id == x)) .Select(x => new TagViewModel(x, OnRemoveTag)); Tags.AddRange(vms); } } }
public static string GetJson(this UserParty self) { var options = new JsonSerializerOptions { Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping, PropertyNamingPolicy = JsonNamingPolicy.CamelCase, PropertyNameCaseInsensitive = true, }; return(JsonSerializer.Serialize(self, options)); }
private void SaveParty(Window window) { if (m_Party == null) { m_Party = new UserParty(m_PartUnits, PartyComment.Value, EstimateDamage.Value, Tags.Select(x => x.Tag.Id).ToArray()); } else { m_Party.UpdateData(m_PartUnits, PartyComment.Value, EstimateDamage.Value, Tags.Select(x => x.Tag.Id).ToArray()); } Database.I.SaveParty(m_Party); window.Close(); }
private void OnSelectAttackRoute(UserParty party, bool isSelect) { if (isSelect) { AttackParties.Add(new AttackRouteListElementViewModel(party, OnUnSelectAttackRoute)); } else { var target = AttackParties.SingleOrDefault(x => x.Id == party.Id); AttackParties.Remove(target); } CheckDoubling(); }
public void SaveParty(UserParty party) { if (UserParties.Contains(party)) { var index = UserParties.FindIndex(x => x.Id == party.Id); UserParties[index] = party; OnChangeUserParty?.Invoke(party); FileManager.I.SaveJson(UserParties.ToArray()); } else { AddParty(party); } }
public void UpdateParty(UserParty party) { Party = party; PartyUnits.Clear(); PartyUnits.AddRange(party.UserUnits.Select(x => new UserUnitViewModel(x))); Comment.Value = party.Comment?.GetFirstLine() ?? string.Empty; EstimateDamage.Value = party.EstimateDamage; IsShowExpandCommentButton.Value = party.Comment?.GetLineCount() <= 1 ? Visibility.Collapsed : Visibility.Visible; Tags.Clear(); var tags = party.Tags?.Select(x => Database.I.Tags.SingleOrDefault(db => db.Id == x)); if (tags?.Count() > 0) { Tags.AddRange(tags.Select(x => new TagViewModel(x))); TagCount.Value += tags.Count(); } }
private void OnChangeUserParty(UserParty party) { var userPartyIndex = UserParties.ToList().FindIndex(x => x.Id == party.Id); if (userPartyIndex >= 0) { UserParties[userPartyIndex].UpdateParty(party);; var parties = UserParties.ToArray(); UserParties.Clear(); UserParties.AddRange(parties.OrderByDescending(x => x.Party.Value.CreateTime)); } var attackRouteIndex = AttackParties.ToList().FindIndex(x => x.Id == party.Id); if (attackRouteIndex >= 0) { AttackParties[attackRouteIndex].UpdateParty(party); CheckDoubling(); } }
public PartyListElementViewModel(UserParty party, Action <UserParty, bool> onSelect) { Id = party.Id; Party.Value = party; PartyUnits = new ReactiveCollection <UserUnitViewModel>(); Tags = new ReactiveCollection <TagViewModel>(); IsExpandComment.Subscribe(x => { if (x) { Comment.Value = party.Comment; } else { Comment.Value = party.Comment?.GetFirstLine() ?? string.Empty; } }); EditParty.Subscribe(x => { var editWindow = new EditParty((UserParty)x); editWindow.ShowDialog(); }); OnDelete.Subscribe(() => DeleteParty(party)); OnExport.Subscribe(() => ExportParty(party)); OnDuplicate.Subscribe(() => DuplicateParty(party)); OnSelect.Subscribe(() => { IsSelectedRoute.Value = !IsSelectedRoute.Value; onSelect?.Invoke(party, IsSelectedRoute.Value); }); UpdateParty(party); }
public ActionResult SetCommitmentState(Guid?id, [FromBody] UserPartyCommitment commitmentState) { try { //Check if PartyId is valid if (!Validator.IsGuidValid(id.ToString())) { return(BadRequest("Party ID is not valid.")); } else { //Select party var party = _dbContext.PartyItems .FirstOrDefault(p => p.PartyId == id); if (party == null) { return(NotFound("Party not found.")); } else if (party.PartyDate.Date < DateTime.Now.Date) { return(BadRequest("Can't commit to a party with party date in the past.")); } else { UserParty userParty = _dbContext.UserPartyItems .FirstOrDefault(up => up.PartyId == party.PartyId && up.UserId == User.UserId); if (userParty == null) { userParty = new UserParty { PartyId = party.PartyId, UserId = User.UserId, EventCommitment = commitmentState.EventCommitment }; _dbContext.UserPartyItems.Add(userParty); _dbContext.SaveChanges(); return(Ok()); } else { if (userParty.EventCommitment == commitmentState.EventCommitment) { //Nothing changed return(Ok()); } else { userParty.EventCommitment = commitmentState.EventCommitment; _dbContext.UserPartyItems.Update(userParty); _dbContext.SaveChanges(); return(Ok()); } } } } } catch (Exception) { return(BadRequest()); } }
public void RemoveParty(UserParty party) { UserParties.Remove(party); OnRemoveUserParty?.Invoke(party); FileManager.I.SaveJson(UserParties.ToArray()); }
public ActionResult SetRating(Guid?id, [FromBody] UserPartyRating partyRating) { try { //Check if PartyId is valid if (!Validator.IsGuidValid(id.ToString())) { return(BadRequest("Party ID is not valid.")); } else { //Select party var party = _dbContext.PartyItems .FirstOrDefault(p => p.PartyId == id); if (party == null) { return(NotFound("Party not found.")); } else if (party.PartyDate.Date != DateTime.Today.Date && party.PartyDate.AddDays(1).Date != DateTime.Today.Date) { return(BadRequest("It's just possible to vote on the day of the party or the day after.")); } else if (!TryValidateModel(partyRating)) { return(BadRequest(new UserPartyRating())); } else { UserParty userParty = _dbContext.UserPartyItems .FirstOrDefault(up => up.PartyId == party.PartyId && up.UserId == User.UserId); if (userParty == null) { return(BadRequest("Can't rate a party without commitment.")); } else if (userParty.EventCommitment == EventCommitmentState.Rejected) { return(BadRequest("Can't rate the party. Users current commitment is rejected.")); } else { String messageRatingRange = CheckRatingValuesRange(partyRating); if (!String.IsNullOrEmpty(messageRatingRange)) { //Something is wrong with the range of the rating values return(BadRequest(messageRatingRange)); } else { Boolean hasChanged = MapRatingToModel(partyRating, ref userParty); if (!hasChanged) { //Nothing changed return(Ok()); } else { _dbContext.UserPartyItems.Update(userParty); _dbContext.SaveChanges(); return(Ok()); } } } } } } catch (Exception) { return(BadRequest()); } }
private void ExportParty(UserParty party) { Clipboard.SetText(party.GetJson()); MessageBox.Show("クリップボードにパーティー情報をコピーしました。\n画面上のインポートボタンから追加することが出来ます。"); }
private void DuplicateParty(UserParty party) { var duplicate = new UserParty(party.UserUnits, party.Comment, party.EstimateDamage); Database.I.AddParty(duplicate); }
public EditParty(UserParty party = null) { InitializeComponent(); DataContext = new EditPartyViewModel(Database.I.Units, party); }
public void AddParty(UserParty party) { UserParties.Add(party); OnAddUserParty?.Invoke(party); FileManager.I.SaveJson(UserParties.ToArray()); }