public static TenantReturnModel MakeReturnTenant(Models.Tenant dbTenant, Models.Property dbProperty) { return(new TenantReturnModel { Name = dbTenant.names, UserId = dbTenant.userId, Username = dbTenant.username, propertyId = dbProperty.propertyId, leaseId = dbTenant.leaseId, Property = new MiniProperty { Address = dbProperty.address, PropertyId = dbProperty.propertyId, TotalLandLords = dbProperty.landLordProperties.Count, TotalManagers = dbProperty.managers.Count, TotalTenants = dbProperty.tenants.Count }, // TODO : Add more tenant fields gender = dbTenant.gender, idNumber = dbTenant.idNumber, cellNumber = dbTenant.cellNumber, createdAt = dbTenant.createdAt, profilePicture = dbTenant.profilePicture, deposit = dbTenant.deposit, rentAmount = dbTenant.rentAmount, Role = dbTenant.role, }); }
public IActionResult AddProperty([FromBody] Models.Property property) { if (!ModelState.IsValid) { throw new Exception("Nieprawidłowe dane wejściowe"); } var owner = _ownerRepository.GetOwner(property.OwnerId); if (owner == null) { return(NotFound("Nie odnaleziono")); } var address = _addressRepository.GetAddress(property.AddressId); if (address == null) { return(NotFound("Nie odnaleziono")); } _propertyRepository.AddProperty(property, address, owner); return(new JsonResult(property.Id)); }
public static object GetConvertedValue <T>(T obj, PropertyInfo propertyInfo, Models.Property property) { var v = propertyInfo.GetValue(obj); switch (property.ConverterEnum) { case ValueConverterEnum.None: case ValueConverterEnum.EnumToString: return(v); case ValueConverterEnum.BoolToString: return(boolToString.ConvertToProviderExpression.Compile()((bool)v)); case ValueConverterEnum.DateTimeToTicks: return(dateTimeToTicks.ConvertToProviderExpression.Compile()((DateTime)v)); case ValueConverterEnum.BoolToZeroOne: return(boolToZeroOne.ConvertToProviderExpression.Compile()((bool)v)); case ValueConverterEnum.UriToString: return(uriToString.ConvertToProviderExpression.Compile()((Uri)v)); default: throw new NotSupportedException($"Not Supported Converter: {property.ConverterEnum}."); } }
public void HandleShouldAddViewingAppointment() { var property = new Models.Property { Description = "Test Property", IsListedForSale = false }; _properties.Find(1).Returns(property); var appointmentTime = new DateTime(2017, 4, 30, 12, 0, 0); var command = new MakeViewingAppointmentCommand(); command.PropertyId = 1; command.AppointmentTime = appointmentTime; command.BuyerUserId = "Test Buyer"; _handler.Handle(command); _context.Properties.Received(1).Find(1); _context.Received(1).SaveChanges(); Assert.True(property.ViewingAppointments.Count == 1); Assert.True(property.ViewingAppointments.First().AppointmentTime == appointmentTime); Assert.True(property.ViewingAppointments.First().BuyerUserId == "Test Buyer"); }
public void HandleShouldAddAppointment() { // Arrange var command = new BookAppointmentCommand { PropertyId = 1, BuyerUserId = "111", AppointmentDateTime = DateTime.Now, }; var property = new Models.Property { Description = "Test Property", IsListedForSale = true, Id = 1, }; _properties.Find(1).Returns(property); // Act _handler.Handle(command); // Assert _context.Properties.Received(1).Find(1); _context.Received(1).SaveChanges(); Assert.AreNotEqual(property.Appointments, null); }
public void HandleShouldAddOffer() { // Arrange var command = new MakeOfferCommand { PropertyId = 1, BuyerUserId = "111", Offer = 1000, }; var property = new Models.Property { Description = "Test Property", IsListedForSale = true, Id = 1, }; _properties.Find(1).Returns(property); // Act _handler.Handle(command); // Assert _context.Properties.Received(1).Find(1); _context.Received(1).SaveChanges(); Assert.AreNotEqual(property.Offers, null); }
public void HandleShouldUpdatePropertyToBeListedForSale() { // Arrange var command = new ListPropertyCommand { PropertyId = 1 }; var property = new Models.Property { Description = "Test Property", IsListedForSale = false }; _properties.Find(1).Returns(property); // Act // WHEN the property is listed for sale _handler.Handle(command); // Assert _context.Properties.Received(1).Find(1); // AND the changes are saved _context.Received(1).SaveChanges(); // THEN the property is listed for sale Assert.True(property.IsListedForSale); }
public ResponseModel <ManagerReturnModel> GetManagerById(string manager_id) { try { var lookupManager = dbcontext.managers.FirstOrDefault(u => u.userId == manager_id); if (lookupManager == null) { throw new Exception("User not found"); } Models.Property dbProperty = dbcontext.properties.FirstOrDefault(u => u.propertyId == lookupManager.propertyId); if (dbProperty == null) { throw new Exception("This user is not linked to any property...."); } return(new ResponseModel <ManagerReturnModel> { data = Converter.MakeReturnManager(lookupManager, dbProperty), message = "success", status = true }); } catch (Exception err) { return(new ResponseModel <ManagerReturnModel> { data = null, message = "An error has occured " + err.Message, status = false }); } }
public ResponseModel <TenantReturnModel> GetTenantById(string tenant_id) { try { //Look tenant by id Models.Tenant lookupTenant = dbcontext.tenants.FirstOrDefault(u => u.userId == tenant_id); if (lookupTenant == null) { throw new Exception("User not found"); } Models.Property dbProperty = dbcontext.properties.FirstOrDefault(u => u.propertyId == lookupTenant.propertyId); if (dbProperty == null) { throw new Exception("This user is not linked to any property...."); } return(new ResponseModel <TenantReturnModel> { data = Converter.MakeReturnTenant(lookupTenant, dbProperty), message = "success", status = true }); } catch (Exception err) { return(new ResponseModel <TenantReturnModel> { data = null, message = "An error has occured" + err.Message, status = false }); } }
public static PropertyReturnModel MakeReturnProperty(Models.Property dbProperty) { double totalMonthlyIncome = 0; Boolean PropertyIsfull = false; dbProperty.tenants.Select(v => v.rentAmount).ToList().ForEach(amount => { totalMonthlyIncome += amount; }); var RoomsOccupied = dbProperty.tenants.Select(v => MakeReturnTenant(v, dbProperty)).ToList().Count; var availableRooms = dbProperty.rooms - RoomsOccupied; if (availableRooms <= 0) { PropertyIsfull = true; } else { PropertyIsfull = false; }; return(new PropertyReturnModel { rooms = dbProperty.rooms, RoomsOccupied = RoomsOccupied, availableRooms = availableRooms, isFull = PropertyIsfull, MonthlyIncome = totalMonthlyIncome, Address = dbProperty.address, LandLords = dbProperty.landLordProperties.Select(v => MakeReturnLandlord(v.LandLord)).ToList(), Managers = dbProperty.managers.Select(v => MakeReturnManager(v, dbProperty)).ToList(), Tenants = dbProperty.tenants.Select(v => MakeReturnTenant(v, dbProperty)).ToList(), Leases = dbProperty.Leases.Select(v => MakeReturnLease(v)).ToList(), Complaints = dbProperty.Complaints.Select(v => MakeReturnComplaint(v)).ToList(), }); }
public async Task <BaseResponse> CreateProduct(CreateProductRequest request, int UserID, int CompanyID) { BaseResponse response = new BaseResponse(); Models.Product product = null; Models.Company company = null; Models.Category category = null; Models.Property property = null; category = request.CategoryID.HasValue ? await this.context.Categories.Where(a => a.ID.Equals(request.CategoryID)).FirstOrDefaultAsync() : null; try { await context.Database.BeginTransactionAsync(); product = new Models.Product(); product.Name = request.Name; product.Barcode = request.Barcode; product.Price = request.Price; product.TaxRate = request.TaxRate; product.TotalPrice = Decimal.Add(product.Price, Decimal.Multiply(product.Price, Decimal.Divide(product.TaxRate, 100))); product.CategoryID = category != null ? (int?)category.ID : null; product.CompanyID = CompanyID; context.Products.Add(product); await context.SaveChangesAsync(); if (request.Properties != null && request.Properties.Count > 0) { foreach (dto.Models.Property dtoProp in request.Properties) { property = new Models.Property(); property.Name = dtoProp.Name; property.ProductID = product.ID; property.Value = dtoProp.Value; property.Type = dtoProp.Type != null?sharedRepository.PropertyTypeConverter(dtoProp.Type) : Models.PropertyType.STRING; context.Properties.Add(property); await context.SaveChangesAsync(); } } context.Database.CommitTransaction(); response.Result.Status = true; response.Result.Message = "Operation successful"; } catch (Exception) { context.Database.RollbackTransaction(); } return(response); }
public IActionResult Updateproperty([FromBody] Models.Property property) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _propertyRepository.EditProperty(property); return(new JsonResult(property.Id)); }
private static PropertyViewModel MapViewModel(Models.Property property) { return(new PropertyViewModel { Id = property.Id, StreetName = property.StreetName, Description = property.Description, NumberOfBedrooms = property.NumberOfBedrooms, PropertyType = property.PropertyType }); }
public static PropertyViewModel MapViewModel(Models.Property property) { return(new PropertyViewModel { Id = property.Id, StreetName = property.StreetName, Description = property.Description, NumberOfBedrooms = property.NumberOfBedrooms, PropertyType = property.PropertyType, SellerUserId = property.SellerUserId, }); }
private static PropertyViewModel MapViewModel(Models.Property property, string currentUserId) { return(new PropertyViewModel { Id = property.Id, StreetName = property.StreetName, Description = property.Description, NumberOfBedrooms = property.NumberOfBedrooms, PropertyType = property.PropertyType, IsCurrentUserOfferAccepted = property.Offers .Any(o => o.Status == OfferStatus.Accepted && o.BuyerId == currentUserId) }); }
private PropertyViewModel MapViewModel(Models.Property property) { var vm = new PropertyViewModel { Id = property.Id, StreetName = property.StreetName, Description = property.Description, NumberOfBedrooms = property.NumberOfBedrooms, PropertyType = property.PropertyType, Offers = property.Offers?.Where(o => o.OfferingUserId == CurrentUserId).ToList(), Viewings = property.Viewings?.Where(v => v.BuyerId == CurrentUserId).ToList() }; return(vm); }
protected bool SkipPropertyForUpdate(Models.Property property, IEnumerable <KeyProperty> keyColumns) { if (keyColumns.Any(key => ( (key.PropertyInfo != default && property.PropertyInfo != default && key.PropertyInfo.Name == property.PropertyInfo.Name) || (key.PropertyInfo == default && property.PropertyInfo == default && key.ColumnName == property.ColumnName) ) && property.Prefix.IsNullOrEmpty())) { return(true); } return(false); }
public void Handle(CreatePropertyCommand command) { var property = new Models.Property { PropertyType = command.PropertyType, StreetName = command.StreetName, Description = command.Description, NumberOfBedrooms = command.NumberOfBedrooms }; property.SellerUserId = command.SellerUserId; this._context.Properties.Add(property); this._context.SaveChanges(); }
public void Handle(CreatePropertyCommand command) { var property = new Models.Property { PropertyType = command.PropertyType, StreetName = command.StreetName, Description = command.Description, NumberOfBedrooms = command.NumberOfBedrooms, IsListedForSale = true //Bug: Defaulting Property for sale to false }; property.SellerUserId = command.SellerUserId; _context.Properties.Add(property); _context.SaveChanges(); }
private static PropertyViewModel MapViewModel(Models.Property property, string userId) { var offers = property.Offers?.Where(x => x.BuyerUserId == userId).FirstOrDefault(); var viewing = property.Viewings?.Where(x => x.BuyerUserId == userId).FirstOrDefault(); return(new PropertyViewModel { Id = property.Id, StreetName = property.StreetName, Description = property.Description, NumberOfBedrooms = property.NumberOfBedrooms, PropertyType = property.PropertyType, OfferStatus = offers?.Status.ToString(), HasViewing = viewing != null ? true : false, ViewingDateTime = viewing?.BookingTime.ToShortDateString() }); }
public async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } var ads = from p in Context.AdsBasicInfo select p; Property = await Context.Property.FirstOrDefaultAsync(m => m.PropertyID == id); AdsList = await ads.ToListAsync(); if (Property == null) { return(NotFound()); } return(Page()); }
/// <summary> /// Gets the properties. /// </summary> /// <param name="type">The type.</param> /// <returns></returns> private static List <Models.Property> GetProperties(Type type) { List <Models.Property> props = new List <Models.Property>(); type.GetProperties().ToList().ForEach((n) => { var prop = new Models.Property { Name = n.Name, ReadOnly = (n.CanWrite ? false : true), TypeName = Regex.Replace(n.PropertyType.Name, TypingSetter, "[]"), Type = n.PropertyType }; prop.Documentation = DocumentService.GetPropertyDocumentation(type.Namespace, type.Name, prop); props.Add(prop); }); return(props); }
private static PropertyViewModel MapViewModel(Models.Property property) { var offer = property.Offers; int?offerStatus = null; if (offer != null && offer.Count != 0) { offerStatus = (int?)offer.OrderByDescending(x => x.CreatedAt).FirstOrDefault().Status; } return(new PropertyViewModel { Id = property.Id, StreetName = property.StreetName, Description = property.Description, NumberOfBedrooms = property.NumberOfBedrooms, PropertyType = property.PropertyType, OfferStatus = offerStatus }); }
private static PropertyViewModel MapViewModel(Models.Property property) { var userOffer = (property.Offers == null ? null : property.Offers.Where(o => o.OfferedByUserId == _currentUser).FirstOrDefault()); var userViewing = (property.Viewings == null ? null : property.Viewings.Where(o => o.RequestUserId == _currentUser).FirstOrDefault()); return(new PropertyViewModel { Id = property.Id, StreetName = property.StreetName, Description = property.Description, NumberOfBedrooms = property.NumberOfBedrooms, PropertyType = property.PropertyType, IsOfferedByLoggedInUser = (userOffer != null), OfferAmount = (userOffer == null ? 0 : userOffer.Amount), IsOfferAcceptedForLoggedInUser = (userOffer != null && userOffer.Status == OfferStatus.Accepted), AcceptedDateTime = (userOffer == null ? default(DateTime) : userOffer.UpdatedAt), IsViewingByLoggedInUser = (userViewing != null), ViewingDate = (userViewing == null ? default(DateTime) : userViewing.RequestDate), }); }
private static PropertyViewModel MapViewModel(Models.Property property) { var offers = new List <Common.OfferViewModel>(); foreach (var o in property.Offers) { offers.Add(new Common.OfferViewModel { Amount = o.Amount, CreatedAt = o.CreatedAt, Id = o.Id, Status = o.Status.ToString(), OfferedBy = o.OfferedBy }); } return(new PropertyViewModel { Id = property.Id, StreetName = property.StreetName, Description = property.Description, NumberOfBedrooms = property.NumberOfBedrooms, PropertyType = property.PropertyType, Offers = offers }); }
public void HandleShouldAddPropertyViewingForCorrectBuyer() { // Arrange const string buyerUserId = "12345"; var command = new ContactAgentCommand { PropertyId = 1, BuyerUserId = buyerUserId }; var property = new Models.Property { Id = 1, Description = "Test Property" }; this._properties.Find(1).Returns(property); // Act this._handler.Handle(command); // Assert Assert.IsTrue(property.PropertyViewings.First().BuyerUserId == buyerUserId); }
public void Handle(CreatePropertyCommand command) { var property = new Models.Property { PropertyType = command.PropertyType, StreetName = command.StreetName, Description = command.Description, NumberOfBedrooms = command.NumberOfBedrooms, Availability = new Availability { StartDate = command.Availability.StartDate, StartTime = command.Availability.StartTime, EndTime = command.Availability.EndTime, ViewingDuration = command.Availability.ViewingDuration }, SellerUserId = command.SellerUserId, }; _context.Properties.Add(property); _context.SaveChanges(); }
public async Task <IActionResult> OnPostAsync() { var personService = new PersonService(); var person = await personService.FindByEmailAsync(User.Identity.Name); Description = this.Request.Form["Description"]; //Place to put data into Models.Property property = new Models.Property { Id = Id, Name = Name, Description = Description, Bedrooms = Bedrooms, RentPerMonth = RentPerMonth, LandlordID = person.Id, LandlordName = person.FullName, LandlordNumber = person.PhoneNumber, ApprovalStatus = Models.Property.ApprovalEnum.Pending, ApprovalComment = "" }; if (Image != null) { using (var stream = new MemoryStream()) { await Image.CopyToAsync(stream); property.Image = stream.ToArray(); property.ImageContentType = Image.ContentType; } } await propertyService.SaveAsync(property); return(RedirectToPage("/Property/List")); }
public void AddViewingForProperty() { // Arrange var command = new BookViewingCommand { PropertyId = 1 }; var property = new Models.Property { Description = "Test Property", }; _properties.Find(1).Returns(property); // Act _handler.Handle(command); // Assert _context.Properties.Received(1).Find(1); _context.Received(1).SaveChanges(); Assert.True(property.Viewings.Any()); }
public static ManagerReturnModel MakeReturnManager(Models.Manager dbManager, Models.Property dbProperty) { return(new ManagerReturnModel { Name = dbManager.names, UserId = dbManager.userId, Username = dbManager.username, Salary = dbManager.salary, Role = dbManager.role, Property = new MiniProperty { Address = dbProperty.address, rooms = dbProperty.rooms, country = dbProperty.country, PropertyId = dbProperty.propertyId, TotalLandLords = dbProperty.landLordProperties.Count, TotalManagers = dbProperty.managers.Count, TotalTenants = dbProperty.tenants.Count } // Add more manager fields }); }