-
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.
- Loading branch information
n.bitounis
committed
May 1, 2019
1 parent
ac745ef
commit 7e9a359
Showing
22 changed files
with
406 additions
and
54 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
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,21 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace xe.bit.property.core.Ads | ||
{ | ||
public class BaseResidenceAd : BaseAd | ||
{ | ||
public virtual string RefId { get; set; } | ||
public virtual Geo Geo { get; } = new Geo(); | ||
public virtual List<Asset> Assets { get; } = new List<Asset>(); | ||
|
||
public void AddAsset(Asset asset) | ||
{ | ||
Assets.Add(asset); | ||
} | ||
|
||
public void ClearAssets() | ||
{ | ||
Assets.Clear(); | ||
} | ||
} | ||
} |
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,36 @@ | ||
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.Validators; | ||
|
||
namespace xe.bit.property.core.Ads | ||
{ | ||
public class ParkingAd : BaseAd | ||
{ | ||
public override ItemType AdType { get; protected set; } = ItemType.re_parking; | ||
public virtual decimal? Area { get; set; } | ||
public virtual Usage? Usage { get; set; } | ||
public virtual int? Slots { get; set; } | ||
public virtual ParkingLevel? Level { get; set; } | ||
public virtual bool? HasElectricDoor { get; set; } | ||
public virtual bool? HasAlarm { get; set; } | ||
public virtual bool? IsAgentAccepted { get; set; } | ||
public override IAddSerializer Serializer { get; } = new XmlParkingAdSerializer(); | ||
|
||
public override ValidationResult Validate() | ||
{ | ||
return new ParkingAdValidator().Validate(this); | ||
} | ||
|
||
public override string Serialize() | ||
{ | ||
return Serializer.Serialize(this); | ||
} | ||
|
||
public override string Serialize(bool skipAssets) | ||
{ | ||
return Serializer.Serialize(this); | ||
} | ||
} | ||
} |
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
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
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
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
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
46 changes: 46 additions & 0 deletions
46
Projects/xe.bit.property.core/Serializers/XmlParkingAdSerializer.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,46 @@ | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Text; | ||
using System.Xml; | ||
using xe.bit.property.core.Ads; | ||
using xe.bit.property.core.Utility.Xml; | ||
|
||
namespace xe.bit.property.core.Serializers | ||
{ | ||
public class XmlParkingAdSerializer : XmlBaseSerializer | ||
{ | ||
public override string Serialize(BaseAd ad) | ||
{ | ||
using (var ms = new MemoryStream()) | ||
using (var writer = XmlWriter.Create(ms, new XmlWriterSettings { ConformanceLevel = ConformanceLevel.Fragment, OmitXmlDeclaration = true, Encoding = new UTF8Encoding(false) })) | ||
{ | ||
SerializeParking((ParkingAd)ad, writer); | ||
|
||
writer.CloseElement(); | ||
|
||
writer.Flush(); | ||
writer.Close(); | ||
return new UTF8Encoding(false).GetString(ms.ToArray()); | ||
} | ||
} | ||
|
||
public override string Serialize(BaseAd ad, bool skipAssets) | ||
{ | ||
return Serialize(ad); | ||
} | ||
|
||
private void SerializeParking(ParkingAd ad, XmlWriter writer) | ||
{ | ||
writer | ||
.ElementWithAttributes("Item", new Dictionary<string, string> { { "type", ad.AdType.ToString() }}) | ||
.NewLine() | ||
.Field("Item.area", ad.Area) | ||
.Field("Item.usage", ad.Usage) | ||
.Field("Item.slots", ad.Slots) | ||
.Field("Item.level", ad.Level) | ||
.Field("Item.hasElectricDoor", ad.HasElectricDoor) | ||
.Field("Item.hasAlarm", ad.HasAlarm) | ||
.Field("Item.isAgentAccepted", ad.IsAgentAccepted); | ||
} | ||
} | ||
} |
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
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
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
27 changes: 27 additions & 0 deletions
27
Projects/xe.bit.property.core/Validators/BaseResidenceAdValidator.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,27 @@ | ||
using FluentValidation; | ||
using xe.bit.property.core.Ads; | ||
using xe.bit.property.core.Errors; | ||
|
||
namespace xe.bit.property.core.Validators | ||
{ | ||
public class BaseResidenceAdValidator : AbstractValidator<BaseResidenceAd> | ||
{ | ||
public BaseResidenceAdValidator() | ||
{ | ||
RuleFor(ad => ad.RefId) | ||
.Cascade(CascadeMode.StopOnFirstFailure) | ||
.NotNull().WithMessage(Messages.RefIdCannotBeNullOrEmpty) | ||
.NotEmpty().WithMessage(Messages.RefIdCannotBeNullOrEmpty); | ||
|
||
RuleFor(ad => ad.OwnerId) | ||
.Cascade(CascadeMode.StopOnFirstFailure) | ||
.NotNull().WithMessage(Messages.OwnerIdCannotBeNullOrEmpty) | ||
.NotEmpty().WithMessage(Messages.OwnerIdCannotBeNullOrEmpty); | ||
|
||
RuleFor(ad => ad.MajorPhone) | ||
.Cascade(CascadeMode.StopOnFirstFailure) | ||
.NotNull().WithMessage(Messages.MajorPhoneCannotBeNullOrEmpty) | ||
.NotEmpty().WithMessage(Messages.MajorPhoneCannotBeNullOrEmpty); | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
Projects/xe.bit.property.core/Validators/ParkingAdValidator.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,25 @@ | ||
using FluentValidation; | ||
using xe.bit.property.core.Ads; | ||
using xe.bit.property.core.Errors; | ||
using xe.bit.property.core.Lookups; | ||
|
||
namespace xe.bit.property.core.Validators | ||
{ | ||
public class ParkingAdValidator : AbstractValidator<ParkingAd> | ||
{ | ||
public ParkingAdValidator() | ||
{ | ||
RuleFor(x => x.AdType) | ||
.Equal(ItemType.re_parking) | ||
.WithMessage(Messages.ItemTypeMustBeParking); | ||
|
||
RuleFor(x => x.Area.HasValue) | ||
.Equal(true) | ||
.WithMessage(Messages.ParkingAreaMustHaveValue); | ||
|
||
RuleFor(x => x.Level.HasValue) | ||
.Equal(true) | ||
.WithMessage(Messages.ParkingLevelMustHaveValue); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.