Exemple #1
0
        private void AccessRequested(ulong uid, Direction direction)
        {
            User = GetUser(uid);

            if (User != null)
            {
                if (direction == Domain.Direction.IN)
                {
                    var ws = new WorkShift()
                    {
                        ArrivalTime = DateTime.Now,
                        CardUid     = (long)uid
                    };
                    _ctx.WorkShifts.Add(ws);
                    _ctx.SaveChanges();
                }
                else
                {
                    long id   = (long)uid;
                    var  last = _ctx.WorkShifts.Where(x => x.CardUid == id).OrderByDescending(x => x.Id)
                                .FirstOrDefault();
                    if (last != null)
                    {
                        last.LeavingTime = DateTime.Now;
                        _ctx.SaveChanges();
                    }
                }

                Access    = AccessStatus.GRANTED;
                Direction = direction;
            }
            else
            {
                Access    = AccessStatus.DENIED;
                Direction = null;
            }

            EventLog.Add(new LogItemViewModel()
            {
                Date      = DateTime.Now,
                CardId    = uid,
                Fio       = User?.FIO,
                Direction = direction,
                Status    = Access.Value
            });

            ArduinoGateway.Instance.SendResponse(Access.Value);
        }
        private void BtnOk_OnClick(object sender, RoutedEventArgs e)
        {
            using (var ctx = new SkudContext())
            {
                if (ctx.Cards.Any(x => x.Uid == (long)CardUid))
                {
                    MessageBox.Show("Карта уже зарегестрирована в системе", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Warning);
                    return;
                }

                Card = new Card()
                {
                    UserId         = _userId,
                    IssueDate      = DateTime.Now,
                    ExpirationDate = ExpirationDate,
                    Uid            = (long)CardUid
                };


                ctx.Cards.Add(Card);
                ctx.SaveChanges();
            }

            DialogResult = true;
            Close();
        }
Exemple #3
0
        // Удаление выбранных карт
        private void mnuRemoveSelected_Click(object sender, RoutedEventArgs e)
        {
            while (cardsGrid.SelectedItems.Count > 0)
            {
                var card = (Card)cardsGrid.SelectedItems[0];
                _ctx.Cards.Remove(card);
            }

            _ctx.SaveChanges();
        }
Exemple #4
0
 private void BtnSave_OnClick(object sender, RoutedEventArgs e)
 {
     try
     {
         _ctx.SaveChanges();
         Update();
     }
     catch (Exception ex)
     {
         MessageBox.Show("Данные заполнены неверно", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Warning);
     }
 }
 private void BtnSave_OnClick(object sender, RoutedEventArgs e)
 {
     _ctx.SaveChanges();
     Update();
 }