public IActionResult MakeOffer(Offer offer) { var userId = User.FindFirstValue(ClaimTypes.NameIdentifier); var product = _productRepository.GetProductById(offer.ProductId); if (ModelState.IsValid) { if (product != null) { if (!product.Sold.IsSold) { // will check latest offer var checkOfferAlreadyExist = _offerRepository.GetOfferForProductByUser(offer.ProductId, userId); if (checkOfferAlreadyExist == null) { offer.UserId = userId; offer.DatePosted = DateTime.Now; offer.isPending = true; _offerRepository.AddOffer(offer); return(Json(new { success = "True", message = "Offer has been sent" })); } // if the offer is not approved and is not in pending state means product has been rejected else if (!checkOfferAlreadyExist.isApproved && !checkOfferAlreadyExist.isPending) { offer.UserId = userId; offer.DatePosted = DateTime.Now; offer.isPending = true; _offerRepository.AddOffer(offer); return(Json(new { success = "true", message = "Offer has been sent" })); } // user already has an offer pending else { return(Json(new { success = "false", message = "Offer is already pending" })); } } return(Json(new { success = "false", message = "Product has already been sold" })); } } return(NotFound()); }
public IActionResult TradeOffered(AddOfferDto newOffer) { if (_repo.AddOffer(newOffer)) { return(Ok()); } else { return(BadRequest()); } }
/// <summary> /// This is the main entry point for your service replica. /// This method executes when this replica of your service becomes primary and has write status. /// </summary> /// <param name="cancellationToken">Canceled when Service Fabric needs to shut down this service replica.</param> protected override async Task RunAsync(CancellationToken cancellationToken) { _repObj = new OfferRepository(this.StateManager); var offer1 = new Offer { OfferId = 1, MinAmount = 20000, MaxAmount = 50000, Cashback = 50 }; var offer2 = new Offer { OfferId = 2, MinAmount = 50001, MaxAmount = 100000, Cashback = 100 }; var offer3 = new Offer { OfferId = 3, MinAmount = 100001, MaxAmount = 150000, Cashback = 200 }; var offer4 = new Offer { OfferId = 4, MinAmount = 150001, MaxAmount = 200000, Cashback = 300 }; await _repObj.AddOffer(offer1); await _repObj.AddOffer(offer2); await _repObj.AddOffer(offer3); await _repObj.AddOffer(offer4); }
//The seller sets his price at $30. That’s his ask price. //You are willing to pay $20 for the card.That your bid price //when user place a bid and asks a price and a quanity for specific product public async Task PlaceBid(int productId, decimal bidAmount, decimal limitPrice) { //Add new bid to offer table await _offerRepository.AddOffer(productId, bidAmount, limitPrice, _userManager.GetUserId(Context.User)); //take the list of bids from Offer table var tempbidTable = _offerRepository.Offers.Where(x => x.ProductId == productId).ToList(); var bidTable = tempbidTable.GroupBy(x => x.PriceOffer).Select(y => new { PriceOffer = y.First().PriceOffer, Quantity = y.Sum(s => s.Quantity), UserOfferId = y.First().UserOfferId }).OrderByDescending(t => t.PriceOffer); await Clients.All.InvokeAsync("PlaceBid", bidTable, productId); await SideNav(productId); }
public ActionResult AddOffer(Offer m_Offer) { if (ModelState.IsValid) { OfferRepository.AddOffer(m_Offer); return(Redirect("/Candidate/DisplayCandidate/" + m_Offer.CandidateId)); } else { ViewBag.CandId = m_Offer.CandidateId; ViewBag.Interviews = InterviewRepository.RetrieveAllCand(m_Offer.CandidateId); return(View("AddOffer")); } }
public async Task <ActionResult <ProspectDto> > AddProspect(ProspectDto dto) { if (dto == null) { return(BadRequest("Prospect does not exist.")); } Company company = new Company() { CompanyId = Guid.NewGuid().ToString(), CompanyName = dto.CompanyName, CompanyCountry = dto.CompanyCountry, CompanyZip = dto.CompanyZip, Registered = DateTime.Now, NumberOfEmployees = dto.NumberOfEmployees, CreatorId = dto.CreatorId }; Offer offer = new Offer() { OfferId = Guid.NewGuid().ToString(), Registered = DateTime.Now, FromCity = dto.FromCity, FromCountry = dto.FromCountry, FromZip = dto.FromZip, ToCity = dto.ToCity, ToCountry = dto.ToCountry, ToZip = dto.ToZip, Text = dto.Text, Solution = dto.Solution, Company = company, CreatorId = dto.CreatorId }; _companyRepository.AddCompany(company); await _companyRepository.SaveAllAsync(); _offerRepository.AddOffer(offer); await _offerRepository.SaveAllAsync(); var offerDto = _mapper.Map <OfferDto>(offer); await _hub.Clients.All.SendAsync("NewOffer", offerDto); return(Ok(dto)); }