-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Holiday residence ads are now supported.
- Loading branch information
n.bitounis
committed
Apr 20, 2019
1 parent
ca075b0
commit 981fca1
Showing
11 changed files
with
260 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using FluentValidation.Results; | ||
using xe.bit.property.core.Lookups; | ||
using xe.bit.property.core.Serializers; | ||
using xe.bit.property.core.Serializers.Interfaces; | ||
using xe.bit.property.core.Utility; | ||
using xe.bit.property.core.Validators; | ||
|
||
namespace xe.bit.property.core.Ads | ||
{ | ||
public class ResidenceAdHoliday : ResidenceAd | ||
{ | ||
public override ItemType AdType { get; protected set; } = Lookups.ItemType.re_residence_hol; | ||
public virtual string Activity { get; set; } | ||
public virtual string Utilities { get; set; } | ||
public virtual string ProximityTo { get; set; } | ||
|
||
public override IAddSerializer Serializer { get; } = new XmlResidenceAdHolidaySerializer(); | ||
|
||
public override ValidationResult Validate() | ||
{ | ||
return ValidationChain.ChainValidators(this, new ResidenceAdHolidayValidator().Validate(this)); | ||
} | ||
|
||
public override string Serialize(bool skipAssets) | ||
{ | ||
return Serializer.Serialize(this, skipAssets); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
Projects/xe.bit.property.core/Serializers/XmlPackageSerializer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
Projects/xe.bit.property.core/Serializers/XmlResidenceAdHolidaySerializer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System.Xml; | ||
using xe.bit.property.core.Ads; | ||
using xe.bit.property.core.Utility.Xml; | ||
|
||
namespace xe.bit.property.core.Serializers | ||
{ | ||
public class XmlResidenceAdHolidaySerializer : XmlResidenceAdSerializer | ||
{ | ||
protected override void SerializeAdditional(BaseAd ad, XmlWriter writer) | ||
{ | ||
var r = (ResidenceAdHoliday)ad; | ||
writer | ||
.Field("Item.activity", r.Activity) | ||
.Field("Item.utilities", r.Utilities) | ||
.Field("Item.proximityTo", r.ProximityTo); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
Projects/xe.bit.property.core/Validators/ResidenceAdHolidayValidator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using FluentValidation; | ||
using xe.bit.property.core.Errors; | ||
using xe.bit.property.core.Lookups; | ||
|
||
namespace xe.bit.property.core.Validators | ||
{ | ||
public class ResidenceAdHolidayValidator : ResidenceValidator | ||
{ | ||
public ResidenceAdHolidayValidator() | ||
{ | ||
RuleFor(ad => ad.AdType) | ||
.Equal(ItemType.re_residence_hol) | ||
.WithMessage(Messages.AddTypeMustBeResidenceHoliday); | ||
|
||
AddOtherRules(); | ||
} | ||
} | ||
} |
104 changes: 3 additions & 101 deletions
104
Projects/xe.bit.property.core/Validators/ResidenceAdValidator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,116 +1,18 @@ | ||
using System; | ||
using FluentValidation; | ||
using xe.bit.property.core.Ads; | ||
using FluentValidation; | ||
using xe.bit.property.core.Errors; | ||
using xe.bit.property.core.Lookups; | ||
|
||
namespace xe.bit.property.core.Validators | ||
{ | ||
public class ResidenceAdValidator : AbstractValidator<ResidenceAd> | ||
public class ResidenceAdValidator : ResidenceValidator | ||
{ | ||
public ResidenceAdValidator() | ||
{ | ||
RuleFor(ad => ad.AdType) | ||
.Equal(ItemType.re_residence) | ||
.WithMessage(Messages.AddTypeMustBeResidence); | ||
|
||
RuleFor(ad => ad.ItemType == ResidenceItemType.APARTMENT && !ad.SubType.HasValue) | ||
.Equal(false) | ||
.WithMessage(Messages.ResidenceSubTypeMustHaveValue); | ||
|
||
RuleFor(ad => ad.ItemType != ResidenceItemType.APARTMENT && ad.SubType.HasValue) | ||
.Equal(false) | ||
.WithMessage(Messages.ResidenceSubTypeMustBeNull); | ||
|
||
RuleFor(ad => ad.Area) | ||
.NotNull().WithMessage(Messages.AreaMustHaveValue); | ||
|
||
When(ad => ad.Area.HasValue, () => | ||
{ | ||
RuleFor(ad => ad.Area.Value) | ||
.GreaterThan(0).WithMessage(Messages.AreaMustHavePositiveValue); | ||
}); | ||
|
||
RuleFor(ad => ad.Level) | ||
.NotNull() | ||
.WithMessage(Messages.LevelMustHaveValue); | ||
|
||
RuleFor(ad => ad.Condition) | ||
.NotNull() | ||
.WithMessage(Messages.ConditionMustHaveValue); | ||
|
||
RuleFor(ad => ad.ConstructionYear) | ||
.GreaterThan(1900).WithMessage(Messages.ConstructionYearOutOfBounds) | ||
.LessThanOrEqualTo(DateTime.UtcNow.Year).WithMessage(Messages.ConstructionYearOutOfBounds); | ||
|
||
When(ad => ad.RefurbishmentYear.HasValue, () => | ||
{ | ||
RuleFor(ad => ad.RefurbishmentYear.Value) | ||
.GreaterThan(1900).WithMessage(Messages.RefurbishmentYearOutOfBounds) | ||
.LessThanOrEqualTo(DateTime.UtcNow.Year).WithMessage(Messages.RefurbishmentYearOutOfBounds); | ||
}); | ||
|
||
RuleFor(ad => ad.Bedrooms - ad.MasterBedrooms) | ||
.GreaterThan(0) | ||
.WithMessage(Messages.BedroomsOutOfBound); | ||
|
||
RuleFor(ad => ComplexFlagCheck(ad.HasStorage, ad.StorageArea.HasValue)) | ||
.Equal(false) | ||
.WithMessage(Messages.HasStorageConstraint); | ||
|
||
RuleFor(ad => ComplexFlagCheck(ad.HasSemiOpenSpaces, ad.SemiOpenSpacesArea.HasValue)) | ||
.Equal(false) | ||
.WithMessage(Messages.HasSemiOpenSpacesConstraint); | ||
|
||
RuleFor(ad => ComplexFlagCheck(ad.HasGarden, ad.GardenArea.HasValue)) | ||
.Equal(false) | ||
.WithMessage(Messages.HasGardenConstraint); | ||
|
||
RuleFor(ad => ComplexFlagCheck(ad.HasTerraceArea, ad.TerraceArea.HasValue)) | ||
.Equal(false) | ||
.WithMessage(Messages.HasTerraceConstraint); | ||
|
||
RuleFor(ad => (ad.Floors.HasValue ^ ad.FloorsArea.HasValue) && (ad.Floors.HasValue && ad.Floors != 0 && !ad.FloorsArea.HasValue)) | ||
.Equal(false) | ||
.WithMessage(Messages.FloorsConstraint); | ||
|
||
RuleFor(ad => ComplexFlagCheck(ad.HasParking, ad.ParkingType.HasValue)) | ||
.Equal(false) | ||
.WithMessage(Messages.HasParkingConstraint); | ||
|
||
RuleFor(ad => ad.Geo) | ||
.Custom((geo, context) => | ||
{ | ||
new GeoValidator().Validate(geo, context); | ||
}); | ||
|
||
RuleFor(ad => ad.Assets) | ||
.Custom((assets, context) => | ||
{ | ||
new AssetsValidator().Validate(assets, context); | ||
}); | ||
} | ||
|
||
/// <summary> | ||
/// Checks valid conditions if a flag and a value are specified (for example, | ||
/// hasTerrace and TerraceArea). We want both these to have values, but if | ||
/// a flag is specified and is false, we do not care of the specified value | ||
/// (for example if hasTerrace has a value and is false, this is allowed). | ||
/// </summary> | ||
/// <returns></returns> | ||
private bool ComplexFlagCheck(bool? flag, bool hasValue) | ||
{ | ||
if (flag.HasValue && flag.Value == false && hasValue) | ||
{ | ||
return true; | ||
} | ||
|
||
if (!flag.HasValue && hasValue) | ||
{ | ||
return true; | ||
} | ||
|
||
return false; | ||
AddOtherRules(); | ||
} | ||
} | ||
} |
Oops, something went wrong.