diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..86c2143 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,13 @@ +# These are supported funding model platforms + +github: [muratbaseren] +# patreon: # Replace with a single Patreon username +# open_collective: # Replace with a single Open Collective username +# ko_fi: # Replace with a single Ko-fi username +# tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel +# community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry +# liberapay: # Replace with a single Liberapay username +# issuehunt: # Replace with a single IssueHunt username +# otechie: # Replace with a single Otechie username +# lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry +# custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..3af3a0e --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2022 K. Murat Başeren + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/MFramework.Services.Business.EntityFramework/MFramework.Services.Business.EntityFramework.csproj b/MFramework.Services.Business.EntityFramework/MFramework.Services.Business.EntityFramework.csproj index 1466e83..baa4352 100644 --- a/MFramework.Services.Business.EntityFramework/MFramework.Services.Business.EntityFramework.csproj +++ b/MFramework.Services.Business.EntityFramework/MFramework.Services.Business.EntityFramework.csproj @@ -1,19 +1,19 @@ - netstandard2.0 + netstandard2.1 true true - K. Murat Başeren + muratbaseren Apache-2.0 https://github.com/muratbaseren/MFramework.Services https://github.com/muratbaseren/MFramework.Services git - 2.3.2 + 3.0.0 - + diff --git a/MFramework.Services.Business.Mongo/MFramework.Services.Business.Mongo.csproj b/MFramework.Services.Business.Mongo/MFramework.Services.Business.Mongo.csproj index a4adfaf..5f04864 100644 --- a/MFramework.Services.Business.Mongo/MFramework.Services.Business.Mongo.csproj +++ b/MFramework.Services.Business.Mongo/MFramework.Services.Business.Mongo.csproj @@ -1,20 +1,20 @@ - netstandard2.0 + netstandard2.1 true - K. Murat Başeren + muratbaseren https://github.com/muratbaseren/MFramework.Services https://github.com/muratbaseren/MFramework.Services git Apache-2.0 true - 2.3.2 + 3.0.0 - - + + diff --git a/MFramework.Services.Business/Abstract/IManager.cs b/MFramework.Services.Business/Abstract/IManager.cs index 9f12c8f..a8fb475 100644 --- a/MFramework.Services.Business/Abstract/IManager.cs +++ b/MFramework.Services.Business/Abstract/IManager.cs @@ -1,5 +1,7 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; +using System.Linq.Expressions; namespace MFramework.Services.Business.Abstract { @@ -10,6 +12,8 @@ public interface IManager TDelete Delete(TKey id); TEntity Find(TKey id); T Find(TKey id); + //T Find(Expression> filter); + //IEnumerable FindAll(Expression> filter); IEnumerable List(); IEnumerable List(); IQueryable Query(); @@ -28,6 +32,8 @@ public interface IManager T Find(TKey id); IEnumerable List(); IEnumerable List(); + //T Find(Expression> filter); + //IEnumerable FindAll(Expression> filter); IQueryable Query(); void Update(TKey id, T model); void Update(TKey id, TEntity model); diff --git a/MFramework.Services.Business/MFramework.Services.Business.csproj b/MFramework.Services.Business/MFramework.Services.Business.csproj index b6a1ff3..42f9ecb 100644 --- a/MFramework.Services.Business/MFramework.Services.Business.csproj +++ b/MFramework.Services.Business/MFramework.Services.Business.csproj @@ -1,15 +1,15 @@ - netstandard2.0 + netstandard2.1 true - K. Murat Başeren + muratbaseren https://github.com/muratbaseren/MFramework.Services https://github.com/muratbaseren/MFramework.Services git Apache-2.0 true - 2.3.2 + 3.0.0 diff --git a/MFramework.Services.Common/MFramework.Services.Common.csproj b/MFramework.Services.Common/MFramework.Services.Common.csproj index dc5cd24..8821ab9 100644 --- a/MFramework.Services.Common/MFramework.Services.Common.csproj +++ b/MFramework.Services.Common/MFramework.Services.Common.csproj @@ -1,21 +1,21 @@ - netstandard2.0 + netstandard2.1 true - K. Murat Başeren + muratbaseren https://github.com/muratbaseren/MFramework.Services https://github.com/muratbaseren/MFramework.Services git Apache-2.0 true - 2.3.2 + 3.0.0 - + diff --git a/MFramework.Services.DataAccess.EntityFramework/MFramework.Services.DataAccess.EntityFramework.csproj b/MFramework.Services.DataAccess.EntityFramework/MFramework.Services.DataAccess.EntityFramework.csproj index 6a8c424..d624837 100644 --- a/MFramework.Services.DataAccess.EntityFramework/MFramework.Services.DataAccess.EntityFramework.csproj +++ b/MFramework.Services.DataAccess.EntityFramework/MFramework.Services.DataAccess.EntityFramework.csproj @@ -4,13 +4,13 @@ netstandard2.1 true true - K. Murat Başeren + muratbaseren K. Murat Başeren Apache-2.0 https://github.com/muratbaseren/MFramework.Services https://github.com/muratbaseren/MFramework.Services git - 2.3.2 + 3.0.0 diff --git a/MFramework.Services.DataAccess.EntityFrameworkCore/MFramework.Services.DataAccess.EntityFrameworkCore.csproj b/MFramework.Services.DataAccess.EntityFrameworkCore/MFramework.Services.DataAccess.EntityFrameworkCore.csproj index ac2ea9e..1dc27d8 100644 --- a/MFramework.Services.DataAccess.EntityFrameworkCore/MFramework.Services.DataAccess.EntityFrameworkCore.csproj +++ b/MFramework.Services.DataAccess.EntityFrameworkCore/MFramework.Services.DataAccess.EntityFrameworkCore.csproj @@ -1,15 +1,15 @@ - netstandard2.0 + netstandard2.1 true true - K. Murat Başeren + muratbaseren Apache-2.0 https://github.com/muratbaseren/MFramework.Services https://github.com/muratbaseren/MFramework.Services git - 2.3.2 + 3.0.0 diff --git a/MFramework.Services.DataAccess.Mongo/MFramework.Services.DataAccess.Mongo.csproj b/MFramework.Services.DataAccess.Mongo/MFramework.Services.DataAccess.Mongo.csproj index efff7b8..c83cb3c 100644 --- a/MFramework.Services.DataAccess.Mongo/MFramework.Services.DataAccess.Mongo.csproj +++ b/MFramework.Services.DataAccess.Mongo/MFramework.Services.DataAccess.Mongo.csproj @@ -1,32 +1,32 @@ - + - - netstandard2.0 - true - K. Murat Başeren - git - https://github.com/muratbaseren/MFramework.Services - https://github.com/muratbaseren/MFramework.Services - 2.3.2 - Apache-2.0 - true - + + netstandard2.1 + true + muratbaseren + git + https://github.com/muratbaseren/MFramework.Services + https://github.com/muratbaseren/MFramework.Services + 3.0.0 + Apache-2.0 + true + - - C:\repos\muratbaseren\MFramework.Services\MFramework.Services.DataAccess.Mongo\MFramework.Services.DataAccess.Mongo.xml - + + C:\repos\muratbaseren\MFramework.Services\MFramework.Services.DataAccess.Mongo\MFramework.Services.DataAccess.Mongo.xml + - - - + + + - - - - + + + + - - - + + + diff --git a/MFramework.Services.DataAccess.Mongo/Repository/Abstract/MongoRepository.cs b/MFramework.Services.DataAccess.Mongo/Repository/Abstract/MongoRepository.cs index 728504e..4101b81 100644 --- a/MFramework.Services.DataAccess.Mongo/Repository/Abstract/MongoRepository.cs +++ b/MFramework.Services.DataAccess.Mongo/Repository/Abstract/MongoRepository.cs @@ -19,8 +19,8 @@ public interface IMongoRepository where TEntity : EntityBase(Expression> filter, TValue value); - List FindAll(Expression> filter, TValue value); + TEntity Find(Expression> filter); + List FindAll(Expression> filter); List List(); IQueryable Queryable(); } @@ -51,25 +51,22 @@ public virtual bool Any() public virtual long Delete(TKey id) { - var filter = Builders.Filter.Eq(x => x.Id, id); - var result = collection.DeleteOne(filter); - return result.DeletedCount; + return collection.DeleteOne(x => x.Id.Equals(id)).DeletedCount; } public virtual TEntity Find(TKey id) { - var filter = Builders.Filter.Eq(x => x.Id, id); - return collection.Find(filter).FirstOrDefault(); + return Queryable().FirstOrDefault(x => x.Id.Equals(id)); } - public virtual TEntity Find(Expression> filter, TValue value) + public virtual TEntity Find(Expression> filter) { - return collection.Find(Builders.Filter.Eq(filter, value)).FirstOrDefault(); + return collection.Find(filter).FirstOrDefault(); } - public virtual List FindAll(Expression> filter, TValue value) + public virtual List FindAll(Expression> filter) { - return collection.Find(Builders.Filter.Eq(filter, value)).ToList(); + return collection.Find(filter).ToList(); } public virtual TEntity Insert(TEntity entity) @@ -80,28 +77,22 @@ public virtual TEntity Insert(TEntity entity) public virtual List List() { - return collection.Find(new BsonDocument()).ToList(); + return Queryable().ToList(); } public virtual IQueryable Queryable() { - return collection.AsQueryable(); + return collection.AsQueryable(); } public virtual long Update(TKey id, UpdateDefinition updateDefinition) { - var filter = Builders.Filter.Eq(x => x.Id, id); - var result = collection.UpdateOne(filter, updateDefinition); - - return result.ModifiedCount; + return collection.UpdateOne(x => x.Id.Equals(id), updateDefinition).ModifiedCount; } public virtual long Update(TKey id, TEntity entity) { - var filter = Builders.Filter.Eq(x => x.Id, id); - var result = collection.ReplaceOne(filter, entity); - - return result.ModifiedCount; + return collection.ReplaceOne(x => x.Id.Equals(id), entity).ModifiedCount; } } } diff --git a/MFramework.Services.DataAccess/MFramework.Services.DataAccess.csproj b/MFramework.Services.DataAccess/MFramework.Services.DataAccess.csproj index 2071800..f34067e 100644 --- a/MFramework.Services.DataAccess/MFramework.Services.DataAccess.csproj +++ b/MFramework.Services.DataAccess/MFramework.Services.DataAccess.csproj @@ -1,15 +1,15 @@ - netstandard2.0 + netstandard2.1 true https://github.com/muratbaseren/MFramework.Services git https://github.com/muratbaseren/MFramework.Services - K. Murat Başeren + muratbaseren Apache-2.0 true - 2.3.2 + 3.0.0 diff --git a/MFramework.Services.Entities/MFramework.Services.Entities.csproj b/MFramework.Services.Entities/MFramework.Services.Entities.csproj index ef04212..761d500 100644 --- a/MFramework.Services.Entities/MFramework.Services.Entities.csproj +++ b/MFramework.Services.Entities/MFramework.Services.Entities.csproj @@ -1,20 +1,20 @@ - netstandard2.0 + netstandard2.1 true - K. Murat Başeren + muratbaseren https://github.com/muratbaseren/MFramework.Services https://github.com/muratbaseren/MFramework.Services git Apache-2.0 true - 2.3.2 + 3.0.0 - + diff --git a/MFramework.Services.sln b/MFramework.Services.sln index 5e98672..d21c154 100644 --- a/MFramework.Services.sln +++ b/MFramework.Services.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.30320.27 +# Visual Studio Version 17 +VisualStudioVersion = 17.5.33414.496 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MFramework.Services.DataAccess.Mongo", "MFramework.Services.DataAccess.Mongo\MFramework.Services.DataAccess.Mongo.csproj", "{1A131912-AA6E-4060-8193-3DBC481F55D0}" EndProject @@ -26,11 +26,13 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{9912 EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SampleConsoleApp", "SampleConsoleApp\SampleConsoleApp.csproj", "{65708DB7-6C6D-4BF2-9519-E3D3D698C15E}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MFramework.Services.DataAccess.EntityFrameworkCore", "MFramework.Services.DataAccess.EntityFrameworkCore\MFramework.Services.DataAccess.EntityFrameworkCore.csproj", "{CC40D73A-1558-4ABC-B060-24F0289B74D4}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MFramework.Services.DataAccess.EntityFrameworkCore", "MFramework.Services.DataAccess.EntityFrameworkCore\MFramework.Services.DataAccess.EntityFrameworkCore.csproj", "{CC40D73A-1558-4ABC-B060-24F0289B74D4}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MFramework.Services.DataAccess.EntityFramework", "MFramework.Services.DataAccess.EntityFramework\MFramework.Services.DataAccess.EntityFramework.csproj", "{21A2BD2F-A5FE-4118-9ED9-C8C5930A6805}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MFramework.Services.DataAccess.EntityFramework", "MFramework.Services.DataAccess.EntityFramework\MFramework.Services.DataAccess.EntityFramework.csproj", "{21A2BD2F-A5FE-4118-9ED9-C8C5930A6805}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MFramework.Services.Business.EntityFramework", "MFramework.Services.Business.EntityFramework\MFramework.Services.Business.EntityFramework.csproj", "{FEA6A00C-FAE1-4E31-9A3B-7CCE7DB2C734}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MFramework.Services.Business.EntityFramework", "MFramework.Services.Business.EntityFramework\MFramework.Services.Business.EntityFramework.csproj", "{FEA6A00C-FAE1-4E31-9A3B-7CCE7DB2C734}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{FC12AEC1-06FF-451C-B7B0-E836E92620F4}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/SampleConsoleApp/Program.cs b/SampleConsoleApp/Program.cs index 4c742f0..8ed954b 100644 --- a/SampleConsoleApp/Program.cs +++ b/SampleConsoleApp/Program.cs @@ -7,8 +7,13 @@ using MFramework.Services.Entities.Abstract; using MFramework.Services.FakeData; using MongoDB.Bson; +using MongoDB.Bson.Serialization.Attributes; +using MongoDB.Driver; using System; +using System.Collections; +using System.Collections.Generic; using System.Linq; +using System.Linq.Expressions; namespace SampleConsoleApp { @@ -23,8 +28,12 @@ public MyMongoContext() : base(null, "mongodb://localhost:27017", "mongotestdb") public class Album : EntityBase { public string Name { get; set; } + + [BsonRepresentation(BsonType.Int32)] public int Year { get; set; } public bool IsSales { get; set; } + + [BsonRepresentation(BsonType.Decimal128)] public decimal Price { get; set; } } @@ -41,6 +50,16 @@ public class AlbumManager : MongoManager public AlbumManager(IMapper mapper) : base(new AlbumRepository(), mapper) { } + + public Album Find(Expression> filter) + { + return repository.Find(filter); + } + + public IEnumerable FindAll(Expression> filter) + { + return repository.FindAll(filter); + } } @@ -49,86 +68,249 @@ class Program { static void Main(string[] args) { - MapperConfiguration mapperConfiguration = new MapperConfiguration(opts => opts.CreateMap()); + MapperConfiguration mapperConfiguration = + new MapperConfiguration(opts => opts.CreateMap()); + IMapper mapper = mapperConfiguration.CreateMapper(); AlbumManager albumManager = new AlbumManager(mapper); CreateFakeData(albumManager); + QueryTest(albumManager); + CreateTest(albumManager); QueryTest(albumManager); + FindTest(albumManager); + UpdateTest(albumManager); QueryTest(albumManager); + DeleteTest(albumManager); + QueryTest(albumManager); + Console.WriteLine(); Console.WriteLine("Please enter to quit!!.."); Console.ReadKey(); } + private static ObjectId newAddedObjId = ObjectId.Empty; + + private static void CreateTest(AlbumManager albumManager) + { + Console.ForegroundColor = ConsoleColor.Yellow; + Console.WriteLine("CREATE TEST"); + Console.WriteLine("==========="); + Console.WriteLine(); + Console.ResetColor(); + + var album = albumManager.Create(new Album { IsSales = false, Name = "testo11", Price = 10, Year = 2021 }); + newAddedObjId = album.Id; + Console.WriteLine(album.ToJson()); + + Console.WriteLine(); + Console.WriteLine("Album created. "); + Console.WriteLine("Please enter key to continue.."); + Console.ReadKey(); + Console.WriteLine(); + } + private static void CreateFakeData(AlbumManager albumManager) { - if (albumManager.Query().Any() == false) + Console.WriteLine("Checking fake data exists..."); + if (albumManager.Query().Any()) { - for (int i = 0; i < 5; i++) + Console.WriteLine("Fake data has already exist.."); + Console.WriteLine(); + } + else + { + Console.WriteLine(); + Console.ForegroundColor = ConsoleColor.Yellow; + Console.WriteLine("ADDING FAKE DATA"); + Console.WriteLine("================"); + Console.WriteLine(); + Console.ResetColor(); + + // Create fake static datas.. + // + Album album1 = new Album + { + Name = "Thompson LLP", + Year = 1983, + IsSales = true, + Price = 2991.897623784793302m + }; + Console.WriteLine(albumManager.Create(album1).ToJson()); + + Album album2 = new Album + { + Name = "Lord and Partners", + Year = 2008, + IsSales = true, + Price = 80.5049157852795798m + }; + Console.WriteLine(albumManager.Create(album2).ToJson()); + + Album album3 = new Album { - albumManager.Create(new Album - { - Name = NameData.GetCompanyName(), - Price = (decimal)NumberData.GetDouble() * NumberData.GetNumber(100, 4000), - IsSales = BooleanData.GetBoolean(), - Year = NumberData.GetNumber(1980, DateTime.Now.Year) - }); - } - - Console.WriteLine("Sample data created. Please enter key to continue.."); + Name = "Summers CIC", + Year = 1981, + IsSales = false, + Price = 50.2335336088358382m + }; + Console.WriteLine(albumManager.Create(album3).ToJson()); + + Album album4 = new Album + { + Name = "Weaver Group", + Year = 2013, + IsSales = true, + Price = 316.240591920093264m + }; + Console.WriteLine(albumManager.Create(album4).ToJson()); + + Album album5 = new Album + { + Name = "Joyce Inc", + Year = 2013, + IsSales = false, + Price = 790.903162565502480m + }; + Console.WriteLine(albumManager.Create(album5).ToJson()); + + + + // Create fake dynamic datas.. + // + //for (int i = 0; i < 5; i++) + //{ + // Console.WriteLine(albumManager.Create(new Album + // { + // Name = NameData.GetCompanyName(), + // Price = (decimal)NumberData.GetDouble() * NumberData.GetNumber(100, 4000), + // IsSales = BooleanData.GetBoolean(), + // Year = NumberData.GetNumber(1980, DateTime.Now.Year) + // }).ToJson()); + //} + Console.WriteLine(); + Console.WriteLine("Fake data created. "); + Console.WriteLine("Please enter key to continue.."); Console.ReadKey(); + Console.WriteLine(); } } private static void QueryTest(AlbumManager albumManager) { + Console.ForegroundColor = ConsoleColor.Yellow; + Console.WriteLine("LIST TEST"); + Console.WriteLine("========="); + Console.WriteLine(); + Console.ResetColor(); + + Console.WriteLine("List 1 All Items"); + Console.WriteLine("================"); var list = albumManager.List().ToList(); list.ForEach(x => Console.WriteLine(x.ToJson())); - - //var list = albumManager.Query().Where(x => x.IsSales).ToList(); - //list.ForEach(x => Console.WriteLine(x.ToJson())); + Console.WriteLine(); - //var list = albumManager.Query().Where(x => x.Name.StartsWith("A")).ToList(); - //list.ForEach(x => Console.WriteLine(x.ToJson())); + Console.WriteLine("List 2 (only IsSale=true)"); + Console.WriteLine("========================="); + var list2 = albumManager.Query().Where(x => x.IsSales).ToList(); + list2.ForEach(x => Console.WriteLine(x.ToJson())); + Console.WriteLine(); + + Console.WriteLine("List 3 (only Name.StartsWith('T'))"); + Console.WriteLine("=================================="); + var list3 = albumManager.Query().Where(x => x.Name.StartsWith("T")).ToList(); + list3.ForEach(x => Console.WriteLine(x.ToJson())); + Console.WriteLine(); - //var list = albumManager.Query().Where(x => x.Price >= 200 && x.Price <= 300).ToList(); - //list.ForEach(x => Console.WriteLine(x.ToJson())); + Console.WriteLine("List 4 (only Price >= 50 && x.Price <= 100)"); + Console.WriteLine("==========================================="); + var list4 = albumManager.Query().Where(x => x.Price >= 50 && x.Price <= 100).ToList(); + list4.ForEach(x => Console.WriteLine(x.ToJson())); + Console.WriteLine(); Console.WriteLine(); - Console.WriteLine("All items listed. Please enter key to continue.."); + Console.WriteLine("Please enter key to continue.."); Console.ReadKey(); Console.WriteLine(); } - private static void UpdateTest(AlbumManager albumManager) + private static void FindTest(AlbumManager albumManager) { - var album = albumManager.Create(new Album { IsSales = false, Name = "testo11", Price = 10, Year = 2021 }); - Console.WriteLine(album.ToJson()); - Console.WriteLine("Album created. Please enter key to continue.."); + Console.ForegroundColor = ConsoleColor.Yellow; + Console.WriteLine("FIND TEST"); + Console.WriteLine("========="); + Console.WriteLine(); + Console.ResetColor(); + + Console.WriteLine($"Find (only id:{newAddedObjId})"); + Console.WriteLine("======================================="); + var item1 = albumManager.Find(newAddedObjId); + Console.WriteLine(item1.ToJson()); + Console.WriteLine(); + + Console.WriteLine($"Find (Price = 10)"); + Console.WriteLine("======================================="); + var item2 = albumManager.Find(x => x.Price == 10); + Console.WriteLine(item2.ToJson()); Console.WriteLine(); + + Console.WriteLine($"Find All (Year > 1980 && Year < 1984)"); + Console.WriteLine("======================================="); + var list = albumManager.FindAll(x => x.Year > 1980 && x.Year < 1984).ToList(); + list.ForEach(x => Console.WriteLine(x.ToJson())); + Console.WriteLine(); + + Console.WriteLine(); + Console.WriteLine("Please enter key to continue.."); Console.ReadKey(); + Console.WriteLine(); + } - var album2 = albumManager.Find(album.Id); + private static void UpdateTest(AlbumManager albumManager) + { + Console.ForegroundColor = ConsoleColor.Yellow; + Console.WriteLine("UPDATE TESTS"); + Console.WriteLine("============"); + Console.WriteLine(); + Console.ResetColor(); + + var album2 = albumManager.Find(newAddedObjId); album2.Name = "testo112"; albumManager.Update(album2.Id, album2); var album3 = albumManager.Find(album2.Id); Console.WriteLine(album3.ToJson()); - Console.WriteLine($"Album name updated {album.Name} => {album3.Name} by Update method. Please enter key to continue.."); + Console.WriteLine($"Album name updated with \"Update\" method. Please enter key to continue.."); Console.WriteLine(); - Console.ReadKey(); - var album4 = albumManager.Find(album.Id); + var album4 = albumManager.Find(newAddedObjId); albumManager.UpdateProperties(album4.Id, new { Name = "testo113" }.ToExpando()); var album5 = albumManager.Find(album4.Id); Console.WriteLine(album5.ToJson()); - Console.WriteLine($"Album name updated {album4.Name} => {album5.Name} by UpdateProperties method. Please enter key to continue.."); + Console.WriteLine($"Album name updated by \"UpdateProperties\" method. "); + Console.WriteLine(); + Console.WriteLine("Please enter key to continue.."); Console.ReadKey(); + Console.WriteLine(); + } + + private static void DeleteTest(AlbumManager albumManager) + { + Console.ForegroundColor = ConsoleColor.Yellow; + Console.WriteLine("DELETE TEST"); + Console.WriteLine("==========="); + Console.WriteLine(); + Console.ResetColor(); + + albumManager.Delete(newAddedObjId); + Console.WriteLine($"Album deleted.(id : {newAddedObjId})"); + Console.WriteLine("Please enter key to continue.."); + Console.ReadKey(); + Console.WriteLine(); } } } diff --git a/SampleConsoleApp/SampleConsoleApp.csproj b/SampleConsoleApp/SampleConsoleApp.csproj index 9a30933..d9be478 100644 --- a/SampleConsoleApp/SampleConsoleApp.csproj +++ b/SampleConsoleApp/SampleConsoleApp.csproj @@ -1,22 +1,22 @@ - + - - Exe - netcoreapp3.1 - + + Exe + netcoreapp3.1 + - - - - + + + + - - - - - - - - + + + + + + + +