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)); }
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 void UpdateContact(Contact contact) { using (var unitOfWork = new AuctionUnitOfWork()) { unitOfWork.ContactRepository.Update(contact); unitOfWork.Commit(); } }
public void AddLot(LotEntity lot) { using (var unitOfWork = new AuctionUnitOfWork()) { unitOfWork.LotRepository.Add(lot); unitOfWork.Commit(); } }
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 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 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)); }
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 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(); } }
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); }