Ejemplo n.º 1
0
 /// <summary>
 /// Deprecated Method for adding a new object to the SavedBuildings EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToSavedBuildings(SavedBuilding savedBuilding)
 {
     base.AddObject("SavedBuildings", savedBuilding);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Saves a Listing for a particular User
        /// </summary>
        /// <param name="listingId">listing identifier</param>
        /// <param name="username">user identifier</param>
        /// <returns>
        /// A status with the saved building
        /// </returns>
        public Status<SavedBuilding> CreateSavedBuilding(long listingId, string username)
        {
            if (listingId == 0)
                return Status.ValidationError<SavedBuilding>(null, "listingId", "listingId is required");

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

            using (var context = new RentlerContext())
            {
                var user = (from u in context.Users.Include("SavedBuildings")
                            where u.IsDeleted == false && (u.Username == username || u.Email == username)
                            select u).SingleOrDefault();

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

                // see if user already saved this building so we don't try to
                // save it again
                if (user.SavedBuildings.Any(s => s.BuildingId == listingId))
                    return Status.Error<SavedBuilding>("User already saved this building", null);

                SavedBuilding newSave = new SavedBuilding()
                {
                    BuildingId = listingId,
                    UserId = user.UserId,
                    CreateDateUtc = DateTime.UtcNow,
                    CreatedBy = "ListingAdapter"
                };

                user.SavedBuildings.Add(newSave);

                try
                {
                    context.SaveChanges();

                    InvalidateCache(newSave.BuildingId);

                    newSave.User = null;
                    return Status.OK<SavedBuilding>(newSave);
                }
                catch (Exception ex)
                {
                    return Status.Error<SavedBuilding>(
                        ex.Message,
                        null
                    );
                }
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Create a new SavedBuilding object.
 /// </summary>
 /// <param name="userId">Initial value of the UserId property.</param>
 /// <param name="buildingId">Initial value of the BuildingId property.</param>
 /// <param name="createDateUtc">Initial value of the CreateDateUtc property.</param>
 /// <param name="createdBy">Initial value of the CreatedBy property.</param>
 public static SavedBuilding CreateSavedBuilding(global::System.Int32 userId, global::System.Int64 buildingId, global::System.DateTime createDateUtc, global::System.String createdBy)
 {
     SavedBuilding savedBuilding = new SavedBuilding();
     savedBuilding.UserId = userId;
     savedBuilding.BuildingId = buildingId;
     savedBuilding.CreateDateUtc = createDateUtc;
     savedBuilding.CreatedBy = createdBy;
     return savedBuilding;
 }