public async Task <ActionResult> AddPropertyInterest(long propertyId) { try { var propertyInterest = new RealEstatePropertyInterest() { PropertyId = propertyId, UserId = UserId }; await realEstatePropertyInterestRepository.CreateRealEstatePropertyInterest(propertyInterest); return(RedirectToAction("PropertyDetails", "Property", new { propertyId })); } catch (ArgumentNullException ex) { ViewBag.Error = "Invalid Property"; return(RedirectToAction("PropertyDetails", "Property", new { propertyId })); } catch (ArgumentException ex) { ViewBag.Error = "Invalid Property"; return(RedirectToAction("PropertyDetails", "Property", new { propertyId })); } catch { throw; } }
public async Task <RealEstatePropertyInterest> CreateRealEstatePropertyInterest(RealEstatePropertyInterest realEstatePropertyInterest) { if (realEstatePropertyInterest == null) { throw new ArgumentNullException(nameof(realEstatePropertyInterest)); } var realEstateProperty = RealEstateContext.RealEstateProperty.FirstOrDefault(x => x.PropertyId == realEstatePropertyInterest.PropertyId); var realEstateUser = RealEstateContext.Users.FirstOrDefault(x => x.Id == realEstatePropertyInterest.UserId); if (realEstateProperty == null || realEstateUser == null) { throw new ArgumentException(nameof(realEstatePropertyInterest)); } realEstatePropertyInterest.CreatedDate = System.DateTime.Now; realEstatePropertyInterest.IsActive = true; RealEstateContext.RealEstatePropertyInterest.Add(realEstatePropertyInterest); await RealEstateContext.SaveChangesAsync(); return(realEstatePropertyInterest); }