public async Task <PropertyListingListViewModel> Handle(CreatePropertyListingCommand request, CancellationToken cancellationToken) { var contact = new ListingContact(request.ContactName, request.ContactTel, request.ContactEmail, request.ContactSMS, request.ContactOthers); //var listedProperty = _context.RentalProperty.FirstOrDefault(p => p.Id == request.RentalPropertyId); var listing = new PropertyListing(request.Title, request.ListingDesc, contact, request.RentalPropertyId, false, request.MonthlyRent, request.Notes, DateTime.Now, DateTime.Now); var listingProeprty = _context.RentalProperty.FirstOrDefault(p => p.Id == request.RentalPropertyId); await _context.AddAsync(listing); var addedListing = new PropertyListingListViewModel(); addedListing.Title = request.Title; addedListing.ListingDesc = request.ListingDesc; addedListing.MonthlyRent = request.MonthlyRent; addedListing.ListingNote = request.Notes; addedListing.IsActive = false; // this represents the status of listing: published or not addedListing.PropertyName = listingProeprty.PropertyName; addedListing.PropertyType = listingProeprty.PropertyType; addedListing.PropertyBuildYear = listingProeprty.PropertyBuildYear; addedListing.IsShared = listingProeprty.IsShared; addedListing.IsBasementSuite = listingProeprty.IsBasementSuite; addedListing.Created = DateTime.Now; addedListing.Updated = DateTime.Now; try { await _context.SaveChangesAsync(); // Send message to message queue addedListing.Id = listing.Id; } catch (Exception ex) { throw ex; } return(addedListing); //throw new NotImplementedException(); }
public PropertyListing(string title, string listingDesc, ListingContact contact, int rentalPropertyId, bool isActive, decimal rent, string notes, DateTime added, DateTime updated) { Title = title; ListingDesc = listingDesc; Contact = contact; RentalPropertyId = rentalPropertyId; IsActive = isActive; MonthlyRent = rent; Note = notes; Created = added; Modified = updated; }
public PropertyListing Update( PropertyListing listing, string title, string listingDesc, ListingContact contact, decimal rent, bool isActive, // add to update the publishing status -- may refactor in the future string notes, DateTime updated) { Title = title; ListingDesc = listingDesc; Contact = contact; MonthlyRent = rent; Note = notes; IsActive = isActive; // add to update the publishing status -- may refactor in the future Modified = updated; return(listing); }
/// <summary> /// This update listing process only catches published/listed event so that Asset microservice can upate the property status from "UnSet" to "Vacant" or vice verser /// </summary> /// <param name="request"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public async Task <PropertyListingUpdateViewModel> Handle(UpdatePropertyListingCommand request, CancellationToken cancellationToken) { var listing = _context.PropertyListing .Include(r => r.RentalProperty) .ThenInclude(p => p.PropertyImg) .FirstOrDefault(i => i.Id == request.Id); //.ThenInclude(m => m.PropertyImg.ToList()) var contact = new ListingContact(request.ContactName, request.ContactTel, request.ContactEmail, request.ContactSMS, request.ContactOthers); var allImgs = _context.PropertyImg.ToList(); // Get all property images var rentalProperty = listing.RentalProperty; var originalStatus = listing.IsActive; var updated = listing.Update(listing, request.Title, request.ListingDesc, contact, request.MonthlyRent, request.isActive, request.Note, DateTime.Now); _context.PropertyListing.Update(updated); var updatedList = new PropertyListingUpdateViewModel(); // need to include all images? updatedList.Id = updated.Id; updatedList.RentalPropertyId = updated.RentalPropertyId; updatedList.Title = updated.Title; updatedList.ListingDesc = updated.ListingDesc; updatedList.MonthlyRent = updated.MonthlyRent; updatedList.Note = updated.Note; updatedList.IsActive = updated.IsActive; updatedList.ContactName = updated.Contact.ContactName; updatedList.ContactEmail = updated.Contact.ContactEmail; updatedList.ContactTel = updated.Contact.ContactTel; updatedList.ContactSMS = updated.Contact.ContactSMS; updatedList.ContactOthers = updated.Contact.ContactOthers; updatedList.Created = updated.Created; updatedList.Modified = updated.Modified; updatedList.Updated = updated.Modified; updatedList.RentalProperty = listing.RentalProperty; updatedList.PropertyName = listing.RentalProperty.PropertyName; updatedList.PropertyImgs = allImgs; updatedList.Contact = contact; //updatedList.PropertyImgs = allImgs.ToList(); // Update rental property status ListingStatus status; if (request.isActive == true) { status = (ListingStatus)Enum.Parse(typeof(ListingStatus), "Listed"); } else { status = (ListingStatus)Enum.Parse(typeof(ListingStatus), "NotSet"); } rentalProperty.StatusUpdate(status); try { await _context.SaveChangesAsync(); // Only send message to the message queue for status change, i.e. isActive from true to false or vice versa if (originalStatus != request.isActive) { RentalPropertyStatusChangeEvent e = new RentalPropertyStatusChangeEvent(new Guid(), listing.RentalProperty.OriginalId, status.ToString()); try { await _messagePublisher.PublishMessageAsync(e.MessageType, e, "status_updated"); // publishing the message Log.Information("Message {MessageType} with Id {MessageId} has been published successfully: Proeprty status change.", e.MessageType, e.MessageId); } catch (Exception ex) { Log.Error(ex, "Error while publishing {MessageType} message with id {MessageId}. Proeprty status change.", e.MessageType, e.MessageId); throw ex; } } } catch (Exception ex) { Log.Information("Error {Message} saving to database!", ex.Message); throw ex; } return(updatedList); //throw new NotImplementedException(); }