Ejemplo n.º 1
0
 /// <summary>
 /// Create a new UserInterest object.
 /// </summary>
 /// <param name="userInterestId">Initial value of the UserInterestId property.</param>
 /// <param name="userId">Initial value of the UserId property.</param>
 /// <param name="buildingId">Initial value of the BuildingId property.</param>
 /// <param name="applicationSubmitted">Initial value of the ApplicationSubmitted property.</param>
 public static UserInterest CreateUserInterest(global::System.Int32 userInterestId, global::System.Int32 userId, global::System.Int64 buildingId, global::System.Boolean applicationSubmitted)
 {
     UserInterest userInterest = new UserInterest();
     userInterest.UserInterestId = userInterestId;
     userInterest.UserId = userId;
     userInterest.BuildingId = buildingId;
     userInterest.ApplicationSubmitted = applicationSubmitted;
     return userInterest;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates the interest in building from the user to the current
        /// listing.
        /// </summary>
        /// <param name="username">The username.</param>
        /// <param name="listingId">The listing id.</param>
        /// <returns>
        /// A status of whether or not the interest was created.
        /// </returns>
        public Status<UserInterest> CreateInterestInBuilding(string username, long listingId, string message)
        {
            if (listingId == 0)
                return Status.ValidationError<UserInterest>(null, "listingId", "listingId is required");

            if (string.IsNullOrWhiteSpace(username))
                return Status.ValidationError<UserInterest>(null, "username", "username is required");

            using (var context = new RentlerContext())
            {
                try
                {
                    User user = (from u in context.Users
                                 where u.Username == username
                                 select u).SingleOrDefault();

                    if (user == null)
                        return Status.NotFound<UserInterest>();

                    UserInterest newInterest = new UserInterest()
                    {
                        BuildingId = listingId,
                        UserId = user.UserId,
                        Message = message
                    };

                    context.UserInterests.Add(newInterest);
                    context.SaveChanges();

                    // loads the building, which generated this interest, into newInterest
                    context.Entry(newInterest).Reference(e => e.Building).Load();

                    // notify landlord of interest
                    // TODO: if we are unable to send this email we need a way to allow the user
                    // to re-notify the Landlord without requiring them to continue to create
                    // interests
                    EmailListingInterestedModel model = new EmailListingInterestedModel(newInterest);
                    mailer.Interested(model);

                    return Status.OK<UserInterest>(newInterest);
                }
                catch (Exception ex)
                {
                    // log exception
                    return Status.Error<UserInterest>("System was unable to create interest", null);
                }
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Deprecated Method for adding a new object to the UserInterests EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToUserInterests(UserInterest userInterest)
 {
     base.AddObject("UserInterests", userInterest);
 }