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);
        }
예제 #2
0
        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);
        }
예제 #3
0
        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();
        }
예제 #4
0
        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));
        }
예제 #5
0
        private void OnRemoveUserParty(UserParty party)
        {
            var userPartyIndex = UserParties.ToList().FindIndex(x => x.Id == party.Id);

            if (userPartyIndex >= 0)
            {
                UserParties.RemoveAt(userPartyIndex);
            }
        }
예제 #6
0
        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);
                }
            }
        }
예제 #8
0
        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();
 }
예제 #10
0
 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();
 }
예제 #11
0
 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();
            }
        }
예제 #13
0
        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();
            }
        }
예제 #14
0
        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);
        }
예제 #15
0
        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());
            }
        }
예제 #16
0
 public void RemoveParty(UserParty party)
 {
     UserParties.Remove(party);
     OnRemoveUserParty?.Invoke(party);
     FileManager.I.SaveJson(UserParties.ToArray());
 }
예제 #17
0
        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());
            }
        }
예제 #18
0
 private void ExportParty(UserParty party)
 {
     Clipboard.SetText(party.GetJson());
     MessageBox.Show("クリップボードにパーティー情報をコピーしました。\n画面上のインポートボタンから追加することが出来ます。");
 }
예제 #19
0
        private void DuplicateParty(UserParty party)
        {
            var duplicate = new UserParty(party.UserUnits, party.Comment, party.EstimateDamage);

            Database.I.AddParty(duplicate);
        }
예제 #20
0
 public EditParty(UserParty party = null)
 {
     InitializeComponent();
     DataContext = new EditPartyViewModel(Database.I.Units, party);
 }
예제 #21
0
 public void AddParty(UserParty party)
 {
     UserParties.Add(party);
     OnAddUserParty?.Invoke(party);
     FileManager.I.SaveJson(UserParties.ToArray());
 }