private void DoChangeVote()
 {
     IsNotFinish     = true;
     _isVoteChange   = true;
     _oldPosition    = CurrentPosition;
     CurrentPosition = CouncilPositions.FirstOrDefault(c => c.Id == SelectedVote.Position.Id);
 }
Example #2
0
        private void AddPositionClosing(object sender, DialogClosingEventArgs args)
        {
            bool result = false;

            if (Equals(args.Parameter, false))
            {
                return;
            }
            if (args.Parameter is TextBox)
            {
                args.Session.UpdateContent(new PleaseWaitView());
                TextBox txtName     = (TextBox)args.Parameter;
                string  name        = txtName.Text.Trim();
                var     newPosition = new CouncilPosition()
                {
                    Position = name
                };
                if (string.IsNullOrEmpty(name) || string.IsNullOrWhiteSpace(name))
                {
                    args.Cancel();
                    args.Session.UpdateContent(new OkMessageDialog()
                    {
                        DataContext = "Null entry"
                    });
                    return;
                }
                var duplicate = _context.CouncilPositions.FirstOrDefault(c => c.Position == name);
                if (duplicate != null)
                {
                    args.Cancel();
                    args.Session.UpdateContent(new OkMessageDialog()
                    {
                        DataContext = "Duplicate Name"
                    });
                    return;
                }
                Task.Run(() =>
                {
                    Thread.Sleep(1000);

                    try
                    {
                        _context.Entry(newPosition).State = EntityState.Added;

                        _context.SaveChanges();
                        result = true;
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);

                        result = false;
                    }
                }).ContinueWith((t, _) =>
                {
                    if (!result)
                    {
                        args.Cancel();
                        args.Session.UpdateContent(new OkMessageDialog()
                        {
                            DataContext = "Failed to add"
                        });
                    }
                    else
                    {
                        PositionList.Add(newPosition);
                    }
                }, null, TaskScheduler.FromCurrentSynchronizationContext());
            }
        }