public void Post(int?id, PropertyDetails propertyDetails)
 {
     try
     {
         if (ModelState.IsValid)
         {
             bool            isNew       = !id.HasValue;
             PropertyDetails propDetails = isNew ? new PropertyDetails
             {
                 Id = id.Value
             } : _context.Set <PropertyDetails>().SingleOrDefault(s => s.Id == id.Value);
             propDetails.Address   = propertyDetails.Address;
             propDetails.Financial = propertyDetails.Financial;
             propDetails.Physical  = propertyDetails.Physical;
             if (isNew)
             {
                 _context.Add(propDetails);
             }
             _context.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #2
0
        public async Task <bool> ToggleInterestAsync(string propertyId, string userId)
        {
            var property = await _propertyDbContext.Properties.Include(x => x.Interests).SingleAsync(x => x.Id == propertyId).ConfigureAwait(false);

            var interest = property.Interests.SingleOrDefault(x => x.CustomerIdentityId == userId);

            var hasInterest = false;

            if (interest == null)
            {
                _propertyDbContext.Add(new PropertyInterest {
                    CustomerIdentityId = userId, Property = property
                });
                hasInterest = true;
            }
            else
            {
                property.Interests.Remove(interest);
            }
            await _propertyDbContext.SaveChangesAsync().ConfigureAwait(false);

            return(hasInterest);
        }