public PropertyInfoDTO(RentalsInfo property) { Id = property.Id; PropertyName = property.Property.PropertyName; SellingPrice = property.Property.SellingPrice; RentalPrice = property.RentalPrice; RentalHirePeriodType = new RentalHirePeriodTypesInfoDTO(property.RentalHirePeriodType); AreaInSquareMeters = property.AreaInSquareMeters; AdditionalDescription = property.AdditionalDescription; CreatedOn = property.CreatedOn; Views = property.Views; PropertyLikesCount = property.PropertyLikes.Count; UnitType = new PropertyTypeInfoDTO(property.UnitType); Address = new AddressInfoDTO(property.Property.Address); PropertySeason = new PropertySeasonInfoDTO(property.Property.PropertySeason); Owner = new OwnerUserInfoDTO(property.Property.Owner); Agent = new AgentUsersInfoDTO(property.Property.Agent); IsActive = property.Property.IsActive; //PropertyRentals = new List<PropertyInfoDTO>(); }
//Work well public async Task <EditRentalInfoForPropertyViewModel> CreateRentalInfo(CreateRentalInfoViewModel rentalInfoToAddInProperty, string loggedUserId) { if (string.IsNullOrEmpty(loggedUserId)) { throw new ArgumentNullException(nameof(loggedUserId)); } var property = await unitOfWork.PropertiesRepository .Include(p => p.Images) .Where(p => p.Id == rentalInfoToAddInProperty.PropertyId) .FirstOrDefaultAsync() ?? throw new ContentNotFoundException("Имотът не е намерен!"); if (property.OwnerId != loggedUserId && property.AgentId != loggedUserId && !await userManager.IsInRoleAsync(loggedUserId, "Administrator")) { throw new NotAuthorizedException("Нямате право да създавате части в този имот!"); } var areaInSquareFt = rentalInfoToAddInProperty.Attributes .Where(a => a.Key == AttributesResolvers.AreaInSquareMetersAttribute) .Select(a => a.Value) .FirstOrDefault(); int?areaFinal = int.TryParse(areaInSquareFt, out var tempArea) ? tempArea : (int?)null; RentalsInfo rental = new RentalsInfo { PropertyId = rentalInfoToAddInProperty.PropertyId, RentalPrice = rentalInfoToAddInProperty.RentalPrice, RentalPricePeriodId = rentalInfoToAddInProperty.RentalPricePeriodId, UnitCount = rentalInfoToAddInProperty.UnitsCount, UnitTypeId = rentalInfoToAddInProperty.UnitTypeId, AdditionalDescription = rentalInfoToAddInProperty.AdditionalInfo, AreaInSquareMeters = areaFinal, Attributes = new HashSet <KeyValuePairs>(rentalInfoToAddInProperty.Attributes .Select(a => AttributesResolvers.AttributesResolver(a.Key, a.Value)) .ToList()), Extras = new HashSet <Extras>(_extrasManager.GetRentalExtras(rentalInfoToAddInProperty .RentalExtras .Where(e => e.IsChecked) .Select(e => e.ExtraId) .ToList())) }; unitOfWork.RentalsRepository.Add(rental); await unitOfWork.SaveAsync(); #region Notifications var creatorName = await unitOfWork.UsersRepository .Where(u => u.Id == property.AgentId) .Select(a => a.FirstName + " " + a.LastName) .FirstOrDefaultAsync(); var notificationToCreate = new NotificationCreateViewModel { NotificationTypeId = (int)NotificationType.Property, NotificationPicture = property.Images.Select(i => i.ImagePath).FirstOrDefault(), NotificationLink = "/properties/details?id=" + rental.Id + "&isrentsearching=True", NotificationText = creatorName + " добави имот: " + property.PropertyName }; await _notificationCreator.CreateGlobalNotification(notificationToCreate, property.AgentId); #endregion return(new EditRentalInfoForPropertyViewModel { UnitCount = rental.UnitCount, UnitTypeId = rental.UnitTypeId, // ReSharper disable once PossibleInvalidOperationException // Rental Create ViewModel guarantee for value here RentalPrice = (decimal)rental.RentalPrice, RentalInfoId = rental.Id, // ReSharper disable once PossibleInvalidOperationException RentalPricePeriodId = (int)rental.RentalPricePeriodId, AdditionalInfo = rental.AdditionalDescription, Attributes = rental.Attributes.Select(ra => new AttributesKeyValueViewModel { Key = ra.Key, Value = ra.Value }).ToList(), RentalExtras = rental.Extras.Select(re => new ExtraCheckBoxViewModel { ExtraId = re.ExtraId, ExtraName = re.ExtraName, IsChecked = true }).ToList() }); }
public List <string> Resolve(RentalsInfo source, DetailsPropertyViewModel destination, List <string> member, ResolutionContext context) { return(source.Property.Images?.Where(i => Math.Abs(i.ImageRatio - 1.5F) < 0.1).Select(i => i.ImagePath).ToList()); }