public void CreateBidAsync_CreateBidInNotActiveAuction_ValidationExceptionThrown() { var bid = new BidDTO() { BidId = 6, Date = new DateTime(2019, 1, 1, 12, 0, 0), PlacedUserName = "******", LotId = 1, Price = 20 }; _mockUnitWork.Setup(x => x.UserProfiles.FindAsync(It.IsAny <Expression <Func <UserProfile, bool> > >(), 10, 0)) .ReturnsAsync((Items: _users, TotalCount: _lots.Count)); _mockUnitWork.Setup(x => x.Lots.GetAsync(bid.LotId)).ReturnsAsync(new Lot() { LotId = 1, BeginDate = new DateTime(2018, 1, 1, 12, 0, 0), EndDate = new DateTime(2019, 1, 1, 12, 0, 0) }); _mockUnitWork.Setup(x => x.Bids.GetAsync(bid.BidId)).ReturnsAsync(new Bid() { BidId = 6 }); Assert.ThrowsAsync <ValidationException>(() => _service.CreateBidAsync(bid), "Auction is not active."); }
public HttpResponseMessage Bid(BidDTO bidDTO) { if (bidDTO.Listing.Bids.Count == 0) { } else { if (bidDTO.BidAmount <= bidDTO.Listing.Bids.Max(b => b.BidAmount)) { return(Request.CreateResponse(HttpStatusCode.Conflict)); } } Bid bidToAdd = mapper.CreateBidEntity(bidDTO); if (bidDTO.Listing.AuctionEndTime > System.DateTime.Now) { bidToAdd = bidRepo.BidOnListing(bidToAdd); } var response = Request.CreateResponse <ListingDetailDTO>(HttpStatusCode.Created, mapper.CreateListingDetailDTO(bidToAdd.Listing)); string uri = Url.Link("DefaultApi", new { id = bidToAdd.ListingId }); response.Headers.Location = new Uri(uri); return(response); }
public void MakeABid(int?lotId, BidDTO bid) { if (bid == null) { throw new ArgumentNullException("bid"); } if (lotId == null) { throw new ArgumentNullException("lotId"); } Lot lot = Database.Lots.Get(lotId.Value); if (lot == null) { throw new ItemNotExistInDbException("lot", lotId.ToString()); } if (lot.Status != Status.Active) { throw new InaccessibleLotException("inactive lot", lot.Id.ToString()); } lot.Bids.Add(Mapper.Map <Bid>(bid)); }
public BidDTO SelectBidById(long BidId) { command = new SqlCommand(StoredProcedureName.Names.SelectBidById.ToString(), connection); command.CommandType = CommandType.StoredProcedure; command.Parameters.Add("@BidId", SqlDbType.BigInt); command.Parameters[0].Value = BidId; connection.Open(); datareader = command.ExecuteReader(); if (!datareader.HasRows) { return(null); } while (datareader.Read()) { bid = new BidDTO(); bid.BidId = Convert.ToInt64(datareader["BidId"]); bid.JobId = Convert.ToInt64(datareader["JobId"]); bid.ProviderId = Convert.ToInt64(datareader["ProviderId"]); bid.ProviderName = datareader["ProviderName"].ToString(); bid.ProviderSkill = datareader["ProviderSkills"].ToString(); bid.ProviderCountry = datareader["ProviderCountry"].ToString(); bid.ProjectTitle = datareader["ProjectTitle"].ToString(); bid.Amount = datareader["Amount"].ToString(); bid.Description = datareader["Description"].ToString(); //bid.BidOn = Convert.ToDateTime(datareader["BidOn"].ToString()); //bid.AdvancePayment = Convert.ToInt16(datareader["AdvancePayment"].ToString()); bid.Duration = datareader["Duration"].ToString(); } connection.Close(); return(bid); }
public async Task CreateBidAsync_CreateValidBid_BidCreated() { var bid = new BidDTO() { BidId = 6, Date = new DateTime(2019, 1, 1, 12, 0, 0), PlacedUserName = "******", LotId = 1, Price = 20 }; _mockUnitWork.Setup(x => x.UserProfiles.FindAsync(It.IsAny <Expression <Func <UserProfile, bool> > >(), 10, 0)) .ReturnsAsync((Items: _users, TotalCount: 1)); _mockUnitWork.Setup(x => x.Lots.GetAsync(bid.LotId)).ReturnsAsync(new Lot() { LotId = 1, BeginDate = new DateTime(2018, 1, 1, 12, 0, 0), EndDate = new DateTime(2020, 1, 1, 12, 0, 0) }); _mockUnitWork.Setup(x => x.Bids.GetAsync(bid.BidId)).ReturnsAsync(new Bid() { BidId = 6 }); var createdBid = await _service.CreateBidAsync(bid); Assert.That(createdBid, Is.Not.Null); Assert.That(createdBid.BidId, Is.EqualTo(bid.BidId)); _mockUnitWork.Verify(x => x.SaveAsync(), Times.Once); }
protected void Page_Load(object sender, EventArgs e) { description = (HtmlMeta)Master.FindControl("Description"); keyword = (HtmlMeta)Master.FindControl("Keywords"); description.Content = "asdasdas"; keyword.Content = "asdasdsadsd,asdasdas,adsda"; bid = Convert.ToInt64(Request.QueryString["BidId"]); bidbl = new BidBL(); bidDTO = bidbl.SelectBidById(bid); LinkProjectName.Text = bidDTO.ProjectTitle.ToString(); LinkProjectName.NavigateUrl = "~/Project/ViewProject.aspx?ProjectId=" + bidDTO.JobId.ToString(); LblProvidername.Text = bidDTO.ProviderName.ToString(); LblProviderSkills.Text = bidDTO.ProviderSkill.ToString(); LblProviderCountry.Text = bidDTO.ProviderCountry.ToString(); LblDuration.Text = bidDTO.Duration.ToString(); LblBidOn.Text = bidDTO.BidOn.ToString(); LblAmount.Text = "$ " + bidDTO.Amount.ToString(); LblAdvancePayment.Text = "$ " + bidDTO.AdvancePayment.ToString(); LblDescription.Text = bidDTO.Description.ToString(); BtnAcceptBid.PostBackUrl = "~/Bid/BidAccept.aspx"; }
public long InsertBid(BidDTO Bid) { command = new SqlCommand(StoredProcedureName.Names.InsertBid.ToString(), connection); command.CommandType = CommandType.StoredProcedure; command.Parameters.Add("@JobId", SqlDbType.BigInt); command.Parameters.Add("@ProviderId", SqlDbType.BigInt); command.Parameters.Add("@Amount", SqlDbType.VarChar, 50); command.Parameters.Add("@Description", SqlDbType.VarChar, 5000); command.Parameters.Add("@BidOn", SqlDbType.DateTime); command.Parameters.Add("@AdvancePayment", SqlDbType.Int); command.Parameters.Add("@Duration ", SqlDbType.VarChar, 50); command.Parameters[0].Value = Bid.JobId; command.Parameters[1].Value = Bid.ProviderId; command.Parameters[2].Value = Bid.Amount; command.Parameters[3].Value = Bid.Description; command.Parameters[4].Value = Bid.BidOn; command.Parameters[5].Value = Bid.AdvancePayment; command.Parameters[6].Value = Bid.Duration; long Bidid = 0; connection.Open(); Bidid = command.ExecuteNonQuery(); connection.Close(); return(Bidid); }
public IHttpActionResult DismissBid(BidDTO bidDTO) { List <Bid> bidsToDismiss = mapper.CreateBidEditEntities(bidDTO); bidRepo.DismissBid(bidsToDismiss); return(Ok()); }
public void CreateBidTest_CreateBidAtNotActiveAuction_BLValidationExceptionThrown() { //arrange var bid = new BidDTO() { Id = 6, BidDate = DateTime.Now, UserName = "******", LotId = 1, BidPrice = 20 }; _mockUnitOfWork.Setup(x => x.Lots.GetById(bid.LotId)).Returns(new Lot() { Id = 1, BeginDate = DateTime.Now.AddDays(-10), EndDate = DateTime.Now.AddDays(-5), InitialPrice = 1, Bids = new List <Bid>() }); //act //assert Assert.Throws <BLValidationException>(() => _service.CreateBid(bid), "Bid can’t be placed after auction end"); }
public async Task <Response> CreateNewBid(NewBidRequest bidRequest) { BidEntity bidEntity = _mapper.Map <BidEntity>(bidRequest); //TODO is this the time we want? (or global). bidEntity.CreationDate = DateTime.Now; bidEntity.Id = Guid.NewGuid().ToString(); bidEntity.UnitsCounter = 0; bidEntity.PotenialSuplliersCounter = 0; bidEntity.Product.Id = Guid.NewGuid().ToString(); bidEntity.CurrentParticipancies = new List <ParticipancyEntity>(); bidEntity.CurrentProposals = new List <SupplierProposalEntity>(); _context.Bids.Add(bidEntity); try { await _context.SaveChangesAsync().ConfigureAwait(false); } catch (Exception ex) { //TODO log exception and return proper error message instead return(new Response() { IsOperationSucceeded = false, SuccessOrFailureMessage = ex.Message }); } BidDTO dto = _mapper.Map <BidDTO>(bidEntity); return(new Response() { IsOperationSucceeded = true, SuccessOrFailureMessage = this.getSuccessMessage() }); }
public async Task <IHttpActionResult> CreateBid([FromBody] BidDTO bid) { if (bid == null) { return(BadRequest()); } var UserName = this.User.Identity.Name; var user = await _userService.FindByNameAsync(UserName); if (user == null) { return(NotFound()); } bid.UserId = user.Id; bid.MadeOn = DateTime.Now; if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { await _bidService.CreateAsync(bid); } catch (ArgumentException e) { return(BadRequest(e.Message)); } catch (Exception e) { return(BadRequest(e.Message)); } return(StatusCode(HttpStatusCode.Created)); }
public void ShuldReturnTrueIfGetBidsWork() { //Arrange Bid one = new Bid { Sum = 10, Id = 1 }; BidDTO two = new BidDTO { Sum = 10, Id = 1 }; Mock <IRepository <Bid> > repositoryMock = new Mock <IRepository <Bid> >(); repositoryMock.Setup(a => a.GetAll()).Returns(new List <Bid>() { one }); var uowMock = new Mock <IUnitOfWork>(); uowMock.Setup(uow => uow.Biddings).Returns(repositoryMock.Object); var bidService = new BidService(uowMock.Object); List <BidDTO> expected = new List <BidDTO>(); expected.Add(two); //Act List <BidDTO> actual = (List <BidDTO>)bidService.GetBids(); //Assert Assert.IsTrue(expected.SequenceEqual(actual, new BiddingDtoEqualityComparer())); }
public int UpdateBid(BidDTO Bid) { command = new SqlCommand(StoredProcedureName.Names.UpdateBid.ToString(), connection); command.CommandType = CommandType.StoredProcedure; command.Parameters.Add("@BidId", SqlDbType.BigInt); command.Parameters.Add("@JobId", SqlDbType.BigInt); command.Parameters.Add("@ProviderId", SqlDbType.BigInt); command.Parameters.Add("@Amount", SqlDbType.VarChar, 50); command.Parameters.Add("@Comments", SqlDbType.VarChar, 500); command.Parameters[0].Value = Bid.BidId; command.Parameters[1].Value = Bid.JobId; command.Parameters[2].Value = Bid.ProviderId; command.Parameters[3].Value = Bid.Amount; //command.Parameters[4].Value = Bid.Comments; int rowaffected = 0; connection.Open(); rowaffected = command.ExecuteNonQuery(); connection.Close(); return(rowaffected); }
public async Task <Response <BidDTO> > CreateNewBid(NewBidRequest bidRquest) { // create BidEntity bidEnitity = _mapper.Map <BidEntity>(bidRquest); bidEnitity.CreationDate = DateTime.Now; bidEnitity.Id = Guid.NewGuid().ToString(); // add to db if (mockedBidsSet.TryAdd(bidEnitity.Id, bidEnitity)) { BidDTO bidDto = _mapper.Map <BidDTO>(bidEnitity); return(new Response <BidDTO> { IsOperationSucceeded = true, //SuccessOrFailureMessage = bidDto.GetType().GetProperties().ToList().ForEach(entity => { }) DTOObject = bidDto, }); } else { return(new Response <BidDTO> { IsOperationSucceeded = false, SuccessOrFailureMessage = "failed to add to db" }); } }
protected void BtnConfirmAndPost_Click(object sender, EventArgs e) { bid = (BidDTO)Session["BidDTO"]; bidbl = new BidBL(); bidbl.InsertBid(bid); Response.Redirect("~/Workspace/ProviderBids.aspx"); }
public async Task <ActionResult> DismissBid(int Id, int ListingId, int UserId) { BidDTO bid = new BidDTO() { Id = Id, Listing = new ListingDTO() { Id = ListingId, AuctionEndTime = System.DateTime.UtcNow }, User = new UserDTO() { Id = UserId } }; string content = JsonConvert.SerializeObject(bid); Byte[] buffer = System.Text.Encoding.UTF8.GetBytes(content); ByteArrayContent byteContent = new ByteArrayContent(buffer); byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json"); HttpResponseMessage result = await client.PostAsync(apiUrl + "/DismissBid", byteContent); return(new EmptyResult()); }
private BidEntry CreateDTO(BidDTO order, int location) { var data = _mapper.Map <BidEntry>(order); data.NiceHashDataCenter = location; return(data); }
public static BidDumbWPF FromDTO(BidDTO bid) { return(new BidDumbWPF() { Amount = bid.Amount, BuyerName = bid.BuyerName, PutDate = bid.PutDate.ToShortDateString() + " " + bid.PutDate.ToShortTimeString() }); }
public async Task CreateAsync(BidDTO model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } model.MadeOn = DateTime.Now; _unitOfWork.Bids.Create(BidMapper.MapToEntity(model)); await _unitOfWork.SaveAsync(); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { bid = (BidDTO)Session["BidDTO"]; //LblJobTitle.Text = bid.ProviderName.ToString(); LblEstimatedduration.Text = bid.Duration; LblDescription.Text = bid.Description; LblAmount.Text = bid.Amount; } }
public static Bid MapToEntity(BidDTO obj) { return(new Bid { Id = obj.Id, ItemId = obj.ItemId, Amount = obj.Amount, MadeOn = obj.MadeOn, UserId = obj.UserId }); }
public Bid CreateBidEntity(BidDTO bidDTO) { return(new Bid() { Id = bidDTO.Id, Dismissed = bidDTO.Dismissed, BidAmount = bidDTO.BidAmount, Listing = listingRepo.GetListingById(bidDTO.Listing.Id), User = userRepo.GetUserById(bidDTO.User.Id) }); }
public async Task <ActionResult> Bid(BidDTO bidDTO) { HttpResponseMessage responseMessage = await client.GetAsync(apiUrl + "/GetListing/" + bidDTO.Listing.Id); string responseData = responseMessage.Content.ReadAsStringAsync().Result; ListingDetailDTO listing = JsonConvert.DeserializeObject <ListingDetailDTO>(responseData); if (listing.Bids.Count > 0) { if (bidDTO.BidAmount < (listing.Bids.Max(b => b.BidAmount) + 0.50M)) { TempData["BidError"] = "true"; return(RedirectToAction("Detail", "Listing", new { id = bidDTO.Listing.Id })); } } else { if (bidDTO.BidAmount < (listing.Price + 0.50M)) { TempData["BidError"] = "true"; return(RedirectToAction("Detail", "Listing", new { id = bidDTO.Listing.Id })); } } ClaimsIdentity identity = (ClaimsIdentity)User.Identity; responseMessage = await client.GetAsync("http://localhost:58999/API/user/GetUser/" + int.Parse(identity.FindFirst(ClaimTypes.NameIdentifier).Value)); responseData = responseMessage.Content.ReadAsStringAsync().Result; UserDTO user = JsonConvert.DeserializeObject <UserDTO>(responseData); BidDTO newBid = new BidDTO(); newBid.BidAmount = bidDTO.BidAmount; newBid.User = user; newBid.Listing = listing; string content = JsonConvert.SerializeObject(newBid); Byte[] buffer = System.Text.Encoding.UTF8.GetBytes(content); ByteArrayContent byteContent = new ByteArrayContent(buffer); byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json"); responseMessage = await client.PostAsync(apiUrl + "/bid", byteContent); if (responseMessage.StatusCode == HttpStatusCode.Created) { return(RedirectToAction("Detail", "Listing", new { id = bidDTO.Listing.Id })); } return(View("Error")); }
public void Add(Bid bid) { var bidHistoryDTO = new BidDTO(); bidHistoryDTO.AuctionId = bid.AuctionId; bidHistoryDTO.Bid = bid.AmountBid.GetSnapshot().Value; bidHistoryDTO.BidderId = bid.Bidder; bidHistoryDTO.TimeOfBid = bid.TimeOfBid; bidHistoryDTO.Id = Guid.NewGuid(); _unitOfWork.RegisterNew(bidHistoryDTO, this); }
public async Task <IHttpActionResult> CreateBidAsync(int lotId, BidDTO bid) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } bid.Price = Math.Round(bid.Price, 2); bid.PlacedUserName = User.Identity.Name; bid.LotId = lotId; var createdBid = await _bidsService.CreateBidAsync(bid); return(Created(Request.RequestUri + "/" + createdBid?.LotId, createdBid)); }
public void Add(Bid bid) { var bidDTO = new BidDTO(); bidDTO.AuctionId = bid.AuctionId; bidDTO.Bid = bid.AmountBid.GetSnapshot().Value; bidDTO.BidderId = bid.Bidder; bidDTO.TimeOfBid = bid.TimeOfBid; bidDTO.Id = Guid.NewGuid(); _auctionExampleContext.Bids.Add(bidDTO); }
protected void DataListProviderBids_OnItemDataBound(object sender, DataListItemEventArgs e) { bid = (BidDTO)e.Item.DataItem; HyperLink LnkName = (HyperLink)e.Item.FindControl("LnkName"); Label LblProjectTitle = (Label)e.Item.FindControl("LblProjectTitle"); Label LblAmount = (Label)e.Item.FindControl("LblAmount"); LnkName.NavigateUrl = "~/Bid/ViewBid.aspx?BidId=" + bid.BidId; LblProjectTitle.Text = bid.ProjectTitle; LblAmount.Text = "<b>Bid Amount</b> $ " + bid.Amount.ToString(); }
public ActionResult Bid(int id) { var bid = new BidDTO { Sum = lotService.GetLotById(id).BidRate, UserId = HttpContext.User.Identity.GetUserId(), LotId = id, Date = DateTime.Now }; bidService.MakeBid(bid); return(View("AcceptedBid")); }
public void Create(BidDTO bid, string userId) { if (bid == null) { throw new ArgumentNullException("bid"); } if (userId == null) { throw new ArgumentNullException("userId"); } //Database.Bids.Create(Mapper.Map<Lot>(bid), ); Database.Save(); }
protected void Page_Load(object sender, EventArgs e) { //System.Diagnostics.Debugger.Break(); GetCookie(); project = new ProjectDTO(); projectbl = new ProjectBL(); bid = new BidDTO(); bidbl = new BidBL(); if (Request.QueryString["ProjectId"] != null && Request.QueryString["ProjectId"] != "") { ProjectId = Convert.ToInt64(Request.QueryString["ProjectId"]); project = projectbl.SelectProjectById(ProjectId); if (ProviderId == project.ProviderId) { BtnBid.Text = "Edit"; } else { BtnBid.Text = "Bid"; } LinkJobPostedBy.Text = project.ProviderName; LblCategory.Text = project.ProjectCategory; LblBidOpenTill.Text = project.BidOpenTill.ToString(); LblDescription.Text = project.Description; LblBudget.Text = project.Budget.ToString(); LblLocation.Text = project.ProjectLocation.ToString(); LblProjectName.Text = project.ProjectTitle; LblSkill.Text = project.ProjectSkills.ToString(); LblPlannedStart.Text = project.PlannedStart; if (bidbl.SelectBidByJobId(ProjectId) != null) { DataListBidOnProject.Visible = true; LblNoBids.Visible = false; DataListBidOnProject.DataSource = bidbl.SelectBidByJobId(ProjectId); DataListBidOnProject.DataBind(); } else { DataListBidOnProject.Visible = false; LblNoBids.Visible = true; } } }