Exemplo n.º 1
0
 /// <summary>
 /// 新增
 /// </summary>
 /// <returns></returns>
 public async Task <int> AddAsync(T entity)
 {
     entity.CreateBy   = CurrentUser.Info.Id;
     entity.CreateDate = DateTime.Now;
     entity.ModifyBy   = 0;
     entity.Disable    = (short)BaseModel.DisableEnum.Normal;
     return(await _repository.AddAsync(entity));
 }
Exemplo n.º 2
0
        public async Task AddAsync_WhenAddOneEmployee_ThenTotalCountShouldBeOne()
        {
            // Arrange
            var employee = _fixture.Create <Employee>();
            var spec     = new EmployeeSpecification();

            // Act
            await _repository.AddAsync(employee);

            var result = await _repository.GetBySpecificationAsync(spec);

            // Assert
            result.Should().HaveCount(1);
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            System.Console.WriteLine("I exist ony to Fake!");

            var connectionString = "mongodb://localhost:27017";

            var repo = new BaseRepository <Ad>(new MongoClient(connectionString));

            var testAddresses = new Faker <Address>()
                                .RuleFor(x => x.BuildingNumber, f => f.Random.Number(1, 100))
                                .RuleFor(x => x.City, f => f.Address.City())
                                .RuleFor(x => x.Street, f => f.Address.StreetName())
                                .RuleFor(x => x.ZipCode, f => f.Address.ZipCode())
                                .RuleFor(x => x.FlatNumber, f => f.Random.Number(1, 100))
                                .Generate(50);

            var testOwners = new Faker <User>()
                             .RuleFor(x => x.Name, f => f.Name.FirstName())
                             .RuleFor(x => x.Surname, f => f.Name.LastName())
                             .Generate(20);

            var testAds = new Faker <Ad>()
                          .RuleFor(x => x.Address, f => f.PickRandom(testAddresses))
                          .RuleFor(x => x.Owner, f => f.PickRandom(testOwners))
                          .RuleFor(x => x.Title, f => f.Commerce.ProductName())
                          .RuleFor(x => x.Description, f => f.Commerce.ProductAdjective())
                          .Generate(34);

            foreach (var item in testAds)
            {
                repo.AddAsync(item).GetAwaiter().GetResult();
            }

            System.Console.WriteLine("And I just did it!");
        }
Exemplo n.º 4
0
        public async Task Add(NewPurchaseModel model)
        {
            var newPurchase = new NewPurchase
            {
                Date                = model.Date,
                SetNumber           = model.SetNumber,
                SetName             = model.SetName,
                Theme               = model.Theme,
                Promotions          = model.Promotions,
                Price               = model.Price,
                UnitPrice           = model.UnitPrice,
                Quantity            = model.Quantity,
                Parts               = model.Parts,
                TotalParts          = model.TotalParts,
                PriceToPartOutRatio = model.PriceToPartOutRatio,
                Source              = model.Source,
                PaymentMethod       = model.PaymentMethod,
                AveragePartOutValue = model.AveragePartOutValue,
                MyPartOutValue      = model.MyPartOutValue,
                ExpectedGrossProfit = model.ExpectedGrossProfit,
                ExpectedNetProfit   = model.ExpectedNetProfit,
                Status              = model.Status,
                SellingNotes        = model.SellingNotes,
                Notes               = model.Notes,
                Receipt             = model.Receipt
            };

            await _repo.AddAsync(newPurchase);
        }
Exemplo n.º 5
0
 public void Run()
 {
     if (!_repLang.GetNoTraking.Any(a => a.Code == "fa-IR"))
     {
         _repLang.AddAsync(new tblLanguages()
         {
             Id                 = new Guid().SequentialGuid(),
             Code               = "fa-IR",
             IsActive           = true,
             IsRtl              = true,
             Name               = "Persian_IR",
             NativeName         = "فارسی (ایران)",
             Abbr               = "fa",
             UseForSiteLanguage = true,
             tblFile            = new tblFiles()
             {
                 Id           = new Guid().SequentialGuid(),
                 Title        = "IranFlag",
                 Date         = DateTime.Now,
                 FileName     = "IranFlag.png",
                 FileServerId = _FileServer.GetNoTraking.Where(a => a.Name == "Public").Select(a => a.Id).Single(),
                 MimeType     = "image/png",
                 Path         = "/flags/",
                 SizeOnDisk   = 0
             }
         }, default, true).Wait();
Exemplo n.º 6
0
 public async void AddJob(Job job)
 {
     using (BaseRepository <Job> repo = new BaseRepository <Job>())
     {
         await repo.AddAsync(job);
     }
 }
Exemplo n.º 7
0
 public void Run()
 {
     if (!_Countries.Get.Any(a => a.Name == "Iran"))
     {
         _Countries.AddAsync(new tblCountries()
         {
             Id       = new Guid().SequentialGuid(),
             Name     = "Iran",
             IsActive = true,
             tblFiles = new tblFiles()
             {
                 Id           = new Guid().SequentialGuid(),
                 Title        = "IranCountryFlag",
                 Date         = DateTime.Now,
                 FileName     = "IranCountryFlag.png",
                 FileServerId = _FileServer.GetNoTraking.Where(a => a.Name == "Public").Select(a => a.Id).Single(),
                 MimeType     = "image/png",
                 Path         = "/flags/",
                 SizeOnDisk   = 0
             },
             tblCountries_Translates = new List <tblCountries_Translates> {
                 new tblCountries_Translates {
                     Id     = new Guid().SequentialGuid(),
                     LangId = _Language.Get.Where(a => a.Code == "fa-IR").Select(a => a.Id).Single(),
                     Title  = "ایران"
                 },
                 new tblCountries_Translates {
                     Id     = new Guid().SequentialGuid(),
                     LangId = _Language.Get.Where(a => a.Code == "en-US").Select(a => a.Id).Single(),
                     Title  = "Iran"
                 }
             }
         }, default).Wait();
     }
 }
Exemplo n.º 8
0
 public void Run()
 {
     // ConfirmationEmail  fa-IR
     if (!_repTemplate.GetNoTraking.Any(a => a.tblLanguages.Code == "fa-IR" && a.Name == "ConfirmationEmail"))
     {
         _repTemplate.AddAsync(new tblTamplates()
         {
             Id       = new Guid().SequentialGuid(),
             LangId   = _repLang.GetNoTraking.Where(a => a.Code == "fa-IR").Select(a => a.Id).Single(),
             Name     = "ConfirmationEmail",
             Template = "<a href='[Url]'>کلیک</a>"
         }, default, true).Wait();
Exemplo n.º 9
0
        public async Task <T> PostAsync <V>(T obj) where V : AbstractValidator <T>
        {
            if (obj.GetType() == typeof(Produto))
            {
                obj = GerarParcelas(obj as Produto);
            }

            Validate(obj, Activator.CreateInstance <V>());

            await repository.AddAsync(obj);

            return(obj);
        }
Exemplo n.º 10
0
        public async Task Add(LogModel model)
        {
            var log = new Log
            {
                Date        = DateTime.Now,
                Title       = model.Title,
                Note        = model.Note,
                FurtherNote = model.FurtherNote,
                Category    = model.Category
            };

            await _repo.AddAsync(log);
        }
Exemplo n.º 11
0
 public void Run()
 {
     if (!_repRoles.Get.Any(a => a.Name == "AdminPage"))
     {
         _repRoles.AddAsync(new TblRole()
         {
             Id             = new Guid().SequentialGuid(),
             ParentId       = null,
             PageName       = "AdminPage",
             Sort           = 0,
             Name           = "AdminPage",
             NormalizedName = "AdminPage".ToUpper(),
             Description    = "دسترسی به پنل مدیریت"
         }, default, false).Wait();
Exemplo n.º 12
0
 public void Run()
 {
     if (!_repFileServer.Get.Any(a => a.Name == "Public"))
     {
         _repFileServer.AddAsync(new tblFileServers()
         {
             Id          = new Guid().SequentialGuid(),
             Name        = "Public",
             FtpData     = "",
             Capacity    = 0,
             Description = "",
             HttpDomin   = "http://127.0.0.111",
             HttpPath    = "/Main",
             IsActive    = true,
         }, default, false).Wait();
Exemplo n.º 13
0
        public async Task <int> RegisterUserAsync(string Name, string LastName, string Email,
                                                  string Password, int RoleTypeId)
        {
            User user = new User
            {
                Name       = Name,
                LastName   = LastName,
                Email      = Email,
                Password   = Password,
                RoleTypeId = RoleTypeId
            };

            using (BaseRepository <User> repo = new BaseRepository <User>())
            {
                return(await repo.AddAsync(user));
            }
        }
 public void Run()
 {
     if (!_repSetting.Get.Any(a => a.IsEnable == true && a.TblLanguage.Code == "fa-IR"))
     {
         _repSetting.AddAsync(new TblSetting()
         {
             Id              = new Guid().SequentialGuid(),
             Date            = DateTime.Now,
             IsEnable        = true,
             IsInManufacture = false,
             LangId          = _repLang.Get.Where(a => a.Code == "fa-IR").Select(a => a.Id).Single(),
             SiteDescription = "سایت فروشگاهی پرنسابیوتی",
             SiteEmail       = "*****@*****.**",
             SitePhoneNumber = "09147922542",
             SiteTitle       = "پرنسابیوتی",
             SiteUrl         = "https://localhost:44382"
         }, default, true).Wait();
        public async Task Add(ExpenseModel model)
        {
            var expense = new Expense
            {
                Id              = model.Id,
                Date            = model.Date,
                TaxCategory     = model.TaxCategory,
                Category        = model.Category,
                Source          = model.Source,
                ExpenditureType = model.ExpenditureType,
                OrderNumber     = model.OrderNumber,
                Price           = model.Price,
                Postage         = model.Postage,
                Receipt         = model.Receipt,
                Notes           = model.Notes,
                Item            = model.Item,
                Quantity        = model.Quantity
            };

            await _repo.AddAsync(expense);
        }
Exemplo n.º 16
0
        public void Run()
        {
            if (!_repAccessLevel.Get.Any(a => a.Name == "GeneralManager"))
            {
                var qAccRole = new tblAccessLevels()
                {
                    Id   = new Guid().SequentialGuid(),
                    Name = "GeneralManager",
                    tblAccessLevel_Roles = new List <tblAccessLevel_Roles>()
                };

                foreach (var item in _repRoles.Get.ToList())
                {
                    qAccRole.tblAccessLevel_Roles.Add(new tblAccessLevel_Roles
                    {
                        Id            = new Guid().SequentialGuid(),
                        AccessLevelId = qAccRole.Id,
                        RoleId        = item.Id
                    });
                }

                _repAccessLevel.AddAsync(qAccRole, default, false).Wait();
        public async Task Add(UsedPurchaseModel model)
        {
            var usedPurchase = new UsedPurchase
            {
                Id                = model.Id,
                Date              = model.Date,
                Source            = model.Source,
                SourceUsername    = model.SourceUsername,
                OrderNumber       = model.OrderNumber,
                Price             = model.Price,
                PaymentMethod     = model.PaymentMethod,
                Receipt           = model.Receipt,
                DistanceTravelled = model.DistanceTravelled,
                Location          = model.Location,
                Postage           = model.Postage,
                Weight            = model.Weight,
                PricePerKilo      = model.PricePerKilo,
                CompleteSets      = model.CompleteSets,
                Notes             = model.Notes
            };

            await _repo.AddAsync(usedPurchase);
        }
Exemplo n.º 18
0
 public void Run()
 {
     if (!_repUser.Get.Any(a => a.UserName == "RezaAhmadi"))
     {
         Guid UserId = new Guid().SequentialGuid();
         _repUser.AddAsync(new tblUsers()
         {
             Id                   = UserId,
             AccessLevelId        = _repAccessLevel.Get.Where(a => a.Name == "GeneralManager").Select(a => a.Id).Single(),
             FirstName            = "محمدرضا",
             LastName             = "احمدی",
             IsActive             = true,
             Date                 = DateTime.Now,
             UserName             = "******",
             NormalizedUserName   = "******".ToUpper(),
             Email                = "*****@*****.**",
             NormalizedEmail      = "*****@*****.**".ToUpper(),
             EmailConfirmed       = true,
             PasswordHash         = "AQAAAAEAACcQAAAAELVlHmEilr3l0mizs5GxKWdCQIL8ys6zuHdVro+hNsU7RxYC9HtJqdajundVGRFC5Q==",
             SecurityStamp        = "QHZXXDN4PZUNNXGC6LQRVNOZ5EGGIKWH",
             ConcurrencyStamp     = "37116a3b-0da5-460e-b266-d5243f62e5c8",
             PhoneNumber          = "9010112829",
             PhoneNumberConfirmed = true,
         }, default, true).Wait();
Exemplo n.º 19
0
 public void Run()
 {
     if (!_repUser.Get.Any(a => a.UserName == "*****@*****.**"))
     {
         Guid UserId = new Guid().SequentialGuid();
         _repUser.AddAsync(new TblUser()
         {
             Id                   = UserId,
             AccessLevelId        = _repAccessLevel.Get.Where(a => a.Name == "GeneralManager").Select(a => a.Id).Single(),
             FirstName            = "آرشام",
             LastName             = "بهبهانی",
             IsActive             = true,
             Date                 = DateTime.Now,
             UserName             = "******",
             NormalizedUserName   = "******".ToUpper(),
             Email                = "*****@*****.**",
             NormalizedEmail      = "*****@*****.**".ToUpper(),
             EmailConfirmed       = true,
             PasswordHash         = "AQAAAAEAACcQAAAAEO4DDm//CF91OA/DWo5+TkznvEzE0UshISWpEGkOTKNCHtV2fXosKhfN3Mw3TSegAA==",
             SecurityStamp        = "QHZXXDN4PZUNNXGC6LQRVNOZ5EGGIKWH",
             ConcurrencyStamp     = "37116a3b-0da5-460e-b266-d5243f62e5c8",
             PhoneNumber          = "9010112829",
             PhoneNumberConfirmed = true,
         }, default, true).Wait();
        /// <summary>
        /// Updates the list of weights for a purchase
        /// </summary>
        /// <param name="id"></param>
        /// <param name="weights"></param>
        /// <returns></returns>
        public async Task UpdateWeights(int id, IEnumerable <UsedPurchaseWeightModel> weights)
        {
            if (weights == null)
            {
                weights = new List <UsedPurchaseWeightModel>();
            }

            var purchase = await _repo.FindOneAsync(id);

            var existingWeights = purchase.Weights;
            var existingIds     = existingWeights.Select(x => x.Id);

            var toAdd    = weights.Where(x => !existingIds.Contains(x.Id) && !x.Delete).ToList();
            var toUpdate = weights.Where(x => existingIds.Contains(x.Id) && !x.Delete).ToList();
            var toDelete = weights.Where(x => x.Delete).ToList();

            // Add
            foreach (var wt in toAdd.Select(x => ToEntity(x, purchase)))
            {
                await _weightRepo.AddAsync(wt);
            }

            // Update
            foreach (var wt in toUpdate)
            {
                var entity = await _weightRepo.FindOneAsync(wt.Id);

                entity.Colour = wt.Colour;
                entity.Weight = wt.Weight;

                await _weightRepo.UpdateAsync(entity);
            }

            // Delete
            await _weightRepo.RemoveManyAsync(toDelete.Select(x => _weightRepo.FindOne(x.Id)));
        }
Exemplo n.º 21
0
        public void Run()
        {
            if (!_Province.Get.Any(a => a.Name == "Tehran"))
            {
                _Province.AddAsync(new tblProvinces()
                {
                    Id        = new Guid().SequentialGuid(),
                    CountryId = _Countries.Get.Where(a => a.Name == "Iran").Select(a => a.Id).Single(),
                    Name      = "Tehran",
                    IsActive  = true,
                    tblProvinces_Translate = new List <tblProvinces_Translate> {
                        new tblProvinces_Translate {
                            Id     = new Guid().SequentialGuid(),
                            LangId = _Language.Get.Where(a => a.Code == "fa-IR").Select(a => a.Id).Single(),
                            Title  = "تهران"
                        },
                        new tblProvinces_Translate {
                            Id     = new Guid().SequentialGuid(),
                            LangId = _Language.Get.Where(a => a.Code == "en-US").Select(a => a.Id).Single(),
                            Title  = "Tehran"
                        }
                    }
                }, default).Wait();
            }

            if (!_Province.Get.Any(a => a.Name == "Esfahan"))
            {
                _Province.AddAsync(new tblProvinces()
                {
                    Id        = new Guid().SequentialGuid(),
                    CountryId = _Countries.Get.Where(a => a.Name == "Iran").Select(a => a.Id).Single(),
                    Name      = "Esfahan",
                    IsActive  = true,
                    tblProvinces_Translate = new List <tblProvinces_Translate> {
                        new tblProvinces_Translate {
                            Id     = new Guid().SequentialGuid(),
                            LangId = _Language.Get.Where(a => a.Code == "fa-IR").Select(a => a.Id).Single(),
                            Title  = "اصفهان"
                        },
                        new tblProvinces_Translate {
                            Id     = new Guid().SequentialGuid(),
                            LangId = _Language.Get.Where(a => a.Code == "en-US").Select(a => a.Id).Single(),
                            Title  = "Esfahan"
                        }
                    }
                }, default).Wait();
            }

            if (!_Province.Get.Any(a => a.Name == "Fars"))
            {
                _Province.AddAsync(new tblProvinces()
                {
                    Id        = new Guid().SequentialGuid(),
                    CountryId = _Countries.Get.Where(a => a.Name == "Iran").Select(a => a.Id).Single(),
                    Name      = "Fars",
                    IsActive  = true,
                    tblProvinces_Translate = new List <tblProvinces_Translate> {
                        new tblProvinces_Translate {
                            Id     = new Guid().SequentialGuid(),
                            LangId = _Language.Get.Where(a => a.Code == "fa-IR").Select(a => a.Id).Single(),
                            Title  = "فارس"
                        },
                        new tblProvinces_Translate {
                            Id     = new Guid().SequentialGuid(),
                            LangId = _Language.Get.Where(a => a.Code == "en-US").Select(a => a.Id).Single(),
                            Title  = "Fars"
                        }
                    }
                }, default).Wait();
            }
        }
Exemplo n.º 22
0
        public void Run()
        {
            if (!_Cities.Get.Any(a => a.Name == "Tehran"))
            {
                _Cities.AddAsync(new tblCities()
                {
                    Id                   = new Guid().SequentialGuid(),
                    ProvinceId           = _Province.Get.Where(a => a.Name == "Tehran").Select(a => a.Id).Single(),
                    Name                 = "Tehran",
                    IsActive             = true,
                    tblCities_Translates = new List <tblCities_Translates> {
                        new tblCities_Translates {
                            Id     = new Guid().SequentialGuid(),
                            LangId = _Language.Get.Where(a => a.Code == "fa-IR").Select(a => a.Id).Single(),
                            Title  = "تهران"
                        },
                        new tblCities_Translates {
                            Id     = new Guid().SequentialGuid(),
                            LangId = _Language.Get.Where(a => a.Code == "en-US").Select(a => a.Id).Single(),
                            Title  = "Tehran"
                        }
                    }
                }, default).Wait();
            }

            if (!_Cities.Get.Any(a => a.Name == "Shiraz"))
            {
                _Cities.AddAsync(new tblCities()
                {
                    Id                   = new Guid().SequentialGuid(),
                    ProvinceId           = _Province.Get.Where(a => a.Name == "Fars").Select(a => a.Id).Single(),
                    Name                 = "Shiraz",
                    IsActive             = true,
                    tblCities_Translates = new List <tblCities_Translates> {
                        new tblCities_Translates {
                            Id     = new Guid().SequentialGuid(),
                            LangId = _Language.Get.Where(a => a.Code == "fa-IR").Select(a => a.Id).Single(),
                            Title  = "شیراز"
                        },
                        new tblCities_Translates {
                            Id     = new Guid().SequentialGuid(),
                            LangId = _Language.Get.Where(a => a.Code == "en-US").Select(a => a.Id).Single(),
                            Title  = "Shiraz"
                        }
                    }
                }, default).Wait();
            }

            if (!_Cities.Get.Any(a => a.Name == "Esfahan"))
            {
                _Cities.AddAsync(new tblCities()
                {
                    Id                   = new Guid().SequentialGuid(),
                    ProvinceId           = _Province.Get.Where(a => a.Name == "Esfahan").Select(a => a.Id).Single(),
                    Name                 = "Esfahan",
                    IsActive             = true,
                    tblCities_Translates = new List <tblCities_Translates> {
                        new tblCities_Translates {
                            Id     = new Guid().SequentialGuid(),
                            LangId = _Language.Get.Where(a => a.Code == "fa-IR").Select(a => a.Id).Single(),
                            Title  = "اصفهان"
                        },
                        new tblCities_Translates {
                            Id     = new Guid().SequentialGuid(),
                            LangId = _Language.Get.Where(a => a.Code == "en-US").Select(a => a.Id).Single(),
                            Title  = "Esfahan"
                        }
                    }
                }, default).Wait();
            }
        }
        public async Task AddBLUpload(UsedPurchaseBLUploadModel model)
        {
            var entity = ToEntity(model);

            await _blUploadRepo.AddAsync(entity);
        }
Exemplo n.º 24
0
        public BaseRepository <TEntity> BaseDal; //通过在子类的构造函数中注入,这里是基类,不用构造函数

        #region 增

        /// <summary>
        ///     写入实体数据
        /// </summary>
        /// <param name="entity">博文实体类</param>
        /// <returns></returns>
        public async Task <int> AddAsync(TEntity entity) => await BaseDal.AddAsync(entity);