private async void ButtonBase_OnClick(object sender, RoutedEventArgs e)//add tovar { using (var uow = new AuctionUnitOfWork()) { var category = uow.CategoryRepository.Get().FirstOrDefault(); var content = uow.ProductContentRepository.Get().FirstOrDefault(); var user = uow.UserRepository.Get(_userId); var product = new Product { Name = ProductTextBox.Text, Category = category, CategoryId = category.Id, Owner = user, OwnerId = user.Id, ProductContents = new List <ProductContent> { content } }; var nameArg = new System.Data.SqlClient.SqlParameter("name", product.Name); var categoryArg = new System.Data.SqlClient.SqlParameter("category", category.Id); var userArg = new System.Data.SqlClient.SqlParameter("user", user.Id); await uow.ProductRepository.Query( "INSERT INTO dbo.Products (Name, CategoryId, OwnerId) VALUES(@name, @category, @user)", nameArg, categoryArg, userArg); //_products.Add(product); ReloadProducts(); ProductTextBox.Clear(); } }
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(); } }
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(); }
public List <Category> GetCategories() { using (var unitOfWork = new AuctionUnitOfWork()) { return(unitOfWork.CategoryRepository.Get().ToList()); } }
public ICollection <NotificationEntity> GetUserNotifications(int userId) { using (var unitOfWork = new AuctionUnitOfWork()) { var notifications = unitOfWork.NotificationRepository.Get(n => n.RecieverId == userId && n.IsReaded == false); return(notifications); } }
public void RefreshAndSort <T>(Func <Lot, T> keySelector) { using (var uow = new AuctionUnitOfWork()) { var lots = GetLots(uow, keySelector); LoadCards(lots); } }
public void AddLot(LotEntity lot) { using (var unitOfWork = new AuctionUnitOfWork()) { unitOfWork.LotRepository.Add(lot); unitOfWork.Commit(); } }
public void UpdateContact(Contact contact) { using (var unitOfWork = new AuctionUnitOfWork()) { unitOfWork.ContactRepository.Update(contact); unitOfWork.Commit(); } }
public void Find(string text) { using (var uow = new AuctionUnitOfWork()) { var lots = uow.LotRepository.Get(l => l.Title.Contains(text)).ToList(); LoadCards(lots); } }
public ItemEntityController() { var db = new DBContext.VareDataModelContext(); IItemRepository repo = new ItemRepository(db); var unit = new AuctionUnitOfWork(db); var dbLogic = new DatabaseLogic(unit, repo); _dbLogic = dbLogic; }
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(); } }
public User GetUser(Func <User, bool> predicate) { using (var unitOfWork = new AuctionUnitOfWork()) { var user = unitOfWork.UserRepository.Select() .Include(u => u.Contact) .FirstOrDefault(predicate); return(user); } }
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(); } }
public MainWindow() { InitializeComponent(); using (var uow = new AuctionUnitOfWork()) { var user = uow.UserRepository.Get().FirstOrDefault(); _userId = user.Id; } }
private void ReloadProducts()//загрузить в комбобокс из базы { ProductComboBox.ItemsSource = null; using (var uow = new AuctionUnitOfWork()) { _products = uow.ProductRepository.Get(p => p.OwnerId == _userId).ToList(); } ProductComboBox.ItemsSource = _products; ProductComboBox.DisplayMemberPath = "Name"; }
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(); } }
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(); } }
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); }
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); } }
public LotEntity GetLot(int id) { using (var unitOfWork = new AuctionUnitOfWork()) { var lot = unitOfWork.LotRepository.Select() .Include(l => l.Category) .Include(l => l.Bids) .Include(l => l.LotContents) .Include(l => l.Users) .Include(l => l.Owner) .Include(l => l.Owner.Contact) .FirstOrDefault(l => l.Id == id); return(lot); } }
private void LotListControl_OnOnCardUdateRequest(object sender, EventArgs e) { var id = (int)sender; using (var uow = new AuctionUnitOfWork()) // Заполнить форму из лота { var lot = uow.LotRepository.Get(id); TitleTextBox.Text = lot.Title; StartBidTextBox.Text = lot.StartBid.ToString(); MinStepTextBox.Text = lot.MinBidStep.ToString(); ProductComboBox.SelectedItem = _products.FirstOrDefault(p => p.Id == lot.ProductId); _currentLot = lot; } EditLot.IsEnabled = true; }
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(); } }
public void Refresh(Expression <Func <LotEntity, bool> > predicate = null, string filterMessage = null) { if (predicate == null) { predicate = l => l.IsActive; } FilterTextBlock.Text = filterMessage; lotStackPanel.Children.Clear(); using (var uow = new AuctionUnitOfWork()) { var lots = uow.LotRepository.Select() .Where(predicate) .OrderByDescending(l => l.DateCreated).ToList(); lots.ForEach(lot => { var card = new LotCard { Title = lot.Title, LotId = lot.Id, Height = 136, Description = String.Format("Стартовая цена: {0:0.00} BYN", lot.StartBid) }; var content = lot.LotContents.FirstOrDefault(); if (content == null) { card.ImageSource = new BitmapImage(new Uri("../Images/empty_auction.jpg", UriKind.Relative)); } else { card.ImageSource = ToImage(content.Content); } card.MouseDown += CardOnMouseDown; lotStackPanel.Children.Add(card); }); } }
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(); }
/// <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); }
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); }
/// <summary> /// оповещает каждого пользователя, участвующего в торгах по лоту, о его завершении /// </summary> /// <param name="unitOfWork"></param> /// <param name="lot"></param> private void Notify(AuctionUnitOfWork unitOfWork, LotEntity lot) { var toOwner = BuildOwnerNotification(lot); _notificationService.Send(toOwner, unitOfWork); if (lot.Bids == null || !lot.Bids.Any()) { return; } var maxBid = lot.Bids.OrderByDescending(b => b.Amount).FirstOrDefault(); var winner = maxBid.User; var toWinner = BuildWinnerNotification(maxBid.UserId, lot); _notificationService.Send(toWinner, unitOfWork); foreach (var user in lot.Users.Where(u => u.Id != winner.Id)) { var toUser = BuildUserNotification(user.Id, lot); _notificationService.Send(toUser, unitOfWork); } }
public void Send(NotificationEntity notification, AuctionUnitOfWork unitOfWork) { unitOfWork.NotificationRepository.Add(notification); }
public BidEntitiesController() { unitOfWork = new AuctionUnitOfWork(); _bidLogic = unitOfWork.BidRepository; }
public ItemEntityController() { unitOfWork = new AuctionUnitOfWork(); _dbLogic = unitOfWork.ItemRepository; }