Ejemplo n.º 1
0
 /// <summary>
 /// Insert a pickup for user into db asyncronously, this method should only be used to manully insert
 /// into the db. Use SchedulePickup() to actually schedule a pickup
 /// </summary>
 /// <param name="p">ScheduledPickup object properly populated</param>
 /// <returns>StatusResult</returns>
 public static async Task<StatusResult<ScheduledPickup>> InsertScheduledPickupAsync(ScheduledPickup p)
 {
     try
     {
         var db = BottleRocketDbContext.Create();
         db.ScheduledPickups.Add(p);
         await db.SaveChangesAsync();
     }
     catch (Exception ex)
     {
         return StatusResult<ScheduledPickup>.Error(ex.Message);
     }
     return StatusResult<ScheduledPickup>.Success();
 }
Ejemplo n.º 2
0
 public static StatusResult<ScheduledPickup> UpdateScheduledPickup(ScheduledPickup p)
 {
     //TODO:: NEED TO BE TESTED, NOT SURE IF THIS WORKS
     try
     {
         var db = BottleRocketDbContext.Create();
         db.Entry(p).State = EntityState.Modified;
         db.SaveChanges();
     }
     catch (Exception ex)
     {
         return StatusResult<ScheduledPickup>.Error(ex.Message);
     }
     return StatusResult<ScheduledPickup>.Success();
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Insert a pickup for user into db asyncronously. This method should only be used to manully insert
        /// into the db. Use SchedulePickup() to actually schedule a pickup
        /// </summary>
        /// <param name="userId">The user's Id </param>
        /// <returns>StatusResult</returns>
        public static async Task<StatusResult<ScheduledPickup>> InsertScheduledPickupAsync(string userId)
        {
            // get the user's address from db
            var userAddy = UserAddressManager.GetUserAddressByUserId(userId);

            if (userAddy.Code != StatusCode.OK)
            {
                return StatusResult<ScheduledPickup>.Error("User address not found");
            }

            var sp = new ScheduledPickup()
            {
                UserId = userId,
                DateCreated = DateTime.UtcNow,
                IsPickedUp = false,
                AddressId = userAddy.Result.Id
            };
            return await InsertScheduledPickupAsync(sp);
        }