private static bool CompareWithDto(TradeOfferGetDto left, TradeOfferDto right) { if (left is null ^ right is null) { return(false); } if (left.Name != right.Name) { return(false); } if (left.ExpiryDate != right.ExpiryDate) { return(false); } if (left.Description != right.Description) { return(false); } if (left.Price != right.Price) { return(false); } if (left.Offer != right.Offer) { return(false); } if (left.BuyerId != right.BuyerId) { return(false); } return(true); }
public override bool Equals(object o) { TradeOfferDto dto = o as TradeOfferDto; if (dto is null) { return(false); } return(CompareWithDto(this, dto)); }
public async Task <IActionResult> PatchTradeOffer(int id, TradeOfferDto tradeOfferDto) { TradeOffer tradeOffer; try { tradeOffer = await _tradeOffersRepository.Select.ById(id); } catch (DataException) { return(BadRequest()); } StudentifyAccount buyerAccount = null; if (tradeOfferDto.BuyerId.HasValue) { var buyerId = tradeOfferDto.BuyerId.Value; try { buyerAccount = await _accountsRepository.Select.ById(buyerId); } catch (DataException) { return(NotFound("Buyer id not found")); } } tradeOffer.Name = tradeOfferDto.Name; tradeOffer.ExpiryDate = tradeOfferDto.ExpiryDate; tradeOffer.MapPoint.X = tradeOfferDto.Longitude; tradeOffer.MapPoint.Y = tradeOfferDto.Latitude; tradeOffer.Address = tradeOfferDto.Address; tradeOffer.Description = tradeOfferDto.Description; tradeOffer.Offer = tradeOfferDto.Offer; tradeOffer.Price = tradeOfferDto.Price; tradeOffer.Buyer = buyerAccount; try { await _tradeOffersRepository.Update.One(tradeOffer, id); } catch (DataException) { return(NotFound()); } return(NoContent()); }
public async Task <ActionResult <TradeOffer> > PostTradeOffer(TradeOfferDto tradeOfferDto) { var username = User.Identity.Name; var account = await _accountsRepository.SelectByUsername(username); StudentifyAccount buyerAccount = null; if (tradeOfferDto.BuyerId.HasValue) { var buyerId = tradeOfferDto.BuyerId.Value; try { buyerAccount = await _accountsRepository.Select.ById(buyerId); } catch (DataException) { return(NotFound("Buyer id not found")); } } var tradeOffer = new TradeOffer { Name = tradeOfferDto.Name, ExpiryDate = tradeOfferDto.ExpiryDate, MapPoint = new Point(tradeOfferDto.Longitude, tradeOfferDto.Latitude) { SRID = 4326 }, Address = tradeOfferDto.Address, Description = tradeOfferDto.Description, AuthorId = account.Id, CreationDate = DateTime.Now, Offer = tradeOfferDto.Offer, Price = tradeOfferDto.Price, Buyer = buyerAccount }; await _tradeOffersRepository.Insert.One(tradeOffer); return(CreatedAtAction(nameof(GetTradeOffer), new { id = tradeOffer.Id }, tradeOffer)); }