public void UpdateUser(UserDto user, AuctionDto auction) { var usr = new User(); usr.UserId = user.UserId; var usr1 = new User(); usr1.UserId = auction.Seller_Id; var credit = _userRepository.GetUserById(new User { UserId = usr1.UserId }).Credit; var usr2 = new User(); usr2.UserId = auction.Seller_Id; if (user.Credit - auction.Price >= 0) { usr.Credit = user.Credit - auction.Price; usr2.Credit = credit + auction.Price; } else { return; } _userRepository.UpdateUser(usr, usr2); }
public async Task <AuctionDto> Get(EntityDto input) { Domain.Auction.Auction item = await _auctionManager.GetDetail(input.Id); var result = new AuctionDto { Id = item.Id, EndDate = item.EndDate, InitPrice = item.InitPrice, MinAcceptPrice = item.MinAcceptPrice, ProductId = item.ProductId, StartDate = item.StartDate, CurrentPrice = item.CurrentPrice, NumberOfBids = item.NumberOfBid, UserName = item.Winner?.UserName, SellerId = item.SellerId }; if (item.LastBidTime.Year < 1900) { result.LastBidTime = null; } else { result.LastBidTime = item.LastBidTime; } return(result); }
public static AuctionViewModel FromAuction(AuctionDto auction, decimal calculatedPrice, string viewerUrl, string infoUrl) { var vm = new AuctionViewModel { BaseSymbol = auction.BaseSymbol, QuoteSymbol = auction.QuoteSymbol, CreatorAddress = auction.CreatorAddress, Price = calculatedPrice, EndDate = new Timestamp(auction.StartDate), StartDate = new Timestamp(auction.StartDate), TokenId = auction.TokenId, InfoUrl = infoUrl }; if (string.IsNullOrEmpty(viewerUrl)) { vm.ViewerUrl = "/img/stock_nft.png"; } else { vm.ViewerUrl = viewerUrl + vm.TokenId; } return(vm); }
public IHttpActionResult Create(AuctionDto auctionDto) { Auction auction = CreateAuction(auctionDto); service.Save(auction); return(Ok()); }
public ActionResult Create(CreateAuctionViewModel newAuction) { if (ModelState.IsValid) { AuctionDto auction = new AuctionDto(); auction.Name = newAuction.Name; auction.Price = newAuction.Price; auction.Seller_Id = Convert.ToInt32(Session["UserId"]); //auction.Seller.UserName = Session["UserName"].ToString(); auction.Description = newAuction.Description; auction.Image_Path = newAuction.Image_Path; if (auction.Image_Path == null) { auction.Image_Path = "http://www.bernunlimited.com/c.4436185/sca-dev-vinson/img/no_image_available.jpeg"; } try { _auctionService.CreateAuction(auction); } catch { return(Content("Insert error")); } return(RedirectToAction("Index", "Home", null)); } else { return(Content("Error")); } }
public async Task DeleteAuction(AuctionDto auctionDto) { var auction = _mapper.Map <Auction>(auctionDto); _unitOfWork.Auction.DeleteAuction(auction); await _unitOfWork.SaveAsync(); }
public async Task <IEnumerable <ItemDto> > GetItemsForAuction(AuctionDto auction) { using (UnitOfWorkProvider.Create()) { return(await auctionService.GetItemsForAuctionAsync(auction.Id)); } }
public void DeleteAuction(AuctionDto auction) { Auction act = new Auction(); act.Id = auction.Id; _auctionRepository.DeleteAuction(act); }
public async Task PayloadPreenchido_LeilaoNaoEncontrado_RetornaNotFound(AuctionDto updateAuctionDto) { HttpResponseMessage response = await httpClient.PutAsJsonAsync($"{endpointUri}/{updateAuctionDto.Id.Substring(0, 24)}", updateAuctionDto); Assert.Equal(HttpStatusCode.NotFound, response.StatusCode); auctionServiceMock.Verify(mock => mock.GetByIdAsync(It.IsAny <string>()), Times.Once); userServiceMock.Verify(mock => mock.GetByIdAsync(It.IsAny <string>()), Times.Never); auctionServiceMock.Verify(mock => mock.UpdateAsync(It.IsAny <Auction>()), Times.Never); }
public void UpdateAuction(AuctionDto auction) { Auction act = new Auction(); act.Id = auction.Id; act.Buyer_Id = auction.Buyer_Id; _auctionRepository.UpdateAuction(act); }
public async Task CloseAuctionDueToTimeoutAsync(AuctionDto auction) { using (var uow = UnitOfWorkProvider.Create()) { var auctionBids = await _bidService.GetBidsAccordingToAuctionAsync(auction.Id); _closingAuctionService.CloseAuctionDueToTimeout(auction, auctionBids); await uow.Commit(); } }
public async Task <IEnumerable <RaiseDto> > GetRaisesForAuctionFromOldest(AuctionDto auction) { if (auction == null) { return(new List <RaiseDto>()); } var raises = await raiseService.GetRaisesByAuctionIDFromOldest(auction.Id); return(raises.Items); }
public void CloseAuctionDueToTimeout(AuctionDto auctionDto, IEnumerable <BidDto> auctionBids) { var auction = Mapper.Map <Auction>(auctionDto); if (auctionBids.Any()) { auction.SellTime = auction.EndTime; } auction.Ended = true; _auctionRepository.Update(auction); }
private Auction CreateAuction(AuctionDto auctionDto) { Auction auction = new Auction(); auction.Title = auctionDto.Title; auction.Description = auctionDto.Description; auction.StartPrice = auctionDto.StartPrice; auction.CurrentPrice = auctionDto.StartPrice; auction.Seller = repository.GetMembers().FirstOrDefault(m => m.DisplayName.Equals(auctionDto.SellerName)); auction.StartDateTimeUtc = DateTime.ParseExact(auctionDto.StartDateTimeUtc, "MM/dd/yyyy HH:mm:ss", null); auction.EndDateTimeUtc = DateTime.ParseExact(auctionDto.EndDateTimeUtc, "MM/dd/yyyy HH:mm:ss", null); return(auction); }
public void EntidadePreenchida_RetornaDtoPreenchido(Auction auction) { AuctionDto result = AuctionDto.From(auction); Assert.Equal(auction.Close, result.Close); Assert.Equal(auction.Id, result.Id); Assert.Equal(auction.InitialBid, result.InitialBid); Assert.Equal(auction.IsUsed, result.IsUsed); Assert.Equal(auction.Name, result.Name); Assert.Equal(auction.Open, result.Open); Assert.Equal(auction.Responsible.Id, result.Responsible.Id); Assert.Equal(auction.Responsible.Name, result.Responsible.Name); }
public void RetornaEntidade(AuctionDto auctionDto, User user) { Auction result = auctionDto.To(user); Assert.Equal(auctionDto.Close, result.Close); Assert.Equal(auctionDto.Id, result.Id); Assert.Equal(auctionDto.InitialBid, result.InitialBid); Assert.Equal(auctionDto.IsUsed, result.IsUsed); Assert.Equal(auctionDto.Name, result.Name); Assert.Equal(auctionDto.Open, result.Open); Assert.Equal(user.Id, result.Responsible.Id); Assert.Equal(user.Name, result.Responsible.Name); }
public async Task <string> PutAuction(int id, [FromBody] AuctionDto auction) { if (!ModelState.IsValid) { throw new HttpResponseException(HttpStatusCode.BadRequest); } var success = await ModifyAuctionsFacade.UpdateAuctionAsync(auction); if (!success) { throw new HttpResponseException(HttpStatusCode.NotFound); } return($"Updated auction with id: {id}"); }
private void GetHtmlDocumentPages(AuctionDto auction, List <HtmlDocument> documents) { int pageCount = GetPageNumber(documents.Single()); _logger.LogInformation($"Znaleziono stron: {pageCount} dla aukcji: {auction.FilteredUrl}"); if (pageCount > 1) { for (int i = 1; i < pageCount; i++) { var document = GetHtmlDocument($"{auction.FilteredUrl}&p={i}"); documents.Add(document); } } }
public async Task BuyoutAuction(AuctionDto auction, BidDto bid) { using (var uow = UnitOfWorkProvider.Create()) { await _bidService.PlaceBid(bid); await uow.Commit(); var auctionBids = await _bidService.GetBidsAccordingToAuctionAsync(auction.Id); _closingAuctionService.CloseAuctionDueToBuyout(auction, auctionBids); await uow.Commit(); } }
public async Task <Auction> Update(AuctionDto auctionDto, int id) { var auc = await GetAuctionById(id); _db.Auctions.Attach(auc); auc.StartDateTime = auctionDto.StartDateTime; auc.EndDateTime = auctionDto.StartDateTime.AddDays(3); auc.Status = auctionDto.Status == Enums.AuctionStatus.Failed ? Enums.AuctionStatus.Failed : auctionDto.StartDateTime > System.DateTime.Now ? Enums.AuctionStatus.Wait : Enums.AuctionStatus.Active; auc.StartPrice = auctionDto.StartPrice; await _db.SaveChangesAsync(); return(auc); }
public async Task <Guid> CreateAuctionWithCategoryNameForUserAsync(AuctionDto auction, string userLogin, string categoryName) { using (var uow = UnitOfWorkProvider.Create()) { auction.CategoryId = (await _categoryService.GetCategoriesIdsAccordingToNameAsync(new[] { categoryName })).FirstOrDefault(); auction.SellerId = (await _userLoginService.GetUserAccordingToUsernameAsync(userLogin)).Id; var auctionId = _auctionService.Create(auction); await uow.Commit(); //var delay = auction.EndTime.Subtract(DateTime.Now); //BackgroundJob.Schedule(() => CloseAuctionDueToTimeoutAsync(auction), delay); //BackgroundJob.Schedule(() => new Func<AuctionDto, Task>(CloseAuctionDueToTimeoutAsync).Invoke(auction), auction.EndTime); return(auctionId); } }
public async Task <bool> EditAuction(AuctionDto auction) { using (var uow = UnitOfWorkProvider.Create()) { if (await _auctionService.GetAsync(auction.Id, false) == null) { return(false); } await _auctionService.Update(auction); await uow.Commit(); return(true); } }
public void CreateAuction(AuctionDto auction) { Auction act = new Auction(); act.Name = auction.Name; act.Price = auction.Price; act.Seller_Id = auction.Seller_Id; act.Description = auction.Description; act.Image_Path = auction.Image_Path; /* * act.Date_Added = DateTime.Now; * act.Date_Purchased = null; */ _auctionRepository.CreateAuction(act); }
public AuctionDto CreateAuction(AuctionDto auctionDto) { if (!ModelState.IsValid) { throw new HttpResponseException(HttpStatusCode.BadRequest); } var auction = Mapper.Map <AuctionDto, Auction>(auctionDto); _context.Auctions.Add(auction); _context.SaveChanges(); auctionDto.Id = auction.Id; return(auctionDto); }
public IEnumerable <AuctionDto> GetAllBought(AuctionDto act) { Auction auct = new Auction(); auct.Buyer_Id = act.Seller_Id; auct.Status = "Sold"; var auctionDtos = new List <AuctionDto>(); foreach (Auction auction in _auctionRepository.GetAllBought(auct)) { auctionDtos.Add(new AuctionDto { Id = auction.Id, Name = auction.Name, Price = auction.Price, Seller_Id = auction.Seller_Id }); } return(auctionDtos); }
public IEnumerable <AuctionDto> GetAllUsersAuctions(AuctionDto act) { Auction auct = new Auction(); auct.Seller_Id = act.Seller_Id; var auctionDtos = new List <AuctionDto>(); foreach (Auction auction in _auctionRepository.GetAllUsersAuctions(auct)) { auctionDtos.Add(new AuctionDto { Id = auction.Id, Name = auction.Name, Price = auction.Price }); } return(auctionDtos); }
public async Task <JsonResult> Update(string auction, int id) // не учитывается статус аукциона для возможности редактирования { AuctionDto auctionDto = JsonConvert.DeserializeObject <AuctionDto>(auction, new IsoDateTimeConverter { DateTimeFormat = "dd.MM.yyyy HH:mm:ss" }); try { var auc = await _auctionService.Update(auctionDto, id); return(Json(new { success = true, result = auc })); } catch (Exception ex) { return(Json(new { success = false, result = ex.Message })); } }
public async Task <Auction> Create(AuctionDto auctionDto) { var newAuction = new Auction() { Status = Enums.AuctionStatus.Wait, PaidStatus = Enums.PaidStatus.NotPaid, StartDateTime = auctionDto.StartDateTime, EndDateTime = auctionDto.StartDateTime.AddDays(3), // 3 дня на аукцион StartPrice = auctionDto.StartPrice, ProductId = auctionDto.ProductId }; await _db.Auctions.AddAsync(newAuction); await _db.SaveChangesAsync(); return(newAuction); }
public void CloseAuctionDueToBuyout(AuctionDto auctionDto, IEnumerable <BidDto> auctionBids) { if (!auctionBids.Any()) { throw new ArgumentException("ClosingAuctionService - CloseAuctionDueToBuyout(...) - auctionBids must contain at least one bid."); } var lastBid = auctionBids.OrderByDescending(bid => bid.Time).First(); if (lastBid.NewItemPrice != auctionDto.BuyoutPrice) { throw new ArgumentException("ClosingAuctionService - CloseAuctionDueToBuyout(...) - auctionBids must contain buyout bid"); } var auction = Mapper.Map <Auction>(auctionDto); auction.Ended = true; auction.SellTime = lastBid.Time; _auctionRepository.Update(auction); }
private AuctionDto TransformAuctionToAuctionDto(Auction a) { var am = new AuctionDto { AuctionId = a.AuctionId, AuctionDate = a.AuctionDate.ToString("yyyy-MM-dd"), Percent = a.Percent, Value = a.Value, Weight = a.Weight, LimitDate = a.LimitDate.ToString("yyyy-MM-dd"), Observation = a.Observation, CompanyName = a.CompanyName, Destination = a.Destination, PhoneNumber = a.PhoneNumber, Status = a.Status, Products = a.Products }; return(am); }