public async Task <UserListings> Update(UserListings userListings, string ownerId) { try { using (ApiMohoContext context = new ApiMohoContext()) { var userListing = await context.UserListings.SingleAsync(id => id.UserListingId == userListings.UserListingId && id.OwnerId == ownerId); userListing.CityRefId = userListings.CityRefId; userListing.ListingTypeRefId = userListings.ListingTypeRefId; userListing.CountryRefId = userListings.CountryRefId; userListing.ProvinceRefId = userListings.ProvinceRefId; userListing.ListingName = userListings.ListingName; userListing.CountryName = userListings.CountryName; userListing.ProvinceName = userListings.ProvinceName; userListing.CityName = userListings.CityName; userListing.LastUpdatedDate = DateTime.Now; userListing.ListingDescription = userListings.ListingDescription; userListing.ListingTitle = userListings.ListingTitle; userListing.PhoneNumber = userListings.PhoneNumber; userListing.Email = userListings.Email; userListing.FullName = userListings.FullName; userListing.Address = userListings.Address; await context.SaveChangesAsync(); return(userListing); } } catch (Exception ex) { _logger.LogError($"error while updateing listing from database: {ex}"); throw ex.GetBaseException(); } }
public async Task <UserListings> GetById(int id) { try { using (var context = new ApiMohoContext()) { var listing = await context.UserListings.FindAsync(id); if (listing != null) { if (listing.Views == null) { listing.Views = 1; } else { listing.Views += 1; } await context.SaveChangesAsync(); return(listing); } return(null); } } catch (Exception e) { Console.WriteLine(e); throw; } }
public async Task AddSendEmailLog(string message, string fromEmail, string toEmail, string recipientUserId) { try { using (var context = new ApiMohoContext()) { var log = new SendEmailLog() { Message = message, FromEmail = fromEmail, RecipientUserId = recipientUserId, ToEmail = toEmail }; await context.AddAsync(log); await context.SaveChangesAsync(); } } catch (Exception e) { Console.WriteLine(e); throw; } }
public async Task AddUserReview(UserReview userReview) { try { using (var context = new ApiMohoContext()) { var usr = await context.UserReview.AddAsync(userReview); await context.SaveChangesAsync(); } } catch (Exception ex) { _logger.LogError($"error while saving user review to database: {ex}"); throw ex.GetBaseException(); } }
public async Task SetListingStatus(int listingId, string ownderId, bool enabled) { using (var context = new ApiMohoContext()) { var listing = await context.UserListings.FindAsync(listingId); if (listing != null) { listing.ListingEnabled = enabled; await context.SaveChangesAsync(); } else { throw new Exception("No Listing was found by the given id {listingId}"); } } }
public async Task DeleteListing(int listingId, string ownderId) { using (var context = new ApiMohoContext()) { var listing = await context.UserListings.FindAsync(listingId); if (listing != null) { var del = context.UserListings.Remove(listing); await context.SaveChangesAsync(); } else { throw new Exception("No Listing was found by the given id {listingId}"); } } }
public async Task <UserListings> AddListing(UserListings userListings) { try { using (ApiMohoContext context = new ApiMohoContext()) { var result = await context.UserListings.AddAsync(userListings); await context.SaveChangesAsync(); var userlisting = result.Entity; return(userlisting); } } catch (Exception ex) { throw ex.InnerException; } }
public async Task AddUserLog(string userId, string logType, string logMessage) { try { using (var context = new ApiMohoContext()) { var log = new UserLogs() { UserId = userId, LogType = logType, LogMessage = logMessage }; await context.AddAsync(log); await context.SaveChangesAsync(); } } catch (Exception e) { Console.WriteLine(e); throw; } }