예제 #1
0
 public static OfferDto MapOfferEntityToDto(Offer offer, bool mapBuyer = true)
 {
     return new OfferDto()
     {
         Id = offer.Id,
         Value = offer.Value,
         Created = offer.Created,
         Buyer = mapBuyer
             ? Mapper.MapUserAndProfileToRelatedUserDto(offer.Buyer.User, offer.Buyer)
             : new RelatedUserDto() { UserId = offer.BuyerId }
     };
 }
예제 #2
0
        public async Task<bool> UpdateOffer(Offer modifiedOffer)
        {
            var existingOffer = await this.dbContext.Offers.FindAsync(modifiedOffer.Id);

            if (existingOffer == null)
            {
                return false;
            }

            // Explicitly map the properties which can be changed to avoid changing some of the unchangable ones (ex: Username)
            existingOffer.Value = modifiedOffer.Value;
            await this.dbContext.SaveChangesAsync();

            return true;
        }
예제 #3
0
        public async Task<bool> CreateOffer(Guid propertyId, Offer newOffer)
        {
            var relatedProperty = await this.dbContext.Properties.FindAsync(propertyId);

            if (relatedProperty == null)
            {
                return false;
            }

            relatedProperty.Offers.Add(newOffer);
            // this.dbContext.Offers.Add(newOffer);
            await this.dbContext.SaveChangesAsync();

            return true;
        }