├── .gitattributes ├── .gitignore ├── 00. Framework ├── Framework.Domain │ ├── ApplicationServices │ │ └── ICommandHandler.cs │ ├── Class1.cs │ ├── Data │ │ ├── IAggregateStore.cs │ │ ├── IEventSource.cs │ │ └── IUnitOfWork.cs │ ├── Entieis │ │ ├── BaseAggregateRoot.cs │ │ └── BaseEntity.cs │ ├── Events │ │ └── IEvent.cs │ ├── Exceptions │ │ └── InvalidEntityStateException.cs │ ├── Framework.Domain.csproj │ └── ValueObjects │ │ └── BaseValueObject.cs └── Framework.Tools │ ├── Class1.cs │ ├── Enums │ └── EnumExtentions.cs │ └── Framework.Tools.csproj ├── 01. Core ├── Bazzar.Core.ApplicationServices │ ├── Advertisements │ │ └── CommandHandlers │ │ │ ├── CreateHandler.cs │ │ │ ├── RequestToPublishHandler.cs │ │ │ ├── SetTitleHandler.cs │ │ │ ├── UpdatePriceHandler.cs │ │ │ └── UpdateTextHandler.cs │ ├── Bazzar.Core.ApplicationServices.csproj │ ├── Class1.cs │ └── UserProfiles │ │ └── CommandHandlers │ │ ├── RegisterUserHandler.cs │ │ ├── UpdateUserDisplayNameHandler.cs │ │ ├── UpdateUserEmailHandler.cs │ │ └── UpdateUserNameHandler.cs └── Bazzar.Core.Domain │ ├── Advertisements │ ├── Commands │ │ ├── Create.cs │ │ ├── RequestToPublish.cs │ │ ├── SetTitle.cs │ │ ├── UpdatePrice.cs │ │ └── UpdateText.cs │ ├── Data │ │ ├── IAdvertisementQueryService.cs │ │ └── IAdvertisementsRepository.cs │ ├── Dtoes │ │ ├── AdvertisementDetail.cs │ │ └── AdvertisementSummary.cs │ ├── Entities │ │ ├── Advertisment.cs │ │ ├── AdvertismentState.cs │ │ └── Picture.cs │ ├── Events │ │ ├── AdvertismentCreated.cs │ │ ├── AdvertismentPictureResized.cs │ │ ├── AdvertismentPriceUpdated.cs │ │ ├── AdvertismentSentForReview.cs │ │ ├── AdvertismentTextUpdated.cs │ │ ├── AdvertismentTitleChanged.cs │ │ └── PictureAddedToAdvertisment.cs │ ├── Queries │ │ ├── GetActiveAdvertisement.cs │ │ ├── GetActiveAdvertisementList.cs │ │ └── GetAdvertisementForSpecificSeller.cs │ └── ValueObjects │ │ ├── AdvertismentText.cs │ │ ├── AdvertismentTitle.cs │ │ ├── PictureSize.cs │ │ ├── PictureUrl.cs │ │ ├── Price.cs │ │ ├── Rial.cs │ │ └── UserId.cs │ ├── Bazzar.Core.Domain.csproj │ ├── Shared │ └── ValueObjects │ │ └── Email.cs │ └── UserProfiles │ ├── Commands │ ├── RegisterUser.cs │ ├── UpdateUserDisplayName.cs │ ├── UpdateUserEmail.cs │ └── UpdateUserName.cs │ ├── Data │ └── IUserProfileRepository.cs │ ├── Entities │ └── UserProfile.cs │ ├── Events │ ├── UserDisplayNameUpdated.cs │ ├── UserEmailUpdated.cs │ ├── UserNameUpdated.cs │ └── UserRegistered.cs │ └── ValueObjects │ ├── DisplayName.cs │ ├── FirstName.cs │ └── LastName.cs ├── 02. Infrastructures └── Data │ ├── Bazzar.Infrastructures.Data.EventsSourcings │ ├── Bazzar.Infrastructures.Data.EventsSourcings.csproj │ ├── BazzarEventSource.cs │ └── Class1.cs │ ├── Bazzar.Infrastructures.Data.Fake │ ├── Advertisments │ │ └── FakeAdvertisementsRepository.cs │ ├── Bazzar.Infrastructures.Data.Fake.csproj │ └── Class1.cs │ └── Bazzar.Infrastructures.Data.SqlServer │ ├── AdvertismentDbContext.cs │ ├── AdvertismentUnitOfWork.cs │ ├── Advertisments │ ├── AdvertisementQueryService.cs │ ├── AdvertismentConfig.cs │ └── EfAdvertisementsRepository.cs │ ├── Bazzar.Infrastructures.Data.SqlServer.csproj │ ├── Migrations │ ├── 20191011115726_init.Designer.cs │ ├── 20191011115726_init.cs │ ├── 20191011121433_add-pictures.Designer.cs │ ├── 20191011121433_add-pictures.cs │ ├── 20191011123008_add-user-profile.Designer.cs │ ├── 20191011123008_add-user-profile.cs │ └── AdvertismentDbContextModelSnapshot.cs │ └── UserProfiles │ ├── EFUserProfileRepository.cs │ └── UserProfileConfig.cs ├── 03. EndPoints └── Bazzar.Endpoints.API │ ├── Bazzar.Endpoints.API.csproj │ ├── Controllers │ ├── AddvertismentController.cs │ ├── AddvertismentQueryController.cs │ └── UserProfileController.cs │ ├── Program.cs │ ├── Properties │ └── launchSettings.json │ ├── Services │ └── RequestHandler.cs │ ├── Startup.cs │ ├── appsettings.Development.json │ └── appsettings.json ├── BazzarClass.sln └── README.md /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Build results 17 | [Dd]ebug/ 18 | [Dd]ebugPublic/ 19 | [Rr]elease/ 20 | [Rr]eleases/ 21 | x64/ 22 | x86/ 23 | [Aa][Rr][Mm]/ 24 | [Aa][Rr][Mm]64/ 25 | bld/ 26 | [Bb]in/ 27 | [Oo]bj/ 28 | [Ll]og/ 29 | 30 | # Visual Studio 2015/2017 cache/options directory 31 | .vs/ 32 | # Uncomment if you have tasks that create the project's static files in wwwroot 33 | #wwwroot/ 34 | 35 | # Visual Studio 2017 auto generated files 36 | Generated\ Files/ 37 | 38 | # MSTest test Results 39 | [Tt]est[Rr]esult*/ 40 | [Bb]uild[Ll]og.* 41 | 42 | # NUNIT 43 | *.VisualState.xml 44 | TestResult.xml 45 | 46 | # Build Results of an ATL Project 47 | [Dd]ebugPS/ 48 | [Rr]eleasePS/ 49 | dlldata.c 50 | 51 | # Benchmark Results 52 | BenchmarkDotNet.Artifacts/ 53 | 54 | # .NET Core 55 | project.lock.json 56 | project.fragment.lock.json 57 | artifacts/ 58 | 59 | # StyleCop 60 | StyleCopReport.xml 61 | 62 | # Files built by Visual Studio 63 | *_i.c 64 | *_p.c 65 | *_h.h 66 | *.ilk 67 | *.meta 68 | *.obj 69 | *.iobj 70 | *.pch 71 | *.pdb 72 | *.ipdb 73 | *.pgc 74 | *.pgd 75 | *.rsp 76 | *.sbr 77 | *.tlb 78 | *.tli 79 | *.tlh 80 | *.tmp 81 | *.tmp_proj 82 | *_wpftmp.csproj 83 | *.log 84 | *.vspscc 85 | *.vssscc 86 | .builds 87 | *.pidb 88 | *.svclog 89 | *.scc 90 | 91 | # Chutzpah Test files 92 | _Chutzpah* 93 | 94 | # Visual C++ cache files 95 | ipch/ 96 | *.aps 97 | *.ncb 98 | *.opendb 99 | *.opensdf 100 | *.sdf 101 | *.cachefile 102 | *.VC.db 103 | *.VC.VC.opendb 104 | 105 | # Visual Studio profiler 106 | *.psess 107 | *.vsp 108 | *.vspx 109 | *.sap 110 | 111 | # Visual Studio Trace Files 112 | *.e2e 113 | 114 | # TFS 2012 Local Workspace 115 | $tf/ 116 | 117 | # Guidance Automation Toolkit 118 | *.gpState 119 | 120 | # ReSharper is a .NET coding add-in 121 | _ReSharper*/ 122 | *.[Rr]e[Ss]harper 123 | *.DotSettings.user 124 | 125 | # JustCode is a .NET coding add-in 126 | .JustCode 127 | 128 | # TeamCity is a build add-in 129 | _TeamCity* 130 | 131 | # DotCover is a Code Coverage Tool 132 | *.dotCover 133 | 134 | # AxoCover is a Code Coverage Tool 135 | .axoCover/* 136 | !.axoCover/settings.json 137 | 138 | # Visual Studio code coverage results 139 | *.coverage 140 | *.coveragexml 141 | 142 | # NCrunch 143 | _NCrunch_* 144 | .*crunch*.local.xml 145 | nCrunchTemp_* 146 | 147 | # MightyMoose 148 | *.mm.* 149 | AutoTest.Net/ 150 | 151 | # Web workbench (sass) 152 | .sass-cache/ 153 | 154 | # Installshield output folder 155 | [Ee]xpress/ 156 | 157 | # DocProject is a documentation generator add-in 158 | DocProject/buildhelp/ 159 | DocProject/Help/*.HxT 160 | DocProject/Help/*.HxC 161 | DocProject/Help/*.hhc 162 | DocProject/Help/*.hhk 163 | DocProject/Help/*.hhp 164 | DocProject/Help/Html2 165 | DocProject/Help/html 166 | 167 | # Click-Once directory 168 | publish/ 169 | 170 | # Publish Web Output 171 | *.[Pp]ublish.xml 172 | *.azurePubxml 173 | # Note: Comment the next line if you want to checkin your web deploy settings, 174 | # but database connection strings (with potential passwords) will be unencrypted 175 | *.pubxml 176 | *.publishproj 177 | 178 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 179 | # checkin your Azure Web App publish settings, but sensitive information contained 180 | # in these scripts will be unencrypted 181 | PublishScripts/ 182 | 183 | # NuGet Packages 184 | *.nupkg 185 | # The packages folder can be ignored because of Package Restore 186 | **/[Pp]ackages/* 187 | # except build/, which is used as an MSBuild target. 188 | !**/[Pp]ackages/build/ 189 | # Uncomment if necessary however generally it will be regenerated when needed 190 | #!**/[Pp]ackages/repositories.config 191 | # NuGet v3's project.json files produces more ignorable files 192 | *.nuget.props 193 | *.nuget.targets 194 | 195 | # Microsoft Azure Build Output 196 | csx/ 197 | *.build.csdef 198 | 199 | # Microsoft Azure Emulator 200 | ecf/ 201 | rcf/ 202 | 203 | # Windows Store app package directories and files 204 | AppPackages/ 205 | BundleArtifacts/ 206 | Package.StoreAssociation.xml 207 | _pkginfo.txt 208 | *.appx 209 | 210 | # Visual Studio cache files 211 | # files ending in .cache can be ignored 212 | *.[Cc]ache 213 | # but keep track of directories ending in .cache 214 | !?*.[Cc]ache/ 215 | 216 | # Others 217 | ClientBin/ 218 | ~$* 219 | *~ 220 | *.dbmdl 221 | *.dbproj.schemaview 222 | *.jfm 223 | *.pfx 224 | *.publishsettings 225 | orleans.codegen.cs 226 | 227 | # Including strong name files can present a security risk 228 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 229 | #*.snk 230 | 231 | # Since there are multiple workflows, uncomment next line to ignore bower_components 232 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 233 | #bower_components/ 234 | 235 | # RIA/Silverlight projects 236 | Generated_Code/ 237 | 238 | # Backup & report files from converting an old project file 239 | # to a newer Visual Studio version. Backup files are not needed, 240 | # because we have git ;-) 241 | _UpgradeReport_Files/ 242 | Backup*/ 243 | UpgradeLog*.XML 244 | UpgradeLog*.htm 245 | ServiceFabricBackup/ 246 | *.rptproj.bak 247 | 248 | # SQL Server files 249 | *.mdf 250 | *.ldf 251 | *.ndf 252 | 253 | # Business Intelligence projects 254 | *.rdl.data 255 | *.bim.layout 256 | *.bim_*.settings 257 | *.rptproj.rsuser 258 | *- Backup*.rdl 259 | 260 | # Microsoft Fakes 261 | FakesAssemblies/ 262 | 263 | # GhostDoc plugin setting file 264 | *.GhostDoc.xml 265 | 266 | # Node.js Tools for Visual Studio 267 | .ntvs_analysis.dat 268 | node_modules/ 269 | 270 | # Visual Studio 6 build log 271 | *.plg 272 | 273 | # Visual Studio 6 workspace options file 274 | *.opt 275 | 276 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 277 | *.vbw 278 | 279 | # Visual Studio LightSwitch build output 280 | **/*.HTMLClient/GeneratedArtifacts 281 | **/*.DesktopClient/GeneratedArtifacts 282 | **/*.DesktopClient/ModelManifest.xml 283 | **/*.Server/GeneratedArtifacts 284 | **/*.Server/ModelManifest.xml 285 | _Pvt_Extensions 286 | 287 | # Paket dependency manager 288 | .paket/paket.exe 289 | paket-files/ 290 | 291 | # FAKE - F# Make 292 | .fake/ 293 | 294 | # JetBrains Rider 295 | .idea/ 296 | *.sln.iml 297 | 298 | # CodeRush personal settings 299 | .cr/personal 300 | 301 | # Python Tools for Visual Studio (PTVS) 302 | __pycache__/ 303 | *.pyc 304 | 305 | # Cake - Uncomment if you are using it 306 | # tools/** 307 | # !tools/packages.config 308 | 309 | # Tabs Studio 310 | *.tss 311 | 312 | # Telerik's JustMock configuration file 313 | *.jmconfig 314 | 315 | # BizTalk build output 316 | *.btp.cs 317 | *.btm.cs 318 | *.odx.cs 319 | *.xsd.cs 320 | 321 | # OpenCover UI analysis results 322 | OpenCover/ 323 | 324 | # Azure Stream Analytics local run output 325 | ASALocalRun/ 326 | 327 | # MSBuild Binary and Structured Log 328 | *.binlog 329 | 330 | # NVidia Nsight GPU debugger configuration file 331 | *.nvuser 332 | 333 | # MFractors (Xamarin productivity tool) working folder 334 | .mfractor/ 335 | 336 | # Local History for Visual Studio 337 | .localhistory/ 338 | 339 | # BeatPulse healthcheck temp database 340 | healthchecksdb -------------------------------------------------------------------------------- /00. Framework/Framework.Domain/ApplicationServices/ICommandHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Framework.Domain.ApplicationServices 6 | { 7 | public interface ICommandHandler 8 | { 9 | void Handle(TCommand command); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /00. Framework/Framework.Domain/Class1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Framework.Domain 4 | { 5 | public class Class1 6 | { 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /00. Framework/Framework.Domain/Data/IAggregateStore.cs: -------------------------------------------------------------------------------- 1 | using Framework.Domain.Entieis; 2 | using System.Threading.Tasks; 3 | 4 | namespace Framework.Domain.Data 5 | { 6 | //public interface IAggregateStore 7 | //{ 8 | // Task Exists(TId aggregateId); 9 | // Task Save(T aggregate) where T : BaseAggregateRoot; 10 | // Task Load(TId aggregateId) where T : BaseAggregateRoot; 11 | //} 12 | } 13 | -------------------------------------------------------------------------------- /00. Framework/Framework.Domain/Data/IEventSource.cs: -------------------------------------------------------------------------------- 1 | using Framework.Domain.Events; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Framework.Domain.Data 7 | { 8 | public interface IEventSource 9 | { 10 | void Save(string aggregateName, string streamId, IEnumerable events) where TEvent : IEvent; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /00. Framework/Framework.Domain/Data/IUnitOfWork.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Framework.Domain.Data 6 | { 7 | public interface IUnitOfWork 8 | { 9 | int Commit(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /00. Framework/Framework.Domain/Entieis/BaseAggregateRoot.cs: -------------------------------------------------------------------------------- 1 | using Framework.Domain.Events; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | 6 | namespace Framework.Domain.Entieis 7 | { 8 | public abstract class BaseAggregateRoot where TId : IEquatable 9 | { 10 | 11 | private readonly List _events; 12 | public TId Id { get; protected set; } 13 | protected BaseAggregateRoot() => _events = new List(); 14 | protected void HandleEvent(IEvent @event) 15 | { 16 | SetStateByEvent(@event); 17 | ValidateInvariants(); 18 | _events.Add(@event); 19 | } 20 | protected abstract void SetStateByEvent(IEvent @event); 21 | public IEnumerable GetEvents() => _events.AsEnumerable(); 22 | public void ClearEvents() => _events.Clear(); 23 | protected abstract void ValidateInvariants(); 24 | 25 | 26 | public override bool Equals(object obj) 27 | { 28 | var other = obj as BaseAggregateRoot; 29 | 30 | if (ReferenceEquals(other, null)) 31 | return false; 32 | 33 | if (ReferenceEquals(this, other)) 34 | return true; 35 | 36 | if (GetType() != other.GetType()) 37 | return false; 38 | 39 | if (Id == default || other.Id == default) 40 | return false; 41 | 42 | return Id.Equals(other.Id); 43 | } 44 | 45 | public static bool operator ==(BaseAggregateRoot a, BaseAggregateRoot b) 46 | { 47 | if (ReferenceEquals(a, null) && ReferenceEquals(b, null)) 48 | return true; 49 | 50 | if (ReferenceEquals(a, null) || ReferenceEquals(b, null)) 51 | return false; 52 | 53 | return a.Equals(b); 54 | } 55 | 56 | public static bool operator !=(BaseAggregateRoot a, BaseAggregateRoot b) 57 | { 58 | return !(a == b); 59 | } 60 | 61 | public override int GetHashCode() 62 | { 63 | return (GetType().ToString() + Id).GetHashCode(); 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /00. Framework/Framework.Domain/Entieis/BaseEntity.cs: -------------------------------------------------------------------------------- 1 | using Framework.Domain.Events; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace Framework.Domain.Entieis 8 | { 9 | //public abstract class BaseEntity 10 | //{ 11 | // private readonly List _events = new List(); 12 | // private void Raise(IEvent @event) => _events.Add(@event); 13 | // protected void HandleEvent(IEvent @event) 14 | // { 15 | // SetStateByEvent(@event); 16 | // ValidateInvariants(); 17 | // Raise(@event); 18 | // } 19 | // protected abstract void SetStateByEvent(IEvent @event); 20 | // public IEnumerable GetChanges() => _events.AsEnumerable(); 21 | // public void ClearChanges() => _events.Clear(); 22 | 23 | // public TId Id { get; set; } 24 | 25 | // protected abstract void ValidateInvariants(); 26 | //} 27 | public abstract class BaseEntity where TId : IEquatable 28 | { 29 | public TId Id { get; protected set; } 30 | private Action _applier; 31 | public BaseEntity(Action applier) 32 | { 33 | _applier = applier; 34 | 35 | } 36 | protected BaseEntity() { } 37 | public void HandleEvent(IEvent @event) 38 | { 39 | SetStateByEvent(@event); 40 | _applier(@event); 41 | } 42 | 43 | protected abstract void SetStateByEvent(IEvent @event); 44 | 45 | public override bool Equals(object obj) 46 | { 47 | var other = obj as BaseEntity; 48 | 49 | if (ReferenceEquals(other, null)) 50 | return false; 51 | 52 | if (ReferenceEquals(this, other)) 53 | return true; 54 | 55 | if (GetType() != other.GetType()) 56 | return false; 57 | 58 | if (Id == default || other.Id == default) 59 | return false; 60 | 61 | return Id.Equals(other.Id); 62 | } 63 | 64 | public static bool operator ==(BaseEntity a, BaseEntity b) 65 | { 66 | if (ReferenceEquals(a, null) && ReferenceEquals(b, null)) 67 | return true; 68 | 69 | if (ReferenceEquals(a, null) || ReferenceEquals(b, null)) 70 | return false; 71 | 72 | return a.Equals(b); 73 | } 74 | 75 | public static bool operator !=(BaseEntity a, BaseEntity b) 76 | { 77 | return !(a == b); 78 | } 79 | 80 | public override int GetHashCode() 81 | { 82 | return (GetType().ToString() + Id).GetHashCode(); 83 | } 84 | 85 | 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /00. Framework/Framework.Domain/Events/IEvent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Framework.Domain.Events 6 | { 7 | public interface IEvent 8 | { 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /00. Framework/Framework.Domain/Exceptions/InvalidEntityStateException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Framework.Domain.Exceptions 6 | { 7 | public class InvalidEntityStateException : Exception 8 | { 9 | public InvalidEntityStateException(object entity, string message) 10 | : base(string.Format("امکان تغییر وضعیت {0} وجود ندارد. {1}", entity.GetType().Name, message)) 11 | { 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /00. Framework/Framework.Domain/Framework.Domain.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netstandard2.1 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /00. Framework/Framework.Domain/ValueObjects/BaseValueObject.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Framework.Domain.ValueObjects 4 | { 5 | public abstract class BaseValueObject : IEquatable 6 | where TValueObject : BaseValueObject 7 | { 8 | public override bool Equals(object obj) 9 | { 10 | var otherObject = obj as TValueObject; 11 | if (ReferenceEquals(otherObject, null)) 12 | return false; 13 | return ObjectIsEqual(otherObject); 14 | } 15 | public override int GetHashCode() 16 | { 17 | return GetHashCode(); 18 | } 19 | public abstract bool ObjectIsEqual(TValueObject otherObject); 20 | public abstract int ObjectGetHashCode(); 21 | public bool Equals(TValueObject other) 22 | { 23 | return this == other; 24 | } 25 | public static bool operator ==(BaseValueObject right, BaseValueObject left) 26 | { 27 | if (ReferenceEquals(right, null) && ReferenceEquals(left, null)) 28 | return true; 29 | if (ReferenceEquals(right, null) || ReferenceEquals(left, null)) 30 | return false; 31 | return right.Equals(left); 32 | } 33 | public static bool operator !=(BaseValueObject right, BaseValueObject left) 34 | { 35 | return !(right == left); 36 | } 37 | 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /00. Framework/Framework.Tools/Class1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Framework.Tools 4 | { 5 | public class Class1 6 | { 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /00. Framework/Framework.Tools/Enums/EnumExtentions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Framework.Tools.Enums 6 | { 7 | public static class EnumExtentions 8 | { 9 | public static string GetDescription(this Enum @enum) 10 | { 11 | 12 | Type genericEnumType = @enum.GetType(); 13 | System.Reflection.MemberInfo[] memberInfo = 14 | genericEnumType.GetMember(@enum.ToString()); 15 | 16 | if (memberInfo != null && memberInfo.Length > 0) 17 | { 18 | 19 | var Attribs = memberInfo[0].GetCustomAttributes 20 | (typeof(System.ComponentModel.DescriptionAttribute), false); 21 | if (Attribs != null && Attribs.Length > 0) 22 | { 23 | return ((System.ComponentModel.DescriptionAttribute)Attribs[0]).Description; 24 | } 25 | } 26 | 27 | return @enum.ToString(); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /00. Framework/Framework.Tools/Framework.Tools.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /01. Core/Bazzar.Core.ApplicationServices/Advertisements/CommandHandlers/CreateHandler.cs: -------------------------------------------------------------------------------- 1 | using Bazzar.Core.Domain.Advertisements.Commands; 2 | using Bazzar.Core.Domain.Advertisements.Data; 3 | using Bazzar.Core.Domain.Advertisements.Entities; 4 | using Bazzar.Core.Domain.Advertisements.ValueObjects; 5 | using Framework.Domain.ApplicationServices; 6 | using Framework.Domain.Data; 7 | using Framework.Domain.Events; 8 | using System; 9 | using System.Collections.Generic; 10 | using System.Text; 11 | 12 | namespace Bazzar.Core.ApplicationServices.Advertisements.CommandHandlers 13 | { 14 | public class CreateHandler : ICommandHandler 15 | { 16 | private readonly IUnitOfWork unitOfWork; 17 | private readonly IAdvertisementsRepository advertisementsRepository; 18 | //private readonly IEventSource eventSource; 19 | 20 | public CreateHandler(IUnitOfWork unitOfWork, 21 | IAdvertisementsRepository advertisementsRepository) 22 | { 23 | this.unitOfWork = unitOfWork; 24 | this.advertisementsRepository = advertisementsRepository; 25 | //this.eventSource = eventSource; 26 | } 27 | public void Handle(Create command) 28 | { 29 | if (advertisementsRepository.Exists(command.Id)) 30 | throw new InvalidOperationException($"قبلا آگهی با شناسه {command.Id} ثبت شده است."); 31 | 32 | var advertisement = new Advertisment(command.Id, 33 | new UserId(command.OwnerId) 34 | ); 35 | advertisementsRepository.Add(advertisement); 36 | unitOfWork.Commit(); 37 | var events = advertisement.GetEvents(); 38 | //eventSource.Save("Advertisement", command.Id.ToString(), events); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /01. Core/Bazzar.Core.ApplicationServices/Advertisements/CommandHandlers/RequestToPublishHandler.cs: -------------------------------------------------------------------------------- 1 | using Bazzar.Core.Domain.Advertisements.Commands; 2 | using Bazzar.Core.Domain.Advertisements.Data; 3 | using Framework.Domain.ApplicationServices; 4 | using Framework.Domain.Data; 5 | using System; 6 | 7 | namespace Bazzar.Core.ApplicationServices.Advertisements.CommandHandlers 8 | { 9 | public class RequestToPublishHandler : ICommandHandler 10 | { 11 | private readonly IUnitOfWork unitOfWork; 12 | protected readonly IAdvertisementsRepository advertisementsRepository; 13 | 14 | public RequestToPublishHandler(IUnitOfWork unitOfWork, IAdvertisementsRepository advertisementsRepository) 15 | { 16 | this.unitOfWork = unitOfWork; 17 | this.advertisementsRepository = advertisementsRepository; 18 | } 19 | public void Handle(RequestToPublish command) 20 | { 21 | var advertisement = advertisementsRepository.Load(command.Id); 22 | if (advertisement == null) 23 | throw new InvalidOperationException($"آگهی با شناسه {command.Id} یافت نشد."); 24 | advertisement.RequestToPublish(); 25 | unitOfWork.Commit(); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /01. Core/Bazzar.Core.ApplicationServices/Advertisements/CommandHandlers/SetTitleHandler.cs: -------------------------------------------------------------------------------- 1 | using Bazzar.Core.Domain.Advertisements.Commands; 2 | using Bazzar.Core.Domain.Advertisements.Data; 3 | using Bazzar.Core.Domain.Advertisements.ValueObjects; 4 | using Framework.Domain.ApplicationServices; 5 | using Framework.Domain.Data; 6 | using System; 7 | 8 | namespace Bazzar.Core.ApplicationServices.Advertisements.CommandHandlers 9 | { 10 | public class SetTitleHandler : ICommandHandler 11 | { 12 | private readonly IUnitOfWork unitOfWork; 13 | protected readonly IAdvertisementsRepository advertisementsRepository; 14 | 15 | public SetTitleHandler(IUnitOfWork unitOfWork, IAdvertisementsRepository advertisementsRepository) 16 | { 17 | this.unitOfWork = unitOfWork; 18 | this.advertisementsRepository = advertisementsRepository; 19 | } 20 | public void Handle(SetTitle command) 21 | { 22 | var advertisement = advertisementsRepository.Load(command.Id); 23 | if (advertisement == null) 24 | throw new InvalidOperationException($"آگهی با شناسه {command.Id} یافت نشد."); 25 | advertisement.SetTitle(AdvertismentTitle.FromString(command.Title)); 26 | unitOfWork.Commit(); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /01. Core/Bazzar.Core.ApplicationServices/Advertisements/CommandHandlers/UpdatePriceHandler.cs: -------------------------------------------------------------------------------- 1 | using Bazzar.Core.Domain.Advertisements.Commands; 2 | using Bazzar.Core.Domain.Advertisements.Data; 3 | using Bazzar.Core.Domain.Advertisements.ValueObjects; 4 | using Framework.Domain.ApplicationServices; 5 | using Framework.Domain.Data; 6 | using System; 7 | 8 | namespace Bazzar.Core.ApplicationServices.Advertisements.CommandHandlers 9 | { 10 | public class UpdatePriceHandler : ICommandHandler 11 | { 12 | private readonly IUnitOfWork unitOfWork; 13 | protected readonly IAdvertisementsRepository advertisementsRepository; 14 | 15 | public UpdatePriceHandler(IUnitOfWork unitOfWork, IAdvertisementsRepository advertisementsRepository) 16 | { 17 | this.unitOfWork = unitOfWork; 18 | this.advertisementsRepository = advertisementsRepository; 19 | } 20 | 21 | 22 | 23 | public void Handle(UpdatePrice command) 24 | { 25 | var advertisement = advertisementsRepository.Load(command.Id); 26 | if (advertisement == null) 27 | throw new InvalidOperationException($"آگهی با شناسه {command.Id} یافت نشد."); 28 | advertisement.UpdatePrice(Price.FromLong(command.Price)); 29 | unitOfWork.Commit(); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /01. Core/Bazzar.Core.ApplicationServices/Advertisements/CommandHandlers/UpdateTextHandler.cs: -------------------------------------------------------------------------------- 1 | using Bazzar.Core.Domain.Advertisements.Commands; 2 | using Bazzar.Core.Domain.Advertisements.Data; 3 | using Bazzar.Core.Domain.Advertisements.ValueObjects; 4 | using Framework.Domain.ApplicationServices; 5 | using Framework.Domain.Data; 6 | using System; 7 | 8 | namespace Bazzar.Core.ApplicationServices.Advertisements.CommandHandlers 9 | { 10 | public class UpdateTextHandler : ICommandHandler 11 | { 12 | private readonly IUnitOfWork unitOfWork; 13 | protected readonly IAdvertisementsRepository advertisementsRepository; 14 | 15 | public UpdateTextHandler(IUnitOfWork unitOfWork, IAdvertisementsRepository advertisementsRepository) 16 | { 17 | this.unitOfWork = unitOfWork; 18 | this.advertisementsRepository = advertisementsRepository; 19 | } 20 | public void Handle(UpdateText command) 21 | { 22 | var advertisement = advertisementsRepository.Load(command.Id); 23 | if (advertisement == null) 24 | throw new InvalidOperationException($"آگهی با شناسه {command.Id} یافت نشد."); 25 | advertisement.UpdateText(AdvertismentText.FromString(command.Text)); 26 | unitOfWork.Commit(); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /01. Core/Bazzar.Core.ApplicationServices/Bazzar.Core.ApplicationServices.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.1 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /01. Core/Bazzar.Core.ApplicationServices/Class1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Bazzar.Core.ApplicationServices 4 | { 5 | public class Class1 6 | { 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /01. Core/Bazzar.Core.ApplicationServices/UserProfiles/CommandHandlers/RegisterUserHandler.cs: -------------------------------------------------------------------------------- 1 | using Bazzar.Core.Domain.UserProfiles.Commands; 2 | using Bazzar.Core.Domain.UserProfiles.Data; 3 | using Bazzar.Core.Domain.UserProfiles.Entities; 4 | using Bazzar.Core.Domain.UserProfiles.ValueObjects; 5 | using Framework.Domain.ApplicationServices; 6 | using Framework.Domain.Data; 7 | using System; 8 | 9 | namespace Bazzar.Core.ApplicationServices.UserProfiles.CommandHandlers 10 | { 11 | public class RegisterUserHandler : ICommandHandler 12 | { 13 | private readonly IUnitOfWork unitOfWork; 14 | private readonly IUserProfileRepository _userProfileRepository; 15 | public RegisterUserHandler(IUnitOfWork unitOfWork, IUserProfileRepository userProfileRepository) 16 | { 17 | this.unitOfWork = unitOfWork; 18 | _userProfileRepository = userProfileRepository; 19 | } 20 | public void Handle(RegisterUser command) 21 | { 22 | if (_userProfileRepository.Exists(command.UserId)) 23 | throw new InvalidOperationException($"قبلا کاربری با شناسه {command.UserId} ثبت شده است."); 24 | 25 | UserProfile userProfile = new UserProfile(command.UserId, 26 | FirstName.FromString(command.FirstName), 27 | LastName.FromString(command.LastName), 28 | DisplayName.FromString(command.DisplayName)); 29 | _userProfileRepository.Add(userProfile); 30 | unitOfWork.Commit(); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /01. Core/Bazzar.Core.ApplicationServices/UserProfiles/CommandHandlers/UpdateUserDisplayNameHandler.cs: -------------------------------------------------------------------------------- 1 | using Bazzar.Core.Domain.UserProfiles.Commands; 2 | using Bazzar.Core.Domain.UserProfiles.Data; 3 | using Bazzar.Core.Domain.UserProfiles.ValueObjects; 4 | using Framework.Domain.ApplicationServices; 5 | using Framework.Domain.Data; 6 | using System; 7 | 8 | namespace Bazzar.Core.ApplicationServices.UserProfiles.CommandHandlers 9 | { 10 | public class UpdateUserDisplayNameHandler : ICommandHandler 11 | { 12 | private readonly IUnitOfWork unitOfWork; 13 | private readonly IUserProfileRepository _userProfileRepository; 14 | public UpdateUserDisplayNameHandler(IUnitOfWork unitOfWork, IUserProfileRepository userProfileRepository) 15 | { 16 | this.unitOfWork = unitOfWork; 17 | _userProfileRepository = userProfileRepository; 18 | } 19 | public void Handle(UpdateUserDisplayName command) 20 | { 21 | var user = _userProfileRepository.Load(command.UserId); 22 | if(user == null) 23 | throw new InvalidOperationException($"کاربری با شناسه {command.UserId} یافت نشد."); 24 | user.UpdateDisplayName(DisplayName.FromString(command.DisplayName)); 25 | unitOfWork.Commit(); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /01. Core/Bazzar.Core.ApplicationServices/UserProfiles/CommandHandlers/UpdateUserEmailHandler.cs: -------------------------------------------------------------------------------- 1 | using Bazzar.Core.Domain.Shared.ValueObjects; 2 | using Bazzar.Core.Domain.UserProfiles.Commands; 3 | using Bazzar.Core.Domain.UserProfiles.Data; 4 | using Framework.Domain.ApplicationServices; 5 | using Framework.Domain.Data; 6 | using System; 7 | 8 | namespace Bazzar.Core.ApplicationServices.UserProfiles.CommandHandlers 9 | { 10 | public class UpdateUserEmailHandler : ICommandHandler 11 | { 12 | private readonly IUnitOfWork unitOfWork; 13 | private readonly IUserProfileRepository _userProfileRepository; 14 | public UpdateUserEmailHandler(IUnitOfWork unitOfWork, IUserProfileRepository userProfileRepository) 15 | { 16 | this.unitOfWork = unitOfWork; 17 | _userProfileRepository = userProfileRepository; 18 | } 19 | public void Handle(UpdateUserEmail command) 20 | { 21 | var user = _userProfileRepository.Load(command.UserId); 22 | if (user == null) 23 | throw new InvalidOperationException($"کاربری با شناسه {command.UserId} یافت نشد."); 24 | user.UpdateEmail(Email.FromString(command.Email)); 25 | unitOfWork.Commit(); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /01. Core/Bazzar.Core.ApplicationServices/UserProfiles/CommandHandlers/UpdateUserNameHandler.cs: -------------------------------------------------------------------------------- 1 | using Bazzar.Core.Domain.UserProfiles.Commands; 2 | using Bazzar.Core.Domain.UserProfiles.Data; 3 | using Bazzar.Core.Domain.UserProfiles.ValueObjects; 4 | using Framework.Domain.ApplicationServices; 5 | using Framework.Domain.Data; 6 | using System; 7 | 8 | namespace Bazzar.Core.ApplicationServices.UserProfiles.CommandHandlers 9 | { 10 | public class UpdateUserNameHandler : ICommandHandler 11 | { 12 | private readonly IUnitOfWork unitOfWork; 13 | private readonly IUserProfileRepository _userProfileRepository; 14 | public UpdateUserNameHandler(IUnitOfWork unitOfWork, IUserProfileRepository userProfileRepository) 15 | { 16 | this.unitOfWork = unitOfWork; 17 | _userProfileRepository = userProfileRepository; 18 | } 19 | public void Handle(UpdateUserName command) 20 | { 21 | var user = _userProfileRepository.Load(command.UserId); 22 | if (user == null) 23 | throw new InvalidOperationException($"کاربری با شناسه {command.UserId} یافت نشد."); 24 | user.UpdateName(FirstName.FromString(command.FirstName), LastName.FromString(command.LastName)); 25 | unitOfWork.Commit(); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /01. Core/Bazzar.Core.Domain/Advertisements/Commands/Create.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Bazzar.Core.Domain.Advertisements.Commands 6 | { 7 | public class Create 8 | { 9 | public Guid Id { get; set; } 10 | public Guid OwnerId { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /01. Core/Bazzar.Core.Domain/Advertisements/Commands/RequestToPublish.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Bazzar.Core.Domain.Advertisements.Commands 4 | { 5 | public class RequestToPublish 6 | { 7 | public Guid Id { get; set; } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /01. Core/Bazzar.Core.Domain/Advertisements/Commands/SetTitle.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Bazzar.Core.Domain.Advertisements.Commands 4 | { 5 | public class SetTitle 6 | { 7 | public Guid Id { get; set; } 8 | public string Title { get; set; } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /01. Core/Bazzar.Core.Domain/Advertisements/Commands/UpdatePrice.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Bazzar.Core.Domain.Advertisements.Commands 4 | { 5 | public class UpdatePrice 6 | { 7 | public Guid Id { get; set; } 8 | public long Price { get; set; } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /01. Core/Bazzar.Core.Domain/Advertisements/Commands/UpdateText.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Bazzar.Core.Domain.Advertisements.Commands 4 | { 5 | public class UpdateText 6 | { 7 | public Guid Id { get; set; } 8 | public string Text { get; set; } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /01. Core/Bazzar.Core.Domain/Advertisements/Data/IAdvertisementQueryService.cs: -------------------------------------------------------------------------------- 1 | using Bazzar.Core.Domain.Advertisements.Dtoes; 2 | using Bazzar.Core.Domain.Advertisements.Queries; 3 | 4 | namespace Bazzar.Core.Domain.Advertisements.Data 5 | { 6 | public interface IAdvertisementQueryService 7 | { 8 | AdvertisementDetail Query(GetActiveAdvertisement query); 9 | AdvertisementSummary Query(GetActiveAdvertisementList query); 10 | AdvertisementSummary Query(GetAdvertisementForSpecificSeller query); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /01. Core/Bazzar.Core.Domain/Advertisements/Data/IAdvertisementsRepository.cs: -------------------------------------------------------------------------------- 1 | using Bazzar.Core.Domain.Advertisements.Entities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Bazzar.Core.Domain.Advertisements.Data 7 | { 8 | public interface IAdvertisementsRepository 9 | { 10 | bool Exists(Guid id); 11 | 12 | Advertisment Load(Guid id); 13 | 14 | void Add(Advertisment entity); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /01. Core/Bazzar.Core.Domain/Advertisements/Dtoes/AdvertisementDetail.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Bazzar.Core.Domain.Advertisements.Dtoes 6 | { 7 | public class AdvertisementDetail 8 | { 9 | public Guid AdvertisementId { get; set; } 10 | public string Title { get; set; } 11 | public long Price { get; set; } 12 | public string Text { get; set; } 13 | public string SellersDisplayName { get; set; } 14 | public string PhotoUrls { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /01. Core/Bazzar.Core.Domain/Advertisements/Dtoes/AdvertisementSummary.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Bazzar.Core.Domain.Advertisements.Dtoes 4 | { 5 | public class AdvertisementSummary 6 | { 7 | public Guid AdvertisementId { get; set; } 8 | public string Title { get; set; } 9 | public decimal Price { get; set; } 10 | public string PhotoUrl { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /01. Core/Bazzar.Core.Domain/Advertisements/Entities/Advertisment.cs: -------------------------------------------------------------------------------- 1 | using Bazzar.Core.Domain.Advertisements.Events; 2 | using Bazzar.Core.Domain.Advertisements.ValueObjects; 3 | using Framework.Domain.Entieis; 4 | using Framework.Domain.Events; 5 | using Framework.Domain.Exceptions; 6 | using Framework.Tools.Enums; 7 | using System; 8 | using System.Collections.Generic; 9 | using System.Linq; 10 | using System.Text; 11 | 12 | namespace Bazzar.Core.Domain.Advertisements.Entities 13 | { 14 | public class Advertisment : BaseAggregateRoot 15 | { 16 | 17 | #region Fields 18 | public UserId OwnerId { get; protected set; } 19 | public UserId ApprovedBy { get; protected set; } 20 | public AdvertismentTitle Title { get; protected set; } 21 | public AdvertismentText Text { get; protected set; } 22 | public Price Price { get; protected set; } 23 | public AdvertismentState State { get; protected set; } 24 | public List Pictures { get; private set; } 25 | #endregion 26 | private Advertisment() 27 | { 28 | 29 | } 30 | public Advertisment(Guid id, UserId ownerId) 31 | { 32 | Pictures = new List(); 33 | HandleEvent(new AdvertismentCreated 34 | { 35 | Id = id, 36 | OwnerId = ownerId.Value 37 | }); 38 | } 39 | public void SetTitle(AdvertismentTitle title) 40 | { 41 | 42 | HandleEvent(new AdvertismentTitleChanged 43 | { 44 | Id = Id, 45 | Title = title.Value 46 | }); 47 | } 48 | 49 | public void UpdateText(AdvertismentText text) 50 | { 51 | 52 | HandleEvent(new AdvertismentTextUpdated 53 | { 54 | Id = Id, 55 | AdvertismentText = text.Value 56 | }); 57 | } 58 | public void UpdatePrice(Price price) 59 | { 60 | 61 | HandleEvent(new AdvertismentPriceUpdated 62 | { 63 | Id = Id, 64 | Price = price.Value.Value 65 | }); 66 | } 67 | public void RequestToPublish() 68 | { 69 | HandleEvent(new AdvertismentSentForReview 70 | { 71 | Id = Id 72 | }); 73 | } 74 | public void AddPicture(Uri pictureUri, PictureSize size) 75 | { 76 | var newPic = new Picture(HandleEvent); 77 | newPic.HandleEvent(new PictureAddedToAdvertisment 78 | { 79 | PictureId = new Guid(), 80 | ClassifiedAdId = Id, 81 | Url = pictureUri.ToString(), 82 | Height = size.Height, 83 | Width = size.Width 84 | }); 85 | Pictures.Add(newPic); 86 | } 87 | public void ResizePicture(Guid pictureId, PictureSize newSize) 88 | { 89 | var picture = FindPicture(pictureId); 90 | if (picture == null) 91 | throw new InvalidOperationException( 92 | "تصویری با شناسه وارد شده وجود برای تغییر سایز وجود ندارد"); 93 | picture.Resize(newSize); 94 | } 95 | private Picture FindPicture(Guid id) => Pictures.FirstOrDefault(x => x.Id == id); 96 | protected override void ValidateInvariants() 97 | { 98 | var isValid = 99 | Id != null && 100 | OwnerId != null && 101 | (State switch 102 | { 103 | AdvertismentState.ReviewPending => 104 | Title != null 105 | && Text != null 106 | && Price != null, 107 | //&& !Pictures.Any(), 108 | AdvertismentState.Active => 109 | Title != null 110 | && Text != null 111 | && Price != null 112 | && ApprovedBy != null, 113 | //&& !Pictures.Any(), 114 | _ => true 115 | }); 116 | if (!isValid) 117 | { 118 | throw new InvalidEntityStateException(this, $"مقدار تنظیم شده برای آگهی در وضیعت {State.GetDescription()} غیر قابل قبول است"); 119 | } 120 | } 121 | 122 | protected override void SetStateByEvent(IEvent @event) 123 | { 124 | switch (@event) 125 | { 126 | case AdvertismentCreated e: 127 | Id = e.Id; 128 | OwnerId = new UserId(e.OwnerId); 129 | State = AdvertismentState.Inactive; 130 | break; 131 | case AdvertismentPriceUpdated e: 132 | Price = new Price(Rial.FromLong(e.Price)); 133 | break; 134 | case AdvertismentSentForReview e: 135 | State = AdvertismentState.ReviewPending; 136 | break; 137 | case AdvertismentTextUpdated e: 138 | Text = new AdvertismentText(e.AdvertismentText); 139 | break; 140 | case AdvertismentTitleChanged e: 141 | Title = new AdvertismentTitle(e.Title); 142 | break; 143 | 144 | default: 145 | throw new InvalidOperationException("امکان اجرای عملیات درخواستی وجود ندارد"); 146 | } 147 | } 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /01. Core/Bazzar.Core.Domain/Advertisements/Entities/AdvertismentState.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | 3 | namespace Bazzar.Core.Domain.Advertisements.Entities 4 | { 5 | public enum AdvertismentState 6 | { 7 | [Description("غیرفعال")] 8 | Inactive = 1, 9 | [Description("در انتظار تایید")] 10 | ReviewPending = 2, 11 | [Description("فعال")] 12 | Active = 3, 13 | [Description("فروخته شده")] 14 | Sold = 4 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /01. Core/Bazzar.Core.Domain/Advertisements/Entities/Picture.cs: -------------------------------------------------------------------------------- 1 | using Bazzar.Core.Domain.Advertisements.Events; 2 | using Bazzar.Core.Domain.Advertisements.ValueObjects; 3 | using Framework.Domain.Entieis; 4 | using Framework.Domain.Events; 5 | using System; 6 | 7 | namespace Bazzar.Core.Domain.Advertisements.Entities 8 | { 9 | public class Picture : BaseEntity 10 | { 11 | #region Fields 12 | public PictureSize Size { get; private set; } 13 | public PictureUrl Location { get; private set; } 14 | public int Order { get; private set; } 15 | #endregion 16 | 17 | #region Constructors 18 | private Picture() 19 | { 20 | 21 | } 22 | public Picture(Action applier) : base(applier) 23 | { 24 | } 25 | #endregion 26 | 27 | #region Methods 28 | protected override void SetStateByEvent(IEvent @event) 29 | { 30 | switch (@event) 31 | { 32 | case PictureAddedToAdvertisment e: 33 | Id = e.PictureId; 34 | Location = PictureUrl.FromString(e.Url); 35 | Size = new PictureSize(e.Height, e.Width); 36 | Order = e.Order; 37 | break; 38 | case AdvertismentPictureResized e: 39 | Size = new PictureSize(e.Height, e.Width); 40 | break; 41 | } 42 | } 43 | public void Resize(PictureSize newSize) 44 | { 45 | SetStateByEvent(new AdvertismentPictureResized 46 | { 47 | PictureId = Id, 48 | Height = newSize.Width, 49 | Width = newSize.Width 50 | }); 51 | } 52 | #endregion 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /01. Core/Bazzar.Core.Domain/Advertisements/Events/AdvertismentCreated.cs: -------------------------------------------------------------------------------- 1 | using Framework.Domain.Events; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Bazzar.Core.Domain.Advertisements.Events 7 | { 8 | public class AdvertismentCreated : IEvent 9 | { 10 | public Guid Id { get; set; } 11 | public Guid OwnerId { get; set; } 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /01. Core/Bazzar.Core.Domain/Advertisements/Events/AdvertismentPictureResized.cs: -------------------------------------------------------------------------------- 1 | using Framework.Domain.Events; 2 | using System; 3 | 4 | namespace Bazzar.Core.Domain.Advertisements.Events 5 | { 6 | public class AdvertismentPictureResized: IEvent 7 | { 8 | public Guid PictureId { get; set; } 9 | public int Height { get; set; } 10 | public int Width { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /01. Core/Bazzar.Core.Domain/Advertisements/Events/AdvertismentPriceUpdated.cs: -------------------------------------------------------------------------------- 1 | using Framework.Domain.Events; 2 | using System; 3 | 4 | namespace Bazzar.Core.Domain.Advertisements.Events 5 | { 6 | public class AdvertismentPriceUpdated : IEvent 7 | { 8 | public Guid Id { get; set; } 9 | public long Price { get; set; } 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /01. Core/Bazzar.Core.Domain/Advertisements/Events/AdvertismentSentForReview.cs: -------------------------------------------------------------------------------- 1 | using Framework.Domain.Events; 2 | using System; 3 | 4 | namespace Bazzar.Core.Domain.Advertisements.Events 5 | { 6 | public class AdvertismentSentForReview : IEvent 7 | { 8 | public Guid Id { get; set; } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /01. Core/Bazzar.Core.Domain/Advertisements/Events/AdvertismentTextUpdated.cs: -------------------------------------------------------------------------------- 1 | using Framework.Domain.Events; 2 | using System; 3 | 4 | namespace Bazzar.Core.Domain.Advertisements.Events 5 | { 6 | public class AdvertismentTextUpdated : IEvent 7 | { 8 | public Guid Id { get; set; } 9 | public string AdvertismentText { get; set; } 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /01. Core/Bazzar.Core.Domain/Advertisements/Events/AdvertismentTitleChanged.cs: -------------------------------------------------------------------------------- 1 | using Framework.Domain.Events; 2 | using System; 3 | 4 | namespace Bazzar.Core.Domain.Advertisements.Events 5 | { 6 | public class AdvertismentTitleChanged : IEvent 7 | { 8 | public Guid Id { get; set; } 9 | public string Title { get; set; } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /01. Core/Bazzar.Core.Domain/Advertisements/Events/PictureAddedToAdvertisment.cs: -------------------------------------------------------------------------------- 1 | using Framework.Domain.Events; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Bazzar.Core.Domain.Advertisements.Events 7 | { 8 | public class PictureAddedToAdvertisment:IEvent 9 | { 10 | public Guid ClassifiedAdId { get; set; } 11 | public Guid PictureId { get; set; } 12 | public string Url { get; set; } 13 | public int Height { get; set; } 14 | public int Width { get; set; } 15 | public int Order { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /01. Core/Bazzar.Core.Domain/Advertisements/Queries/GetActiveAdvertisement.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Bazzar.Core.Domain.Advertisements.Queries 6 | { 7 | public class GetActiveAdvertisement 8 | { 9 | public Guid AdvertisementId { get; set; } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /01. Core/Bazzar.Core.Domain/Advertisements/Queries/GetActiveAdvertisementList.cs: -------------------------------------------------------------------------------- 1 | namespace Bazzar.Core.Domain.Advertisements.Queries 2 | { 3 | public class GetActiveAdvertisementList 4 | { 5 | public int PageNumber { get; set; } 6 | public int PageSize { get; set; } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /01. Core/Bazzar.Core.Domain/Advertisements/Queries/GetAdvertisementForSpecificSeller.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Bazzar.Core.Domain.Advertisements.Queries 4 | { 5 | public class GetAdvertisementForSpecificSeller 6 | { 7 | public Guid OwneruserId { get; set; } 8 | public int PageNumber { get; set; } 9 | public int PageSize { get; set; } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /01. Core/Bazzar.Core.Domain/Advertisements/ValueObjects/AdvertismentText.cs: -------------------------------------------------------------------------------- 1 | using Framework.Domain.ValueObjects; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Bazzar.Core.Domain.Advertisements.ValueObjects 7 | { 8 | public class AdvertismentText : BaseValueObject 9 | { 10 | 11 | public string Value { get; private set; } 12 | public static AdvertismentText FromString(string value) => new AdvertismentText(value); 13 | private AdvertismentText() 14 | { 15 | 16 | } 17 | public AdvertismentText(string value) 18 | { 19 | if (string.IsNullOrEmpty(value)) 20 | { 21 | throw new ArgumentException("برای متن آگهی مقدار لازم است", nameof(value)); 22 | } 23 | Value = value; 24 | } 25 | public override int ObjectGetHashCode() => Value.GetHashCode(); 26 | public override bool ObjectIsEqual(AdvertismentText otherObject) => Value == otherObject.Value; 27 | 28 | public static implicit operator string(AdvertismentText advertismentText) => advertismentText.Value; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /01. Core/Bazzar.Core.Domain/Advertisements/ValueObjects/AdvertismentTitle.cs: -------------------------------------------------------------------------------- 1 | using Framework.Domain.ValueObjects; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Bazzar.Core.Domain.Advertisements.ValueObjects 7 | { 8 | public class AdvertismentTitle:BaseValueObject 9 | { 10 | public string Value { get; private set; } 11 | public static AdvertismentTitle FromString(string value) => new AdvertismentTitle(value); 12 | 13 | private AdvertismentTitle() 14 | { 15 | 16 | } 17 | public AdvertismentTitle(string value) 18 | { 19 | if (string.IsNullOrEmpty(value)) 20 | { 21 | throw new ArgumentException("برای عنوان آگهی مقدار لازم است", nameof(value)); 22 | } 23 | if (value.Length > 100) 24 | { 25 | throw new ArgumentOutOfRangeException("عنوان آگهی نباید بیش از 100 کاراکتر باشد", nameof(value)); 26 | } 27 | Value = value; 28 | } 29 | public override int ObjectGetHashCode() => Value.GetHashCode(); 30 | public override bool ObjectIsEqual(AdvertismentTitle otherObject) => Value == otherObject.Value; 31 | 32 | public static implicit operator string(AdvertismentTitle advertismentTitle) => advertismentTitle.Value; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /01. Core/Bazzar.Core.Domain/Advertisements/ValueObjects/PictureSize.cs: -------------------------------------------------------------------------------- 1 | using Framework.Domain.ValueObjects; 2 | using System; 3 | 4 | namespace Bazzar.Core.Domain.Advertisements.ValueObjects 5 | { 6 | public class PictureSize : BaseValueObject 7 | { 8 | public int Height { get; private set; } 9 | public int Width { get; private set; } 10 | private PictureSize() 11 | { 12 | 13 | } 14 | public PictureSize(int width, int height) 15 | { 16 | if (Width <= 0) 17 | throw new ArgumentOutOfRangeException(nameof(width),"عرض تصویر باید عددی مثبت باشد."); 18 | if (Height <= 0) 19 | throw new ArgumentOutOfRangeException(nameof(height),"ارتفاع تصویر باید عددی مثبت باشد"); 20 | Width = width; 21 | Height = height; 22 | } 23 | public override int ObjectGetHashCode() 24 | { 25 | return (Width + Height).GetHashCode(); 26 | } 27 | 28 | public override bool ObjectIsEqual(PictureSize otherObject) 29 | { 30 | return Height == otherObject.Height && Width == otherObject.Width; 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /01. Core/Bazzar.Core.Domain/Advertisements/ValueObjects/PictureUrl.cs: -------------------------------------------------------------------------------- 1 | using Framework.Domain.ValueObjects; 2 | using System; 3 | 4 | namespace Bazzar.Core.Domain.Advertisements.ValueObjects 5 | { 6 | public class PictureUrl : BaseValueObject 7 | { 8 | public string Url { get; private set; } 9 | public static PictureUrl FromString(string value) => new PictureUrl(value); 10 | private PictureUrl() 11 | { 12 | 13 | } 14 | public PictureUrl(string value) 15 | { 16 | if (string.IsNullOrEmpty(value)) 17 | { 18 | throw new ArgumentException("برای آدرس تصویر مقدار لازم است", nameof(value)); 19 | } 20 | 21 | Url = value; 22 | } 23 | public override int ObjectGetHashCode() => Url.GetHashCode(); 24 | public override bool ObjectIsEqual(PictureUrl otherObject) => Url == otherObject.Url; 25 | 26 | public static implicit operator string(PictureUrl advertismentText) => advertismentText.Url; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /01. Core/Bazzar.Core.Domain/Advertisements/ValueObjects/Price.cs: -------------------------------------------------------------------------------- 1 | using Framework.Domain.ValueObjects; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Bazzar.Core.Domain.Advertisements.ValueObjects 7 | { 8 | public class Price : BaseValueObject 9 | { 10 | public Rial Value { get; private set; } 11 | public static Price FromString(string value) => new Price(Rial.FromString(value)); 12 | public static Price FromLong(long value) => new Price(Rial.FromLong(value)); 13 | private Price() 14 | { 15 | 16 | } 17 | public Price(Rial rial) 18 | { 19 | if (rial < 1) 20 | { 21 | throw new ArgumentOutOfRangeException("مقدار قیمت کمتر از 1 ریال نمی‌تواند باشد", nameof(Price)); 22 | } 23 | Value = rial; 24 | } 25 | public override int ObjectGetHashCode() 26 | { 27 | return Value.GetHashCode(); 28 | } 29 | 30 | public override bool ObjectIsEqual(Price otherObject) 31 | { 32 | return Value == otherObject.Value; 33 | } 34 | public static implicit operator long(Price price) => price.Value; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /01. Core/Bazzar.Core.Domain/Advertisements/ValueObjects/Rial.cs: -------------------------------------------------------------------------------- 1 | using Framework.Domain.ValueObjects; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Bazzar.Core.Domain.Advertisements.ValueObjects 7 | { 8 | public class Rial : BaseValueObject 9 | { 10 | public long Value { get; private set; } 11 | public static Rial FromString(string value) => new Rial(long.Parse(value)); 12 | public static Rial FromLong(long value) => new Rial(value); 13 | public override int ObjectGetHashCode() 14 | { 15 | return Value.GetHashCode(); 16 | } 17 | protected Rial(long value) 18 | { 19 | Value = value; 20 | } 21 | private Rial() 22 | { 23 | 24 | } 25 | public override bool ObjectIsEqual(Rial otherObject) 26 | { 27 | return Value == otherObject.Value; 28 | } 29 | 30 | public Rial Add(Rial rial) 31 | { 32 | return new Rial(rial.Value + Value); 33 | } 34 | public Rial Subtract(Rial rial) 35 | { 36 | return new Rial(rial.Value + Value); 37 | } 38 | 39 | public static Rial operator +(Rial leftSide, Rial rightSide) 40 | { 41 | return leftSide.Add(rightSide); 42 | } 43 | public static Rial operator -(Rial leftSide, Rial rightSide) 44 | { 45 | return leftSide.Subtract(rightSide); 46 | } 47 | 48 | public static implicit operator long(Rial rial) => rial.Value; 49 | 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /01. Core/Bazzar.Core.Domain/Advertisements/ValueObjects/UserId.cs: -------------------------------------------------------------------------------- 1 | using Framework.Domain.ValueObjects; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Bazzar.Core.Domain.Advertisements.ValueObjects 7 | { 8 | public class UserId : BaseValueObject 9 | { 10 | public Guid Value { get; private set; } 11 | private UserId() 12 | { 13 | 14 | } 15 | public static UserId FromString(string value) => new UserId(Guid.Parse(value)); 16 | public UserId(Guid value) 17 | { 18 | if (value == default) 19 | throw new ArgumentException("شناسه کاربر نمی‌تواند خالی باشد", nameof(value)); 20 | Value = value; 21 | } 22 | public override int ObjectGetHashCode() 23 | { 24 | return Value.GetHashCode(); 25 | } 26 | 27 | public override bool ObjectIsEqual(UserId otherObject) 28 | { 29 | return Value == otherObject.Value; 30 | } 31 | public static implicit operator Guid(UserId userId) => userId.Value; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /01. Core/Bazzar.Core.Domain/Bazzar.Core.Domain.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.1 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /01. Core/Bazzar.Core.Domain/Shared/ValueObjects/Email.cs: -------------------------------------------------------------------------------- 1 | using Framework.Domain.ValueObjects; 2 | using System; 3 | 4 | namespace Bazzar.Core.Domain.Shared.ValueObjects 5 | { 6 | public class Email : BaseValueObject 7 | { 8 | 9 | public string Value { get; private set; } 10 | public static Email FromString(string value) => new Email(value); 11 | private Email() 12 | { 13 | 14 | } 15 | public Email(string value) 16 | { 17 | if (string.IsNullOrEmpty(value)) 18 | { 19 | throw new ArgumentException("برای ایمیل مقدار لازم است", nameof(value)); 20 | } 21 | Value = value; 22 | } 23 | public override int ObjectGetHashCode() => Value.GetHashCode(); 24 | public override bool ObjectIsEqual(Email otherObject) => Value == otherObject.Value; 25 | 26 | public static implicit operator string(Email email) => email.Value; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /01. Core/Bazzar.Core.Domain/UserProfiles/Commands/RegisterUser.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Bazzar.Core.Domain.UserProfiles.Commands 6 | { 7 | public class RegisterUser 8 | { 9 | public Guid UserId { get; set; } 10 | public string FirstName { get; set; } 11 | public string LastName { get; set; } 12 | public string DisplayName { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /01. Core/Bazzar.Core.Domain/UserProfiles/Commands/UpdateUserDisplayName.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Bazzar.Core.Domain.UserProfiles.Commands 4 | { 5 | public class UpdateUserDisplayName 6 | { 7 | public Guid UserId { get; set; } 8 | public string DisplayName { get; set; } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /01. Core/Bazzar.Core.Domain/UserProfiles/Commands/UpdateUserEmail.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Bazzar.Core.Domain.UserProfiles.Commands 4 | { 5 | public class UpdateUserEmail 6 | { 7 | public Guid UserId { get; set; } 8 | public string Email { get; set; } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /01. Core/Bazzar.Core.Domain/UserProfiles/Commands/UpdateUserName.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Bazzar.Core.Domain.UserProfiles.Commands 4 | { 5 | public class UpdateUserName 6 | { 7 | public Guid UserId { get; set; } 8 | public string FirstName { get; set; } 9 | public string LastName { get; set; } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /01. Core/Bazzar.Core.Domain/UserProfiles/Data/IUserProfileRepository.cs: -------------------------------------------------------------------------------- 1 | using Bazzar.Core.Domain.UserProfiles.Entities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Bazzar.Core.Domain.UserProfiles.Data 7 | { 8 | public interface IUserProfileRepository 9 | { 10 | UserProfile Load(Guid id); 11 | void Add(UserProfile entity); 12 | bool Exists(Guid id); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /01. Core/Bazzar.Core.Domain/UserProfiles/Entities/UserProfile.cs: -------------------------------------------------------------------------------- 1 | using Bazzar.Core.Domain.Shared.ValueObjects; 2 | using Bazzar.Core.Domain.UserProfiles.Events; 3 | using Bazzar.Core.Domain.UserProfiles.ValueObjects; 4 | using Framework.Domain.Entieis; 5 | using Framework.Domain.Events; 6 | using System; 7 | 8 | namespace Bazzar.Core.Domain.UserProfiles.Entities 9 | { 10 | public class UserProfile : BaseAggregateRoot 11 | { 12 | #region Fields 13 | public FirstName FirstName { get; private set; } 14 | public LastName LastName { get; private set; } 15 | public DisplayName DisplayName { get; private set; } 16 | public Email Email { get; private set; } 17 | #endregion 18 | 19 | #region Costructurs 20 | private UserProfile() { } 21 | 22 | public UserProfile(Guid id, 23 | FirstName firstName, 24 | LastName lastName, 25 | DisplayName displayName) 26 | { 27 | HandleEvent(new UserRegistered 28 | { 29 | UserId = id, 30 | FirstName = firstName, 31 | LastName = lastName, 32 | DisplayName = displayName, 33 | }); 34 | } 35 | #endregion 36 | 37 | public void UpdateName( FirstName firstName, LastName lastName) 38 | { 39 | HandleEvent(new UserNameUpdated 40 | { 41 | UserId = Id, 42 | FirstName = firstName, 43 | LastName = lastName 44 | }); 45 | } 46 | 47 | public void UpdateDisplayName(DisplayName displayName) 48 | { 49 | HandleEvent(new UserDisplayNameUpdated 50 | { 51 | UserId = Id, 52 | DisplayName = displayName, 53 | }); 54 | } 55 | 56 | public void UpdateEmail(Email email) 57 | { 58 | HandleEvent(new UserEmailUpdated 59 | { 60 | UserId = Id, 61 | Email = email, 62 | }); 63 | } 64 | 65 | protected override void SetStateByEvent(IEvent @event) 66 | { 67 | switch (@event) 68 | { 69 | case UserRegistered e: 70 | Id = e.UserId; 71 | FirstName = FirstName.FromString(e.FirstName); 72 | LastName = LastName.FromString(e.LastName); 73 | DisplayName = DisplayName.FromString(e.DisplayName); 74 | break; 75 | case UserNameUpdated e: 76 | FirstName = FirstName.FromString(e.FirstName); 77 | LastName = LastName.FromString(e.LastName); 78 | break; 79 | case UserEmailUpdated e: 80 | Email = Email.FromString(e.Email); 81 | break; 82 | case UserDisplayNameUpdated e: 83 | DisplayName = DisplayName.FromString(e.DisplayName); 84 | break; 85 | default: 86 | throw new InvalidOperationException("امکان اجرای عملیات درخواستی وجود ندارد"); 87 | } 88 | } 89 | 90 | protected override void ValidateInvariants() 91 | { 92 | //Impliment invariants 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /01. Core/Bazzar.Core.Domain/UserProfiles/Events/UserDisplayNameUpdated.cs: -------------------------------------------------------------------------------- 1 | using Framework.Domain.Events; 2 | using System; 3 | 4 | namespace Bazzar.Core.Domain.UserProfiles.Events 5 | { 6 | public class UserDisplayNameUpdated : IEvent 7 | { 8 | public Guid UserId { get; set; } 9 | public string DisplayName { get; set; } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /01. Core/Bazzar.Core.Domain/UserProfiles/Events/UserEmailUpdated.cs: -------------------------------------------------------------------------------- 1 | using Framework.Domain.Events; 2 | using System; 3 | 4 | namespace Bazzar.Core.Domain.UserProfiles.Events 5 | { 6 | public class UserEmailUpdated : IEvent 7 | { 8 | public Guid UserId { get; set; } 9 | public string Email { get; set; } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /01. Core/Bazzar.Core.Domain/UserProfiles/Events/UserNameUpdated.cs: -------------------------------------------------------------------------------- 1 | using Framework.Domain.Events; 2 | using System; 3 | 4 | namespace Bazzar.Core.Domain.UserProfiles.Events 5 | { 6 | public class UserNameUpdated : IEvent 7 | { 8 | public Guid UserId { get; set; } 9 | public string FirstName { get; set; } 10 | public string LastName { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /01. Core/Bazzar.Core.Domain/UserProfiles/Events/UserRegistered.cs: -------------------------------------------------------------------------------- 1 | using Framework.Domain.Events; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Bazzar.Core.Domain.UserProfiles.Events 7 | { 8 | public class UserRegistered:IEvent 9 | { 10 | public Guid UserId { get; set; } 11 | public string FirstName { get; set; } 12 | public string LastName { get; set; } 13 | public string DisplayName { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /01. Core/Bazzar.Core.Domain/UserProfiles/ValueObjects/DisplayName.cs: -------------------------------------------------------------------------------- 1 | using Framework.Domain.ValueObjects; 2 | using System; 3 | 4 | namespace Bazzar.Core.Domain.UserProfiles.ValueObjects 5 | { 6 | public class DisplayName : BaseValueObject 7 | { 8 | 9 | public string Value { get; private set; } 10 | public static DisplayName FromString(string value) => new DisplayName(value); 11 | private DisplayName() 12 | { 13 | 14 | } 15 | public DisplayName(string value) 16 | { 17 | if (string.IsNullOrEmpty(value)) 18 | { 19 | throw new ArgumentException("برای نام نمایشی مقدار لازم است", nameof(value)); 20 | } 21 | Value = value; 22 | } 23 | public override int ObjectGetHashCode() => Value.GetHashCode(); 24 | public override bool ObjectIsEqual(DisplayName otherObject) => Value == otherObject.Value; 25 | 26 | public static implicit operator string(DisplayName displayName) => displayName.Value; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /01. Core/Bazzar.Core.Domain/UserProfiles/ValueObjects/FirstName.cs: -------------------------------------------------------------------------------- 1 | using Framework.Domain.ValueObjects; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Bazzar.Core.Domain.UserProfiles.ValueObjects 7 | { 8 | public class FirstName : BaseValueObject 9 | { 10 | 11 | public string Value { get; private set; } 12 | public static FirstName FromString(string value) => new FirstName(value); 13 | private FirstName() 14 | { 15 | 16 | } 17 | public FirstName(string value) 18 | { 19 | if (string.IsNullOrEmpty(value)) 20 | { 21 | throw new ArgumentException("برای نام مقدار لازم است", nameof(value)); 22 | } 23 | Value = value; 24 | } 25 | public override int ObjectGetHashCode() => Value.GetHashCode(); 26 | public override bool ObjectIsEqual(FirstName otherObject) => Value == otherObject.Value; 27 | 28 | public static implicit operator string(FirstName firstName) => firstName.Value; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /01. Core/Bazzar.Core.Domain/UserProfiles/ValueObjects/LastName.cs: -------------------------------------------------------------------------------- 1 | using Framework.Domain.ValueObjects; 2 | using System; 3 | 4 | namespace Bazzar.Core.Domain.UserProfiles.ValueObjects 5 | { 6 | public class LastName : BaseValueObject 7 | { 8 | 9 | public string Value { get; private set; } 10 | public static LastName FromString(string value) => new LastName(value); 11 | private LastName() 12 | { 13 | 14 | } 15 | public LastName(string value) 16 | { 17 | if (string.IsNullOrEmpty(value)) 18 | { 19 | throw new ArgumentException("برای نام‌خانوادگی مقدار لازم است", nameof(value)); 20 | } 21 | Value = value; 22 | } 23 | public override int ObjectGetHashCode() => Value.GetHashCode(); 24 | public override bool ObjectIsEqual(LastName otherObject) => Value == otherObject.Value; 25 | 26 | public static implicit operator string(LastName lastName) => lastName.Value; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /02. Infrastructures/Data/Bazzar.Infrastructures.Data.EventsSourcings/Bazzar.Infrastructures.Data.EventsSourcings.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.1 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /02. Infrastructures/Data/Bazzar.Infrastructures.Data.EventsSourcings/BazzarEventSource.cs: -------------------------------------------------------------------------------- 1 | using EventStore.ClientAPI; 2 | using Framework.Domain.Data; 3 | using Framework.Domain.Events; 4 | using Newtonsoft.Json; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Text; 9 | 10 | namespace Bazzar.Infrastructures.Data.EventsSourcings 11 | { 12 | public class BazzarEventSource : IEventSource 13 | { 14 | private readonly IEventStoreConnection _connection; 15 | public BazzarEventSource(IEventStoreConnection connection) 16 | { 17 | _connection = connection; 18 | _connection.ConnectAsync().Wait(); 19 | } 20 | public void Save(string aggregateName, string streamId, IEnumerable events) 21 | where TEvent : IEvent 22 | { 23 | if (!events.Any()) return; 24 | var changes = events 25 | .Select(@event => 26 | new EventData( 27 | eventId: Guid.NewGuid(), 28 | type: @event.GetType().Name, 29 | isJson: true, 30 | data: Serialize(@event), 31 | metadata: Serialize(new EventMetadata 32 | { ClrType = @event.GetType().AssemblyQualifiedName }) 33 | )) 34 | .ToArray(); 35 | if (!changes.Any()) return; 36 | var streamName = $"{aggregateName} - {streamId}"; 37 | _connection.AppendToStreamAsync( 38 | streamName, 39 | ExpectedVersion.Any, 40 | changes).Wait(); 41 | } 42 | 43 | private static byte[] Serialize(object data) => Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(data)); 44 | } 45 | internal class EventMetadata 46 | { 47 | public string ClrType { get; set; } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /02. Infrastructures/Data/Bazzar.Infrastructures.Data.EventsSourcings/Class1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Bazzar.Infrastructures.Data.EventsSourcings 4 | { 5 | public class Class1 6 | { 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /02. Infrastructures/Data/Bazzar.Infrastructures.Data.Fake/Advertisments/FakeAdvertisementsRepository.cs: -------------------------------------------------------------------------------- 1 | using Bazzar.Core.Domain.Advertisements.Data; 2 | using Bazzar.Core.Domain.Advertisements.Entities; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace Bazzar.Infrastructures.Data.Fake.Advertisments 8 | { 9 | public class FakeAdvertisementsRepository : IAdvertisementsRepository 10 | { 11 | private readonly Dictionary db = new Dictionary(); 12 | public bool Exists(Guid id) 13 | { 14 | return db.ContainsKey(id); 15 | } 16 | 17 | public Advertisment Load(Guid id) 18 | { 19 | return db[id]; 20 | } 21 | 22 | public void Add(Advertisment entity) 23 | { 24 | db[entity.Id] = entity; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /02. Infrastructures/Data/Bazzar.Infrastructures.Data.Fake/Bazzar.Infrastructures.Data.Fake.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.1 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /02. Infrastructures/Data/Bazzar.Infrastructures.Data.Fake/Class1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Bazzar.Infrastructures.Data.Fake 4 | { 5 | public class Class1 6 | { 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /02. Infrastructures/Data/Bazzar.Infrastructures.Data.SqlServer/AdvertismentDbContext.cs: -------------------------------------------------------------------------------- 1 | using Bazzar.Core.Domain.Advertisements.Entities; 2 | using Bazzar.Core.Domain.UserProfiles.Entities; 3 | using Microsoft.EntityFrameworkCore; 4 | using System; 5 | using System.Diagnostics.CodeAnalysis; 6 | 7 | namespace Bazzar.Infrastructures.Data.SqlServer 8 | { 9 | public class AdvertismentDbContext : DbContext 10 | { 11 | public AdvertismentDbContext([NotNull] DbContextOptions options) : base(options) 12 | { 13 | } 14 | 15 | protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) 16 | { 17 | 18 | } 19 | protected override void OnModelCreating(ModelBuilder modelBuilder) 20 | { 21 | modelBuilder.ApplyConfigurationsFromAssembly(GetType().Assembly); 22 | 23 | } 24 | 25 | public DbSet Advertisments { get; set; } 26 | public DbSet UserProfiles { get; set; } 27 | 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /02. Infrastructures/Data/Bazzar.Infrastructures.Data.SqlServer/AdvertismentUnitOfWork.cs: -------------------------------------------------------------------------------- 1 | using Framework.Domain.Data; 2 | using Framework.Domain.Entieis; 3 | using Microsoft.EntityFrameworkCore; 4 | using Microsoft.EntityFrameworkCore.ChangeTracking; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | 9 | namespace Bazzar.Infrastructures.Data.SqlServer 10 | { 11 | public class AdvertismentUnitOfWork : IUnitOfWork 12 | { 13 | private readonly AdvertismentDbContext advertismentDbContext; 14 | private readonly IEventSource eventSource; 15 | 16 | public AdvertismentUnitOfWork(AdvertismentDbContext advertismentDbContext, IEventSource eventSource) 17 | { 18 | this.advertismentDbContext = advertismentDbContext; 19 | this.eventSource = eventSource; 20 | } 21 | public int Commit() 22 | { 23 | var entityForSave = GetEntityForSave(); 24 | int result = advertismentDbContext.SaveChanges(); 25 | SaveEvents(entityForSave); 26 | return result; 27 | } 28 | 29 | private void SaveEvents(List entityForSave) 30 | { 31 | foreach (var item in entityForSave) 32 | { 33 | var root = item.Entity as BaseAggregateRoot; 34 | if (root != null) 35 | { 36 | var id = root.Id.ToString(); 37 | var aggName = item.Entity.GetType().FullName; 38 | eventSource.Save(aggName, id, root.GetEvents()); 39 | } 40 | } 41 | } 42 | 43 | private List GetEntityForSave() 44 | { 45 | return advertismentDbContext.ChangeTracker 46 | .Entries() 47 | .Where(x => x.State == EntityState.Modified || x.State == EntityState.Added || x.State == EntityState.Deleted) 48 | .ToList(); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /02. Infrastructures/Data/Bazzar.Infrastructures.Data.SqlServer/Advertisments/AdvertisementQueryService.cs: -------------------------------------------------------------------------------- 1 | using Bazzar.Core.Domain.Advertisements.Data; 2 | using Bazzar.Core.Domain.Advertisements.Dtoes; 3 | using Bazzar.Core.Domain.Advertisements.Queries; 4 | using Dapper; 5 | using Microsoft.Data.SqlClient; 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Text; 9 | 10 | namespace Bazzar.Infrastructures.Data.SqlServer.Advertisments 11 | { 12 | public class AdvertisementQueryService : IAdvertisementQueryService 13 | { 14 | private readonly SqlConnection sqlConnection; 15 | 16 | public AdvertisementQueryService(SqlConnection sqlConnection) 17 | { 18 | this.sqlConnection = sqlConnection; 19 | } 20 | public AdvertisementDetail Query(GetActiveAdvertisement query) 21 | { 22 | string sqlQuery = "Select Top 1 a.Id as 'AdvertisementId'," + 23 | " a.Title,a.Text,p.Location as 'photoUrls', up.DisplayName as 'SellersDisplayName' " + 24 | " FROM Advertisments a " + 25 | " Inner Join Picture p on a.Id = p.AdvertismentId " + 26 | " Inner Join UserProfiles up on a.OwnerId = up.Id" + 27 | " Where State = 2 and " + 28 | " a.Id = @AdvertisementId " + 29 | " Order By p.[Order]"; 30 | return sqlConnection.QuerySingleOrDefault(sqlQuery, new { query.AdvertisementId }); 31 | } 32 | 33 | public AdvertisementSummary Query(GetActiveAdvertisementList query) 34 | { 35 | throw new NotImplementedException(); 36 | } 37 | 38 | public AdvertisementSummary Query(GetAdvertisementForSpecificSeller query) 39 | { 40 | throw new NotImplementedException(); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /02. Infrastructures/Data/Bazzar.Infrastructures.Data.SqlServer/Advertisments/AdvertismentConfig.cs: -------------------------------------------------------------------------------- 1 | using Bazzar.Core.Domain.Advertisements.Entities; 2 | using Bazzar.Core.Domain.Advertisements.ValueObjects; 3 | using Microsoft.EntityFrameworkCore; 4 | using Microsoft.EntityFrameworkCore.Metadata.Builders; 5 | 6 | namespace Bazzar.Infrastructures.Data.SqlServer.Advertisments 7 | { 8 | public class AdvertismentConfig : IEntityTypeConfiguration 9 | { 10 | public void Configure(EntityTypeBuilder builder) 11 | { 12 | builder.Property(c => c.Price).HasConversion(c => c.Value.Value, d => Price.FromLong(d)); 13 | builder.Property(c => c.OwnerId).HasConversion(c => c.Value.ToString(), d => UserId.FromString(d)); 14 | builder.Property(c => c.ApprovedBy).HasConversion(c => c.Value.ToString(), d => UserId.FromString(d)); 15 | builder.Property(c => c.Text).HasConversion(c => c.Value, d => AdvertismentText.FromString(d)); 16 | builder.Property(c => c.Title).HasConversion(c => c.Value, d => AdvertismentTitle.FromString(d)); 17 | } 18 | } 19 | public class PictureConfig : IEntityTypeConfiguration 20 | { 21 | public void Configure(EntityTypeBuilder builder) 22 | { 23 | builder.Property(c => c.Location).HasConversion(c => c.Url, d => PictureUrl.FromString(d)); 24 | builder.OwnsOne(c => c.Size); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /02. Infrastructures/Data/Bazzar.Infrastructures.Data.SqlServer/Advertisments/EfAdvertisementsRepository.cs: -------------------------------------------------------------------------------- 1 | using Bazzar.Core.Domain.Advertisements.Data; 2 | using Bazzar.Core.Domain.Advertisements.Entities; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace Bazzar.Infrastructures.Data.SqlServer.Advertisments 9 | { 10 | public class EfAdvertisementsRepository : IAdvertisementsRepository, IDisposable 11 | { 12 | private readonly AdvertismentDbContext advertismentDbContext; 13 | 14 | public EfAdvertisementsRepository(AdvertismentDbContext advertismentDbContext) 15 | { 16 | this.advertismentDbContext = advertismentDbContext; 17 | } 18 | 19 | public void Dispose() 20 | { 21 | advertismentDbContext.Dispose(); 22 | } 23 | 24 | public bool Exists(Guid id) 25 | { 26 | return advertismentDbContext.Advertisments.Any(c => c.Id == id); 27 | } 28 | 29 | public Advertisment Load(Guid id) 30 | { 31 | return advertismentDbContext.Advertisments.Find(id); 32 | } 33 | 34 | public void Add(Advertisment entity) 35 | { 36 | advertismentDbContext.Advertisments.Add(entity); 37 | 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /02. Infrastructures/Data/Bazzar.Infrastructures.Data.SqlServer/Bazzar.Infrastructures.Data.SqlServer.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.1 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /02. Infrastructures/Data/Bazzar.Infrastructures.Data.SqlServer/Migrations/20191011115726_init.Designer.cs: -------------------------------------------------------------------------------- 1 | // 2 | using System; 3 | using Bazzar.Infrastructures.Data.SqlServer; 4 | using Microsoft.EntityFrameworkCore; 5 | using Microsoft.EntityFrameworkCore.Infrastructure; 6 | using Microsoft.EntityFrameworkCore.Metadata; 7 | using Microsoft.EntityFrameworkCore.Migrations; 8 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion; 9 | 10 | namespace Bazzar.Infrastructures.Data.SqlServer.Migrations 11 | { 12 | [DbContext(typeof(AdvertismentDbContext))] 13 | [Migration("20191011115726_init")] 14 | partial class init 15 | { 16 | protected override void BuildTargetModel(ModelBuilder modelBuilder) 17 | { 18 | #pragma warning disable 612, 618 19 | modelBuilder 20 | .HasAnnotation("ProductVersion", "3.0.0") 21 | .HasAnnotation("Relational:MaxIdentifierLength", 128) 22 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 23 | 24 | modelBuilder.Entity("Bazzar.Core.Domain.Advertisements.Entities.Advertisment", b => 25 | { 26 | b.Property("Id") 27 | .ValueGeneratedOnAdd() 28 | .HasColumnType("uniqueidentifier"); 29 | 30 | b.Property("ApprovedBy") 31 | .HasColumnType("nvarchar(max)"); 32 | 33 | b.Property("OwnerId") 34 | .HasColumnType("nvarchar(max)"); 35 | 36 | b.Property("Price") 37 | .HasColumnType("bigint"); 38 | 39 | b.Property("State") 40 | .HasColumnType("int"); 41 | 42 | b.Property("Text") 43 | .HasColumnType("nvarchar(max)"); 44 | 45 | b.Property("Title") 46 | .HasColumnType("nvarchar(max)"); 47 | 48 | b.HasKey("Id"); 49 | 50 | b.ToTable("Advertisments"); 51 | }); 52 | #pragma warning restore 612, 618 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /02. Infrastructures/Data/Bazzar.Infrastructures.Data.SqlServer/Migrations/20191011115726_init.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.EntityFrameworkCore.Migrations; 3 | 4 | namespace Bazzar.Infrastructures.Data.SqlServer.Migrations 5 | { 6 | public partial class init : Migration 7 | { 8 | protected override void Up(MigrationBuilder migrationBuilder) 9 | { 10 | migrationBuilder.CreateTable( 11 | name: "Advertisments", 12 | columns: table => new 13 | { 14 | Id = table.Column(nullable: false), 15 | OwnerId = table.Column(nullable: true), 16 | ApprovedBy = table.Column(nullable: true), 17 | Title = table.Column(nullable: true), 18 | Text = table.Column(nullable: true), 19 | Price = table.Column(nullable: true), 20 | State = table.Column(nullable: false) 21 | }, 22 | constraints: table => 23 | { 24 | table.PrimaryKey("PK_Advertisments", x => x.Id); 25 | }); 26 | } 27 | 28 | protected override void Down(MigrationBuilder migrationBuilder) 29 | { 30 | migrationBuilder.DropTable( 31 | name: "Advertisments"); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /02. Infrastructures/Data/Bazzar.Infrastructures.Data.SqlServer/Migrations/20191011121433_add-pictures.Designer.cs: -------------------------------------------------------------------------------- 1 | // 2 | using System; 3 | using Bazzar.Infrastructures.Data.SqlServer; 4 | using Microsoft.EntityFrameworkCore; 5 | using Microsoft.EntityFrameworkCore.Infrastructure; 6 | using Microsoft.EntityFrameworkCore.Metadata; 7 | using Microsoft.EntityFrameworkCore.Migrations; 8 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion; 9 | 10 | namespace Bazzar.Infrastructures.Data.SqlServer.Migrations 11 | { 12 | [DbContext(typeof(AdvertismentDbContext))] 13 | [Migration("20191011121433_add-pictures")] 14 | partial class addpictures 15 | { 16 | protected override void BuildTargetModel(ModelBuilder modelBuilder) 17 | { 18 | #pragma warning disable 612, 618 19 | modelBuilder 20 | .HasAnnotation("ProductVersion", "3.0.0") 21 | .HasAnnotation("Relational:MaxIdentifierLength", 128) 22 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 23 | 24 | modelBuilder.Entity("Bazzar.Core.Domain.Advertisements.Entities.Advertisment", b => 25 | { 26 | b.Property("Id") 27 | .ValueGeneratedOnAdd() 28 | .HasColumnType("uniqueidentifier"); 29 | 30 | b.Property("ApprovedBy") 31 | .HasColumnType("nvarchar(max)"); 32 | 33 | b.Property("OwnerId") 34 | .HasColumnType("nvarchar(max)"); 35 | 36 | b.Property("Price") 37 | .HasColumnType("bigint"); 38 | 39 | b.Property("State") 40 | .HasColumnType("int"); 41 | 42 | b.Property("Text") 43 | .HasColumnType("nvarchar(max)"); 44 | 45 | b.Property("Title") 46 | .HasColumnType("nvarchar(max)"); 47 | 48 | b.HasKey("Id"); 49 | 50 | b.ToTable("Advertisments"); 51 | }); 52 | 53 | modelBuilder.Entity("Bazzar.Core.Domain.Advertisements.Entities.Picture", b => 54 | { 55 | b.Property("Id") 56 | .ValueGeneratedOnAdd() 57 | .HasColumnType("uniqueidentifier"); 58 | 59 | b.Property("AdvertismentId") 60 | .HasColumnType("uniqueidentifier"); 61 | 62 | b.Property("Location") 63 | .HasColumnType("nvarchar(max)"); 64 | 65 | b.Property("Order") 66 | .HasColumnType("int"); 67 | 68 | b.HasKey("Id"); 69 | 70 | b.HasIndex("AdvertismentId"); 71 | 72 | b.ToTable("Picture"); 73 | }); 74 | 75 | modelBuilder.Entity("Bazzar.Core.Domain.Advertisements.Entities.Picture", b => 76 | { 77 | b.HasOne("Bazzar.Core.Domain.Advertisements.Entities.Advertisment", null) 78 | .WithMany("Pictures") 79 | .HasForeignKey("AdvertismentId"); 80 | 81 | b.OwnsOne("Bazzar.Core.Domain.Advertisements.ValueObjects.PictureSize", "Size", b1 => 82 | { 83 | b1.Property("PictureId") 84 | .HasColumnType("uniqueidentifier"); 85 | 86 | b1.Property("Height") 87 | .HasColumnType("int"); 88 | 89 | b1.Property("Width") 90 | .HasColumnType("int"); 91 | 92 | b1.HasKey("PictureId"); 93 | 94 | b1.ToTable("Picture"); 95 | 96 | b1.WithOwner() 97 | .HasForeignKey("PictureId"); 98 | }); 99 | }); 100 | #pragma warning restore 612, 618 101 | } 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /02. Infrastructures/Data/Bazzar.Infrastructures.Data.SqlServer/Migrations/20191011121433_add-pictures.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.EntityFrameworkCore.Migrations; 3 | 4 | namespace Bazzar.Infrastructures.Data.SqlServer.Migrations 5 | { 6 | public partial class addpictures : Migration 7 | { 8 | protected override void Up(MigrationBuilder migrationBuilder) 9 | { 10 | migrationBuilder.CreateTable( 11 | name: "Picture", 12 | columns: table => new 13 | { 14 | Id = table.Column(nullable: false), 15 | Size_Height = table.Column(nullable: true), 16 | Size_Width = table.Column(nullable: true), 17 | Location = table.Column(nullable: true), 18 | Order = table.Column(nullable: false), 19 | AdvertismentId = table.Column(nullable: true) 20 | }, 21 | constraints: table => 22 | { 23 | table.PrimaryKey("PK_Picture", x => x.Id); 24 | table.ForeignKey( 25 | name: "FK_Picture_Advertisments_AdvertismentId", 26 | column: x => x.AdvertismentId, 27 | principalTable: "Advertisments", 28 | principalColumn: "Id", 29 | onDelete: ReferentialAction.Restrict); 30 | }); 31 | 32 | migrationBuilder.CreateIndex( 33 | name: "IX_Picture_AdvertismentId", 34 | table: "Picture", 35 | column: "AdvertismentId"); 36 | } 37 | 38 | protected override void Down(MigrationBuilder migrationBuilder) 39 | { 40 | migrationBuilder.DropTable( 41 | name: "Picture"); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /02. Infrastructures/Data/Bazzar.Infrastructures.Data.SqlServer/Migrations/20191011123008_add-user-profile.Designer.cs: -------------------------------------------------------------------------------- 1 | // 2 | using System; 3 | using Bazzar.Infrastructures.Data.SqlServer; 4 | using Microsoft.EntityFrameworkCore; 5 | using Microsoft.EntityFrameworkCore.Infrastructure; 6 | using Microsoft.EntityFrameworkCore.Metadata; 7 | using Microsoft.EntityFrameworkCore.Migrations; 8 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion; 9 | 10 | namespace Bazzar.Infrastructures.Data.SqlServer.Migrations 11 | { 12 | [DbContext(typeof(AdvertismentDbContext))] 13 | [Migration("20191011123008_add-user-profile")] 14 | partial class adduserprofile 15 | { 16 | protected override void BuildTargetModel(ModelBuilder modelBuilder) 17 | { 18 | #pragma warning disable 612, 618 19 | modelBuilder 20 | .HasAnnotation("ProductVersion", "3.0.0") 21 | .HasAnnotation("Relational:MaxIdentifierLength", 128) 22 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 23 | 24 | modelBuilder.Entity("Bazzar.Core.Domain.Advertisements.Entities.Advertisment", b => 25 | { 26 | b.Property("Id") 27 | .ValueGeneratedOnAdd() 28 | .HasColumnType("uniqueidentifier"); 29 | 30 | b.Property("ApprovedBy") 31 | .HasColumnType("nvarchar(max)"); 32 | 33 | b.Property("OwnerId") 34 | .HasColumnType("nvarchar(max)"); 35 | 36 | b.Property("Price") 37 | .HasColumnType("bigint"); 38 | 39 | b.Property("State") 40 | .HasColumnType("int"); 41 | 42 | b.Property("Text") 43 | .HasColumnType("nvarchar(max)"); 44 | 45 | b.Property("Title") 46 | .HasColumnType("nvarchar(max)"); 47 | 48 | b.HasKey("Id"); 49 | 50 | b.ToTable("Advertisments"); 51 | }); 52 | 53 | modelBuilder.Entity("Bazzar.Core.Domain.Advertisements.Entities.Picture", b => 54 | { 55 | b.Property("Id") 56 | .ValueGeneratedOnAdd() 57 | .HasColumnType("uniqueidentifier"); 58 | 59 | b.Property("AdvertismentId") 60 | .HasColumnType("uniqueidentifier"); 61 | 62 | b.Property("Location") 63 | .HasColumnType("nvarchar(max)"); 64 | 65 | b.Property("Order") 66 | .HasColumnType("int"); 67 | 68 | b.HasKey("Id"); 69 | 70 | b.HasIndex("AdvertismentId"); 71 | 72 | b.ToTable("Picture"); 73 | }); 74 | 75 | modelBuilder.Entity("Bazzar.Core.Domain.UserProfiles.Entities.UserProfile", b => 76 | { 77 | b.Property("Id") 78 | .ValueGeneratedOnAdd() 79 | .HasColumnType("uniqueidentifier"); 80 | 81 | b.Property("DisplayName") 82 | .HasColumnType("nvarchar(max)"); 83 | 84 | b.Property("Email") 85 | .HasColumnType("nvarchar(max)"); 86 | 87 | b.Property("FirstName") 88 | .HasColumnType("nvarchar(max)"); 89 | 90 | b.Property("LastName") 91 | .HasColumnType("nvarchar(max)"); 92 | 93 | b.HasKey("Id"); 94 | 95 | b.ToTable("UserProfiles"); 96 | }); 97 | 98 | modelBuilder.Entity("Bazzar.Core.Domain.Advertisements.Entities.Picture", b => 99 | { 100 | b.HasOne("Bazzar.Core.Domain.Advertisements.Entities.Advertisment", null) 101 | .WithMany("Pictures") 102 | .HasForeignKey("AdvertismentId"); 103 | 104 | b.OwnsOne("Bazzar.Core.Domain.Advertisements.ValueObjects.PictureSize", "Size", b1 => 105 | { 106 | b1.Property("PictureId") 107 | .HasColumnType("uniqueidentifier"); 108 | 109 | b1.Property("Height") 110 | .HasColumnType("int"); 111 | 112 | b1.Property("Width") 113 | .HasColumnType("int"); 114 | 115 | b1.HasKey("PictureId"); 116 | 117 | b1.ToTable("Picture"); 118 | 119 | b1.WithOwner() 120 | .HasForeignKey("PictureId"); 121 | }); 122 | }); 123 | #pragma warning restore 612, 618 124 | } 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /02. Infrastructures/Data/Bazzar.Infrastructures.Data.SqlServer/Migrations/20191011123008_add-user-profile.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.EntityFrameworkCore.Migrations; 3 | 4 | namespace Bazzar.Infrastructures.Data.SqlServer.Migrations 5 | { 6 | public partial class adduserprofile : Migration 7 | { 8 | protected override void Up(MigrationBuilder migrationBuilder) 9 | { 10 | migrationBuilder.CreateTable( 11 | name: "UserProfiles", 12 | columns: table => new 13 | { 14 | Id = table.Column(nullable: false), 15 | FirstName = table.Column(nullable: true), 16 | LastName = table.Column(nullable: true), 17 | DisplayName = table.Column(nullable: true), 18 | Email = table.Column(nullable: true) 19 | }, 20 | constraints: table => 21 | { 22 | table.PrimaryKey("PK_UserProfiles", x => x.Id); 23 | }); 24 | } 25 | 26 | protected override void Down(MigrationBuilder migrationBuilder) 27 | { 28 | migrationBuilder.DropTable( 29 | name: "UserProfiles"); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /02. Infrastructures/Data/Bazzar.Infrastructures.Data.SqlServer/Migrations/AdvertismentDbContextModelSnapshot.cs: -------------------------------------------------------------------------------- 1 | // 2 | using System; 3 | using Bazzar.Infrastructures.Data.SqlServer; 4 | using Microsoft.EntityFrameworkCore; 5 | using Microsoft.EntityFrameworkCore.Infrastructure; 6 | using Microsoft.EntityFrameworkCore.Metadata; 7 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion; 8 | 9 | namespace Bazzar.Infrastructures.Data.SqlServer.Migrations 10 | { 11 | [DbContext(typeof(AdvertismentDbContext))] 12 | partial class AdvertismentDbContextModelSnapshot : ModelSnapshot 13 | { 14 | protected override void BuildModel(ModelBuilder modelBuilder) 15 | { 16 | #pragma warning disable 612, 618 17 | modelBuilder 18 | .HasAnnotation("ProductVersion", "3.0.0") 19 | .HasAnnotation("Relational:MaxIdentifierLength", 128) 20 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 21 | 22 | modelBuilder.Entity("Bazzar.Core.Domain.Advertisements.Entities.Advertisment", b => 23 | { 24 | b.Property("Id") 25 | .ValueGeneratedOnAdd() 26 | .HasColumnType("uniqueidentifier"); 27 | 28 | b.Property("ApprovedBy") 29 | .HasColumnType("nvarchar(max)"); 30 | 31 | b.Property("OwnerId") 32 | .HasColumnType("nvarchar(max)"); 33 | 34 | b.Property("Price") 35 | .HasColumnType("bigint"); 36 | 37 | b.Property("State") 38 | .HasColumnType("int"); 39 | 40 | b.Property("Text") 41 | .HasColumnType("nvarchar(max)"); 42 | 43 | b.Property("Title") 44 | .HasColumnType("nvarchar(max)"); 45 | 46 | b.HasKey("Id"); 47 | 48 | b.ToTable("Advertisments"); 49 | }); 50 | 51 | modelBuilder.Entity("Bazzar.Core.Domain.Advertisements.Entities.Picture", b => 52 | { 53 | b.Property("Id") 54 | .ValueGeneratedOnAdd() 55 | .HasColumnType("uniqueidentifier"); 56 | 57 | b.Property("AdvertismentId") 58 | .HasColumnType("uniqueidentifier"); 59 | 60 | b.Property("Location") 61 | .HasColumnType("nvarchar(max)"); 62 | 63 | b.Property("Order") 64 | .HasColumnType("int"); 65 | 66 | b.HasKey("Id"); 67 | 68 | b.HasIndex("AdvertismentId"); 69 | 70 | b.ToTable("Picture"); 71 | }); 72 | 73 | modelBuilder.Entity("Bazzar.Core.Domain.UserProfiles.Entities.UserProfile", b => 74 | { 75 | b.Property("Id") 76 | .ValueGeneratedOnAdd() 77 | .HasColumnType("uniqueidentifier"); 78 | 79 | b.Property("DisplayName") 80 | .HasColumnType("nvarchar(max)"); 81 | 82 | b.Property("Email") 83 | .HasColumnType("nvarchar(max)"); 84 | 85 | b.Property("FirstName") 86 | .HasColumnType("nvarchar(max)"); 87 | 88 | b.Property("LastName") 89 | .HasColumnType("nvarchar(max)"); 90 | 91 | b.HasKey("Id"); 92 | 93 | b.ToTable("UserProfiles"); 94 | }); 95 | 96 | modelBuilder.Entity("Bazzar.Core.Domain.Advertisements.Entities.Picture", b => 97 | { 98 | b.HasOne("Bazzar.Core.Domain.Advertisements.Entities.Advertisment", null) 99 | .WithMany("Pictures") 100 | .HasForeignKey("AdvertismentId"); 101 | 102 | b.OwnsOne("Bazzar.Core.Domain.Advertisements.ValueObjects.PictureSize", "Size", b1 => 103 | { 104 | b1.Property("PictureId") 105 | .HasColumnType("uniqueidentifier"); 106 | 107 | b1.Property("Height") 108 | .HasColumnType("int"); 109 | 110 | b1.Property("Width") 111 | .HasColumnType("int"); 112 | 113 | b1.HasKey("PictureId"); 114 | 115 | b1.ToTable("Picture"); 116 | 117 | b1.WithOwner() 118 | .HasForeignKey("PictureId"); 119 | }); 120 | }); 121 | #pragma warning restore 612, 618 122 | } 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /02. Infrastructures/Data/Bazzar.Infrastructures.Data.SqlServer/UserProfiles/EFUserProfileRepository.cs: -------------------------------------------------------------------------------- 1 | using Bazzar.Core.Domain.UserProfiles.Data; 2 | using Bazzar.Core.Domain.UserProfiles.Entities; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace Bazzar.Infrastructures.Data.SqlServer.UserProfiles 9 | { 10 | public class EFUserProfileRepository : IUserProfileRepository, IDisposable 11 | { 12 | private readonly AdvertismentDbContext advertismentDbContext; 13 | 14 | public EFUserProfileRepository(AdvertismentDbContext advertismentDbContext) 15 | { 16 | this.advertismentDbContext = advertismentDbContext; 17 | } 18 | public void Add(UserProfile entity) 19 | { 20 | advertismentDbContext.UserProfiles.Add(entity); 21 | } 22 | 23 | public void Dispose() 24 | { 25 | advertismentDbContext.Dispose(); 26 | } 27 | 28 | public bool Exists(Guid id) 29 | { 30 | return advertismentDbContext.UserProfiles.Any(c => c.Id == id); 31 | } 32 | 33 | public UserProfile Load(Guid id) 34 | { 35 | return advertismentDbContext.UserProfiles.Find(id); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /02. Infrastructures/Data/Bazzar.Infrastructures.Data.SqlServer/UserProfiles/UserProfileConfig.cs: -------------------------------------------------------------------------------- 1 | using Bazzar.Core.Domain.Shared.ValueObjects; 2 | using Bazzar.Core.Domain.UserProfiles.Entities; 3 | using Bazzar.Core.Domain.UserProfiles.ValueObjects; 4 | using Microsoft.EntityFrameworkCore; 5 | using Microsoft.EntityFrameworkCore.Metadata.Builders; 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Text; 9 | 10 | namespace Bazzar.Infrastructures.Data.SqlServer.UserProfiles 11 | { 12 | public class UserProfileConfig : IEntityTypeConfiguration 13 | { 14 | public void Configure(EntityTypeBuilder builder) 15 | { 16 | builder.Property(c => c.FirstName).HasConversion(c => c.Value, d => FirstName.FromString(d)); 17 | builder.Property(c => c.LastName).HasConversion(c => c.Value, d => LastName.FromString(d)); 18 | builder.Property(c => c.DisplayName).HasConversion(c => c.Value, d => DisplayName.FromString(d)); 19 | builder.Property(c => c.Email).HasConversion(c => c.Value, d => Email.FromString(d)); 20 | 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /03. EndPoints/Bazzar.Endpoints.API/Bazzar.Endpoints.API.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.0 5 | 6 | 7 | 8 | 9 | 10 | all 11 | runtime; build; native; contentfiles; analyzers; buildtransitive 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /03. EndPoints/Bazzar.Endpoints.API/Controllers/AddvertismentController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Bazzar.Core.ApplicationServices.Advertisements.CommandHandlers; 6 | using Bazzar.Core.Domain.Advertisements.Commands; 7 | using Microsoft.AspNetCore.Mvc; 8 | using Microsoft.Extensions.Logging; 9 | 10 | namespace Bazzar.Endpoints.API.Controllers 11 | { 12 | [ApiController] 13 | [Route("[controller]")] 14 | public class AddvertismentController : ControllerBase 15 | { 16 | 17 | 18 | [HttpPost] 19 | public IActionResult Post([FromServices] CreateHandler handler, Create request) 20 | { 21 | handler.Handle(request); 22 | return Ok(); 23 | } 24 | 25 | [Route("title")] 26 | [HttpPut] 27 | public IActionResult Put([FromServices] SetTitleHandler handler, SetTitle request) 28 | { 29 | handler.Handle(request); 30 | return Ok(); 31 | } 32 | 33 | [Route("text")] 34 | [HttpPut] 35 | public IActionResult Put([FromServices] UpdateTextHandler handler, UpdateText request) 36 | { 37 | handler.Handle(request); 38 | return Ok(); 39 | } 40 | 41 | [Route("price")] 42 | [HttpPut] 43 | public IActionResult Put([FromServices] UpdatePriceHandler handler, UpdatePrice request) 44 | { 45 | handler.Handle(request); 46 | return Ok(); 47 | } 48 | 49 | [Route("publish")] 50 | [HttpPut] 51 | public IActionResult Put([FromServices] RequestToPublishHandler handler, RequestToPublish request) 52 | { 53 | handler.Handle(request); 54 | return Ok(); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /03. EndPoints/Bazzar.Endpoints.API/Controllers/AddvertismentQueryController.cs: -------------------------------------------------------------------------------- 1 | using Bazzar.Core.Domain.Advertisements.Data; 2 | using Bazzar.Core.Domain.Advertisements.Queries; 3 | using Microsoft.AspNetCore.Mvc; 4 | 5 | // For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 6 | 7 | namespace Bazzar.EndPoints.API.Controllers 8 | { 9 | [ApiController] 10 | [Route("[controller]")] 11 | public class AddvertismentQueryController : ControllerBase 12 | { 13 | private readonly IAdvertisementQueryService advertisementQueryService; 14 | 15 | public AddvertismentQueryController(IAdvertisementQueryService advertisementQueryService) 16 | { 17 | this.advertisementQueryService = advertisementQueryService; 18 | } 19 | 20 | [HttpGet] 21 | public IActionResult Get([FromQuery]GetActiveAdvertisement request) 22 | { 23 | return new OkObjectResult(advertisementQueryService.Query(request)); 24 | } 25 | 26 | //[HttpGet] 27 | //public IActionResult Get([FromQuery]GetActiveAdvertisementList request) 28 | //{ 29 | // return new OkObjectResult(advertisementQueryService.Query(request)); 30 | //} 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /03. EndPoints/Bazzar.Endpoints.API/Controllers/UserProfileController.cs: -------------------------------------------------------------------------------- 1 | using Bazzar.Core.ApplicationServices.UserProfiles.CommandHandlers; 2 | using Bazzar.Core.Domain.UserProfiles.Commands; 3 | using Bazzar.EndPoints.API.Services; 4 | using Microsoft.AspNetCore.Mvc; 5 | 6 | // For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 7 | 8 | namespace Bazzar.EndPoints.API.Controllers 9 | { 10 | [ApiController] 11 | [Route("/profile")] 12 | public class UserProfileController : Controller 13 | { 14 | [HttpPost] 15 | public IActionResult Post([FromServices] RegisterUserHandler registerUserHandler, 16 | RegisterUser request) 17 | { 18 | return RequestHandler.HandleRequest(request, registerUserHandler.Handle); 19 | } 20 | [Route("name")] 21 | [HttpPut] 22 | public IActionResult Put([FromServices] UpdateUserNameHandler updateUserNameHandler, 23 | UpdateUserName request) 24 | { 25 | return RequestHandler.HandleRequest(request, updateUserNameHandler.Handle); 26 | } 27 | [Route("displayname")] 28 | [HttpPut] 29 | public IActionResult Put([FromServices] UpdateUserDisplayNameHandler updateUserDisplayNameHandler, 30 | UpdateUserDisplayName request) 31 | { 32 | return RequestHandler.HandleRequest(request, updateUserDisplayNameHandler.Handle); 33 | } 34 | 35 | [Route("email")] 36 | [HttpPut] 37 | public IActionResult Put([FromServices] UpdateUserEmailHandler updateUserEmailHandler, 38 | UpdateUserEmail request) 39 | { 40 | return RequestHandler.HandleRequest(request, updateUserEmailHandler.Handle); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /03. EndPoints/Bazzar.Endpoints.API/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Hosting; 6 | using Microsoft.Extensions.Configuration; 7 | using Microsoft.Extensions.Hosting; 8 | using Microsoft.Extensions.Logging; 9 | 10 | namespace Bazzar.Endpoints.API 11 | { 12 | public class Program 13 | { 14 | public static void Main(string[] args) 15 | { 16 | CreateHostBuilder(args).Build().Run(); 17 | } 18 | 19 | public static IHostBuilder CreateHostBuilder(string[] args) => 20 | Host.CreateDefaultBuilder(args) 21 | .ConfigureWebHostDefaults(webBuilder => 22 | { 23 | webBuilder.UseStartup(); 24 | }); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /03. EndPoints/Bazzar.Endpoints.API/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:53872", 8 | "sslPort": 44374 9 | } 10 | }, 11 | "profiles": { 12 | "IIS Express": { 13 | "commandName": "IISExpress", 14 | "launchBrowser": true, 15 | "launchUrl": "weatherforecast", 16 | "environmentVariables": { 17 | "ASPNETCORE_ENVIRONMENT": "Development" 18 | } 19 | }, 20 | "Bazzar.Endpoints.API": { 21 | "commandName": "Project", 22 | "launchBrowser": true, 23 | "launchUrl": "weatherforecast", 24 | "applicationUrl": "https://localhost:5001;http://localhost:5000", 25 | "environmentVariables": { 26 | "ASPNETCORE_ENVIRONMENT": "Development" 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /03. EndPoints/Bazzar.Endpoints.API/Services/RequestHandler.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using Microsoft.Extensions.Logging; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | 8 | namespace Bazzar.EndPoints.API.Services 9 | { 10 | public static class RequestHandler 11 | { 12 | public static IActionResult HandleRequest(T request, Action handler) 13 | { 14 | try 15 | { 16 | //LogStart 17 | handler(request); 18 | return new OkResult(); 19 | } 20 | catch (Exception e) 21 | { 22 | //Log Exception 23 | return new BadRequestObjectResult(new 24 | { 25 | error = 26 | e.Message, 27 | stackTrace = e.StackTrace 28 | }); 29 | } 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /03. EndPoints/Bazzar.Endpoints.API/Startup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Bazzar.Core.ApplicationServices.Advertisements.CommandHandlers; 6 | using Bazzar.Core.ApplicationServices.UserProfiles.CommandHandlers; 7 | using Bazzar.Core.Domain.Advertisements.Data; 8 | using Bazzar.Core.Domain.UserProfiles.Data; 9 | using Bazzar.Infrastructures.Data.EventsSourcings; 10 | using Bazzar.Infrastructures.Data.Fake.Advertisments; 11 | using Bazzar.Infrastructures.Data.SqlServer; 12 | using Bazzar.Infrastructures.Data.SqlServer.Advertisments; 13 | using Bazzar.Infrastructures.Data.SqlServer.UserProfiles; 14 | using EventStore.ClientAPI; 15 | using Framework.Domain.Data; 16 | using Microsoft.AspNetCore.Builder; 17 | using Microsoft.AspNetCore.Hosting; 18 | using Microsoft.AspNetCore.HttpsPolicy; 19 | using Microsoft.AspNetCore.Mvc; 20 | using Microsoft.Data.SqlClient; 21 | using Microsoft.EntityFrameworkCore; 22 | using Microsoft.Extensions.Configuration; 23 | using Microsoft.Extensions.DependencyInjection; 24 | using Microsoft.Extensions.Hosting; 25 | using Microsoft.Extensions.Logging; 26 | using Microsoft.OpenApi.Models; 27 | 28 | namespace Bazzar.Endpoints.API 29 | { 30 | public class Startup 31 | { 32 | public Startup(IWebHostEnvironment environment, IConfiguration configuration) 33 | { 34 | Configuration = configuration; 35 | Environment = environment; 36 | } 37 | private IWebHostEnvironment Environment { get; } 38 | public IConfiguration Configuration { get; } 39 | 40 | // This method gets called by the runtime. Use this method to add services to the container. 41 | public void ConfigureServices(IServiceCollection services) 42 | { 43 | services.AddControllers(); 44 | 45 | var esConnection = EventStoreConnection.Create(Configuration["EventStore:ConnectionString"], ConnectionSettings.Create().KeepReconnecting(), Environment.ApplicationName); 46 | var store = new BazzarEventSource(esConnection); 47 | services.AddSingleton(esConnection); 48 | services.AddSingleton(store); 49 | 50 | services.AddScoped(); 51 | services.AddScoped(); 52 | services.AddScoped(); 53 | services.AddScoped(c => new SqlConnection(Configuration.GetConnectionString("AddvertismentCnn"))); 54 | services.AddScoped(); 55 | 56 | services.AddDbContext(c => c.UseSqlServer(Configuration.GetConnectionString("AddvertismentCnn"))); 57 | 58 | services.AddScoped(); 59 | services.AddScoped(); 60 | services.AddScoped(); 61 | services.AddScoped(); 62 | services.AddScoped(); 63 | 64 | services.AddScoped(); 65 | services.AddScoped(); 66 | services.AddScoped(); 67 | services.AddScoped(); 68 | 69 | services.AddSwaggerGen(c => 70 | { 71 | c.SwaggerDoc("v1", new OpenApiInfo { Title = "Advertisment", Version = "v1" }); 72 | }); 73 | } 74 | 75 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 76 | public void Configure(IApplicationBuilder app, IWebHostEnvironment env) 77 | { 78 | if (env.IsDevelopment()) 79 | { 80 | app.UseDeveloperExceptionPage(); 81 | } 82 | 83 | app.UseHttpsRedirection(); 84 | 85 | app.UseRouting(); 86 | app.UseSwagger(); 87 | app.UseSwaggerUI(c => 88 | { 89 | c.SwaggerEndpoint("/swagger/v1/swagger.json", "Advertisment API V1"); 90 | }); 91 | 92 | app.UseEndpoints(endpoints => 93 | { 94 | endpoints.MapControllers(); 95 | }); 96 | } 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /03. EndPoints/Bazzar.Endpoints.API/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Debug", 5 | "System": "Information", 6 | "Microsoft": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /03. EndPoints/Bazzar.Endpoints.API/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "ConnectionStrings": { 3 | "AddvertismentCnn": "Server = .; Database=AddvertismentDb2;Integrated Security=true" 4 | }, 5 | "EventStore": { 6 | "ConnectionString": "ConnectTo=tcp://admin:changeit@localhost:1113; DefaultUserCredentials=admin:changeit;" 7 | }, 8 | "Logging": { 9 | "LogLevel": { 10 | "Default": "Information", 11 | "Microsoft": "Warning", 12 | "Microsoft.Hosting.Lifetime": "Information" 13 | } 14 | }, 15 | "AllowedHosts": "*" 16 | } 17 | -------------------------------------------------------------------------------- /BazzarClass.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.29409.12 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "01. Core", "01. Core", "{E7ACF836-8B97-43D2-8652-9FE722BBD263}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bazzar.Core.Domain", "01. Core\Bazzar.Core.Domain\Bazzar.Core.Domain.csproj", "{4CEDEF98-12EE-4407-ABD7-A75FF5F3AE23}" 9 | EndProject 10 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "00. Framework", "00. Framework", "{7C2A3989-579C-4824-AADD-D9211649E072}" 11 | EndProject 12 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Framework.Domain", "00. Framework\Framework.Domain\Framework.Domain.csproj", "{0DC98FA2-6491-4704-9326-E7E458100E71}" 13 | EndProject 14 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "02. Infrastructures", "02. Infrastructures", "{72A51CF9-0C62-411E-9709-7287B8D8E003}" 15 | EndProject 16 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "03. EndPoints", "03. EndPoints", "{FB6C3223-B4D2-48F9-8086-1846493537A6}" 17 | EndProject 18 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bazzar.Endpoints.API", "03. EndPoints\Bazzar.Endpoints.API\Bazzar.Endpoints.API.csproj", "{798A5180-8BA3-4AAB-A1C0-79F15DDF770D}" 19 | EndProject 20 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Framework.Tools", "00. Framework\Framework.Tools\Framework.Tools.csproj", "{2703AE5F-B905-40B6-A2FA-13BFB9BA26D9}" 21 | EndProject 22 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bazzar.Core.ApplicationServices", "01. Core\Bazzar.Core.ApplicationServices\Bazzar.Core.ApplicationServices.csproj", "{06731471-DB69-41D3-96A7-E5B1BE615FE6}" 23 | EndProject 24 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bazzar.Infrastructures.Data.Fake", "02. Infrastructures\Data\Bazzar.Infrastructures.Data.Fake\Bazzar.Infrastructures.Data.Fake.csproj", "{CCD6FAD7-43DB-417D-B938-88D6E0670B7D}" 25 | EndProject 26 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bazzar.Infrastructures.Data.SqlServer", "02. Infrastructures\Data\Bazzar.Infrastructures.Data.SqlServer\Bazzar.Infrastructures.Data.SqlServer.csproj", "{7E71680D-2370-4C48-958A-BB012FD3FF4B}" 27 | EndProject 28 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Data", "Data", "{6596C4A6-1D34-49DE-8BA8-DCF1862025DA}" 29 | EndProject 30 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bazzar.Infrastructures.Data.EventsSourcings", "02. Infrastructures\Data\Bazzar.Infrastructures.Data.EventsSourcings\Bazzar.Infrastructures.Data.EventsSourcings.csproj", "{4EF5D70A-71DC-4EA1-B6DB-6446C70CCCC8}" 31 | EndProject 32 | Global 33 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 34 | Debug|Any CPU = Debug|Any CPU 35 | Release|Any CPU = Release|Any CPU 36 | EndGlobalSection 37 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 38 | {4CEDEF98-12EE-4407-ABD7-A75FF5F3AE23}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 39 | {4CEDEF98-12EE-4407-ABD7-A75FF5F3AE23}.Debug|Any CPU.Build.0 = Debug|Any CPU 40 | {4CEDEF98-12EE-4407-ABD7-A75FF5F3AE23}.Release|Any CPU.ActiveCfg = Release|Any CPU 41 | {4CEDEF98-12EE-4407-ABD7-A75FF5F3AE23}.Release|Any CPU.Build.0 = Release|Any CPU 42 | {0DC98FA2-6491-4704-9326-E7E458100E71}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 43 | {0DC98FA2-6491-4704-9326-E7E458100E71}.Debug|Any CPU.Build.0 = Debug|Any CPU 44 | {0DC98FA2-6491-4704-9326-E7E458100E71}.Release|Any CPU.ActiveCfg = Release|Any CPU 45 | {0DC98FA2-6491-4704-9326-E7E458100E71}.Release|Any CPU.Build.0 = Release|Any CPU 46 | {798A5180-8BA3-4AAB-A1C0-79F15DDF770D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 47 | {798A5180-8BA3-4AAB-A1C0-79F15DDF770D}.Debug|Any CPU.Build.0 = Debug|Any CPU 48 | {798A5180-8BA3-4AAB-A1C0-79F15DDF770D}.Release|Any CPU.ActiveCfg = Release|Any CPU 49 | {798A5180-8BA3-4AAB-A1C0-79F15DDF770D}.Release|Any CPU.Build.0 = Release|Any CPU 50 | {2703AE5F-B905-40B6-A2FA-13BFB9BA26D9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 51 | {2703AE5F-B905-40B6-A2FA-13BFB9BA26D9}.Debug|Any CPU.Build.0 = Debug|Any CPU 52 | {2703AE5F-B905-40B6-A2FA-13BFB9BA26D9}.Release|Any CPU.ActiveCfg = Release|Any CPU 53 | {2703AE5F-B905-40B6-A2FA-13BFB9BA26D9}.Release|Any CPU.Build.0 = Release|Any CPU 54 | {06731471-DB69-41D3-96A7-E5B1BE615FE6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 55 | {06731471-DB69-41D3-96A7-E5B1BE615FE6}.Debug|Any CPU.Build.0 = Debug|Any CPU 56 | {06731471-DB69-41D3-96A7-E5B1BE615FE6}.Release|Any CPU.ActiveCfg = Release|Any CPU 57 | {06731471-DB69-41D3-96A7-E5B1BE615FE6}.Release|Any CPU.Build.0 = Release|Any CPU 58 | {CCD6FAD7-43DB-417D-B938-88D6E0670B7D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 59 | {CCD6FAD7-43DB-417D-B938-88D6E0670B7D}.Debug|Any CPU.Build.0 = Debug|Any CPU 60 | {CCD6FAD7-43DB-417D-B938-88D6E0670B7D}.Release|Any CPU.ActiveCfg = Release|Any CPU 61 | {CCD6FAD7-43DB-417D-B938-88D6E0670B7D}.Release|Any CPU.Build.0 = Release|Any CPU 62 | {7E71680D-2370-4C48-958A-BB012FD3FF4B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 63 | {7E71680D-2370-4C48-958A-BB012FD3FF4B}.Debug|Any CPU.Build.0 = Debug|Any CPU 64 | {7E71680D-2370-4C48-958A-BB012FD3FF4B}.Release|Any CPU.ActiveCfg = Release|Any CPU 65 | {7E71680D-2370-4C48-958A-BB012FD3FF4B}.Release|Any CPU.Build.0 = Release|Any CPU 66 | {4EF5D70A-71DC-4EA1-B6DB-6446C70CCCC8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 67 | {4EF5D70A-71DC-4EA1-B6DB-6446C70CCCC8}.Debug|Any CPU.Build.0 = Debug|Any CPU 68 | {4EF5D70A-71DC-4EA1-B6DB-6446C70CCCC8}.Release|Any CPU.ActiveCfg = Release|Any CPU 69 | {4EF5D70A-71DC-4EA1-B6DB-6446C70CCCC8}.Release|Any CPU.Build.0 = Release|Any CPU 70 | EndGlobalSection 71 | GlobalSection(SolutionProperties) = preSolution 72 | HideSolutionNode = FALSE 73 | EndGlobalSection 74 | GlobalSection(NestedProjects) = preSolution 75 | {4CEDEF98-12EE-4407-ABD7-A75FF5F3AE23} = {E7ACF836-8B97-43D2-8652-9FE722BBD263} 76 | {0DC98FA2-6491-4704-9326-E7E458100E71} = {7C2A3989-579C-4824-AADD-D9211649E072} 77 | {798A5180-8BA3-4AAB-A1C0-79F15DDF770D} = {FB6C3223-B4D2-48F9-8086-1846493537A6} 78 | {2703AE5F-B905-40B6-A2FA-13BFB9BA26D9} = {7C2A3989-579C-4824-AADD-D9211649E072} 79 | {06731471-DB69-41D3-96A7-E5B1BE615FE6} = {E7ACF836-8B97-43D2-8652-9FE722BBD263} 80 | {CCD6FAD7-43DB-417D-B938-88D6E0670B7D} = {6596C4A6-1D34-49DE-8BA8-DCF1862025DA} 81 | {7E71680D-2370-4C48-958A-BB012FD3FF4B} = {6596C4A6-1D34-49DE-8BA8-DCF1862025DA} 82 | {6596C4A6-1D34-49DE-8BA8-DCF1862025DA} = {72A51CF9-0C62-411E-9709-7287B8D8E003} 83 | {4EF5D70A-71DC-4EA1-B6DB-6446C70CCCC8} = {6596C4A6-1D34-49DE-8BA8-DCF1862025DA} 84 | EndGlobalSection 85 | GlobalSection(ExtensibilityGlobals) = postSolution 86 | SolutionGuid = {4286AC54-4421-4FF1-977A-98D08EC70C68} 87 | EndGlobalSection 88 | EndGlobal 89 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | BazzarClass 2 | --------------------------------------------------------------------------------