예제 #1
0
 public async Task <IActionResult> CreateEntity([FromBody] ItemEntity item)
 {
     Console.WriteLine("Adding item with title: " + item.Title);
     item.DateCreated = DateTime.Now;
     _dbLogic.Add(item);
     _dbLogic.GenerateTags(item);
     unitOfWork.Commit();
     return(Ok(item));
 }
예제 #2
0
        public void UpdateLot(LotEntity lot, bool contentChanged)
        {
            using (var unitOfWork = new AuctionUnitOfWork())
            {
                var dbLot = unitOfWork.LotRepository.Get(lot.Id);

                if (contentChanged)
                {
                    var dbContents = unitOfWork.LotContentRepository.Get(c => c.LotId == lot.Id);

                    foreach (var content in dbContents)
                    {
                        unitOfWork.LotContentRepository.Delete(content);
                    }

                    var cnt = lot.LotContents.Select(c => new LotContent {
                        Content = c.Content, LotId = c.LotId
                    }).ToList();
                    dbLot.LotContents = cnt;
                }

                dbLot.Title       = lot.Title;
                dbLot.Description = lot.Description;
                dbLot.CategoryId  = lot.CategoryId;

                unitOfWork.Commit();
            }
        }
예제 #3
0
        private void AddLot_OnClick(object sender, RoutedEventArgs e)// Добавить лот в базу и карточки и отсортировать карточки
        {
            using (var uow = new AuctionUnitOfWork(true))
            {
                var user            = uow.UserRepository.Get(_userId);
                var selectedProduct = (Product)ProductComboBox.SelectedItem;
                var product         = uow.ProductRepository.Get(selectedProduct.Id);

                var lot = new Lot
                {
                    Title        = TitleTextBox.Text,
                    StartBid     = decimal.Parse(StartBidTextBox.Text),
                    CurrentBid   = decimal.Parse(StartBidTextBox.Text),
                    MinBidStep   = decimal.Parse(MinStepTextBox.Text),
                    DateCreated  = DateTime.Now,
                    DateToExpire = new DateTime(2019, 11, 11),
                    Users        = new List <User> {
                        user
                    },
                    Product   = product,
                    ProductId = product.Id
                };

                uow.LotRepository.Add(lot);

                uow.Commit();
            }

            LotListControl.RefreshAndSort(l => l.Id);
            ClearForm();
        }
예제 #4
0
 public void UpdateContact(Contact contact)
 {
     using (var unitOfWork = new AuctionUnitOfWork())
     {
         unitOfWork.ContactRepository.Update(contact);
         unitOfWork.Commit();
     }
 }
예제 #5
0
 public void AddLot(LotEntity lot)
 {
     using (var unitOfWork = new AuctionUnitOfWork())
     {
         unitOfWork.LotRepository.Add(lot);
         unitOfWork.Commit();
     }
 }
예제 #6
0
        private static void Init()
        {
            using (var uow = new AuctionUnitOfWork())
            {
                var cat = new Category {
                    Description = "Default Description", Name = "Awesome"
                };
                var catR = uow.CategoryRepository;
                catR.Add(cat);

                var cnt = new Contact {
                    Address = "Jaos", Email = "rxt@ash", Phone = "1230-112"
                };
                var cnt2 = new Contact {
                    Address = "Jaosinen", Email = "rxqwrt@ash", Phone = "14130-112"
                };
                var cnt3 = new Contact {
                    Address = "Bel", Email = "124t@as4", Phone = "112413()1312"
                };
                var contactR = uow.ContactRepository;
                contactR.Add(cnt);
                contactR.Add(cnt2);
                contactR.Add(cnt3);

                var usr = new User {
                    Contact = cnt, ContactId = cnt.Id, Login = "******", Password = "******"
                };
                var usr2 = new User {
                    Contact = cnt2, ContactId = cnt2.Id, Login = "******", Password = "******"
                };
                var userR = uow.UserRepository;
                userR.Add(usr);
                userR.Add(usr2);

                var lot = new Lot
                {
                    Users = new HashSet <User> {
                        usr, usr2
                    },
                    Title        = "GOOD TV",
                    StartBid     = (decimal)123.21,
                    CurrentBid   = (decimal)123.21,
                    DateCreated  = DateTime.Now,
                    DateToExpire = new DateTime(2019, 11, 11),
                    Category     = cat,
                    OwnerId      = usr.Id,
                    Owner        = usr,
                    Description  = "Lorem ipsum dolor"
                };

                var lotR = uow.LotRepository;
                lotR.Add(lot);

                uow.Commit();
            }
        }
예제 #7
0
 public void ChangePassword(int userId, string newPassword)
 {
     using (var unitOfWork = new AuctionUnitOfWork())
     {
         var user = unitOfWork.UserRepository.Get(userId);
         user.Password = newPassword;
         unitOfWork.UserRepository.Update(user);
         unitOfWork.Commit();
     }
 }
예제 #8
0
 public async Task <IActionResult> CreateBid([FromBody] BidEntity bid)
 {
     while (User.Identity.Name == null)
     {
     }
     bid.UserIdBuyer = User.Identity.Name;
     bid.Created     = DateTime.Now;
     _bidLogic.Add(bid);
     unitOfWork.Commit();
     return(Ok(bid));
 }
예제 #9
0
        public void AddContact(Contact contact, int userId)
        {
            using (var unitOfWork = new AuctionUnitOfWork())
            {
                unitOfWork.ContactRepository.Add(contact);

                var user = unitOfWork.UserRepository.Get(userId);
                user.ContactId = contact.Id;
                user.Contact   = contact;

                unitOfWork.Commit();
            }
        }
예제 #10
0
        public void DisableLot(int lotId)
        {
            using (var unitOfWork = new AuctionUnitOfWork())
            {
                var lot = unitOfWork.LotRepository.Get(lotId);

                lot.IsActive     = false;
                lot.DateFinished = DateTime.Now;

                Notify(unitOfWork, lot);

                unitOfWork.Commit();
            }
        }
예제 #11
0
 public bool ChangeLogin(int userId, string newLogin)
 {
     using (var unitOfWork = new AuctionUnitOfWork())
     {
         if (unitOfWork.UserRepository.Get(u => u.Login == newLogin).Any())
         {
             MessageBox.Show("Пользователь с таким логином уже существует", "Логин", MessageBoxButton.OK, MessageBoxImage.Error);
             return(false);
         }
         var user = unitOfWork.UserRepository.Get(userId);
         user.Login = newLogin;
         unitOfWork.UserRepository.Update(user);
         unitOfWork.Commit();
     }
     return(true);
 }
예제 #12
0
        public ICollection <NotificationEntity> MarkAsReaded(IEnumerable <int> notificationIDs)
        {
            using (var unitOfWork = new AuctionUnitOfWork())
            {
                var notifications = unitOfWork.NotificationRepository.Get(n => notificationIDs.Contains(n.Id));

                foreach (var notification in notifications)
                {
                    notification.IsReaded = true;
                }

                unitOfWork.Commit();

                return(notifications);
            }
        }
예제 #13
0
        public void AddBid(Bid bid)
        {
            using (var unitOfWork = new AuctionUnitOfWork())
            {
                var lot  = unitOfWork.LotRepository.Get(bid.LotId);
                var user = unitOfWork.UserRepository.Get(bid.UserId);

                lot.Bids.Add(bid);

                if (!lot.Users.Any(u => u.Id == bid.UserId))
                {
                    lot.Users.Add(user);
                }

                lot.CurrentBid = bid.Amount;

                unitOfWork.Commit();
            }
        }
예제 #14
0
        private void EditLot_OnClick(object sender, RoutedEventArgs e)
        {
            using (var uow = new AuctionUnitOfWork(true)) // Обновить лот
            {
                var lot             = uow.LotRepository.Get(_currentLot.Id);
                var selectedProduct = (Product)ProductComboBox.SelectedItem;
                var product         = uow.ProductRepository.Get(selectedProduct.Id);

                lot.Title      = TitleTextBox.Text;
                lot.StartBid   = decimal.Parse(StartBidTextBox.Text);
                lot.MinBidStep = decimal.Parse(MinStepTextBox.Text);
                lot.ProductId  = product.Id;
                lot.Product    = product;

                uow.LotRepository.Update(lot);
                uow.Commit();
            }
            LotListControl.RefreshAndSort(l => l.Id);
            ClearForm();
        }
예제 #15
0
        /// <summary>
        /// завершение лотов, у которых время торгов истекло, при старте приложения
        /// </summary>
        public void RunLotExpirationProcessor()
        {
            Task.Factory.StartNew(() =>
            {
                using (var unitOfWork = new AuctionUnitOfWork())
                {
                    var lotsToExpire = unitOfWork.LotRepository.Select()
                                       .Where(l => l.IsActive && l.DateToExpire < DateTime.Now).ToList();

                    foreach (var lot in lotsToExpire)
                    {
                        lot.IsActive     = false;
                        lot.DateFinished = DateTime.Now;

                        Notify(unitOfWork, lot);
                    }

                    unitOfWork.Commit();
                }
            }).ConfigureAwait(false);
        }
예제 #16
0
        public bool TryRegistration(User user, string passwordConfirm, out string message)
        {
            message = "OK";

            if (user.Password != passwordConfirm)
            {
                message = "Корректно подтвердите пароль!";
                return(false);
            }

            using (var unitOfWork = new AuctionUnitOfWork())
            {
                if (unitOfWork.UserRepository.Get(u => u.Login == user.Login).Any())
                {
                    message = "Пользователь с таким логином уже существует";
                    return(false);
                }
                unitOfWork.UserRepository.Add(user);
                unitOfWork.Commit();
            }
            return(true);
        }