public IActionResult Post([FromBody] Lesson item)
        {
            var result = _context.Lessons.Add(item);

            _context.SaveChanges();
            return(Ok(result.Entity));
        }
Ejemplo n.º 2
0
        private void InitialiseDatabase()
        {
            var systemAccount = new Account
            {
                AccountId           = Guid.Parse("35c38df0-a959-4232-aadd-40db2260f557"),
                AddedByAccountId    = null,
                AddedOnUtc          = DateTime.UtcNow,
                ModifiedByAccountId = null,
                ModifiedOnUtc       = DateTime.UtcNow
            };

            var otherAccounts = new List <Account>
            {
                new Account
                {
                    AccountId           = Guid.Parse("015b76fc-2833-45d9-85a7-ab1c389c1c11"),
                    AddedByAccountId    = Guid.Parse("35c38df0-a959-4232-aadd-40db2260f557"),
                    AddedOnUtc          = DateTime.UtcNow,
                    ModifiedByAccountId = Guid.Parse("35c38df0-a959-4232-aadd-40db2260f557"),
                    ModifiedOnUtc       = DateTime.UtcNow
                },
                new Account
                {
                    AccountId           = Guid.Parse("538ee0dd-531a-41c6-8414-0769ec5990d8"),
                    AddedByAccountId    = Guid.Parse("35c38df0-a959-4232-aadd-40db2260f557"),
                    AddedOnUtc          = DateTime.UtcNow,
                    ModifiedByAccountId = Guid.Parse("35c38df0-a959-4232-aadd-40db2260f557"),
                    ModifiedOnUtc       = DateTime.UtcNow
                },
                new Account
                {
                    AccountId           = Guid.Parse("8288d9ac-fbce-417e-89ef-82266b284b78"),
                    AddedByAccountId    = Guid.Parse("35c38df0-a959-4232-aadd-40db2260f557"),
                    AddedOnUtc          = DateTime.UtcNow,
                    ModifiedByAccountId = Guid.Parse("35c38df0-a959-4232-aadd-40db2260f557"),
                    ModifiedOnUtc       = DateTime.UtcNow
                },
                new Account
                {
                    AccountId           = Guid.Parse("4bcfe9f8-e4a5-49f0-b6ee-44871632a903"),
                    AddedByAccountId    = Guid.Parse("35c38df0-a959-4232-aadd-40db2260f557"),
                    AddedOnUtc          = DateTime.UtcNow,
                    ModifiedByAccountId = Guid.Parse("35c38df0-a959-4232-aadd-40db2260f557"),
                    ModifiedOnUtc       = DateTime.UtcNow
                }
            };

            _dbContext.Add(systemAccount);
            _dbContext.AddRange(otherAccounts);

            try
            {
                _dbContext.SaveChanges();
            }
            catch (Exception ex)
            {
                // Just checking to see if anything was being raised.
            }
        }
Ejemplo n.º 3
0
 public void InserMany <T>(IEnumerable <T> entities)
     where T : class
 {
     using (var context = new EntityFrameworkDbContext()) {
         context.Set <T>().AddRange(entities);
         context.SaveChanges();
     }
 }
Ejemplo n.º 4
0
        public TEntity Add(TEntity entity)
        {
            entity.Created = DateTime.UtcNow;
            TEntity addedEntity = DbSet.Add(entity);

            EntityFrameworkDbContext.SaveChanges();
            return(addedEntity);
        }
Ejemplo n.º 5
0
 public void InsertOne <T>(T entity)
     where T : class
 {
     using (var context = new EntityFrameworkDbContext()) {
         context.Set <T>().Add(entity);
         context.SaveChanges();
     }
 }
Ejemplo n.º 6
0
        public virtual void Update(TEntity entity, bool save = true)
        {
            DbSet.Attach(entity);
            EntityFrameworkDbContext.Entry(entity).State = EntityState.Modified;

            if (save)
            {
                EntityFrameworkDbContext.SaveChanges();
            }
        }
Ejemplo n.º 7
0
 private static void CreateFtpUsers(int count, string login)
 {
     using var context = new EntityFrameworkDbContext();
     context.FtpUsers.AddRange(Enumerable.Range(0, count).Select(_ => new FtpUser
     {
         Login = login,
         BoxId = Guid.NewGuid().ToString(),
         Id    = Guid.NewGuid(),
     }));
     context.SaveChanges();
 }
Ejemplo n.º 8
0
        private static UsersTable[] GenerateRandomUsersAndAssertCount(int count)
        {
            var scopeId = Guid.NewGuid().ToString();
            var users   = Enumerable.Range(0, count).Select(_ => GetRandomUser(scopeId, $"{Guid.NewGuid()}@gmail.com")).ToArray();

            using var context = new EntityFrameworkDbContext();
            context.Users.AddRange(users);
            context.SaveChanges();

            Assert.That(() => GetUserObjectsCount(scopeId, count), Is.EqualTo(count).After(180000, 1000));
            return(users);
        }
Ejemplo n.º 9
0
 public IActionResult Delete(string date, string time, string lecturer, string status,
                             int id = 0)
 {
     if (status == "Add")
     {
         var lesson = _context.Lessons.Find(id);
         if (lesson != null)
         {
             _context.Lessons.Remove(lesson);
             _context.SaveChanges();
             return(RedirectToAction("Index"));
         }
         return(RedirectToAction("Index"));
     }
     _context.Lessons.Add(new Lesson
     {
         Date        = date,
         BeginLesson = time,
         Lecturer    = lecturer,
         Status      = "Delete"
     });
     _context.SaveChanges();
     return(RedirectToAction("Index"));
 }
Ejemplo n.º 10
0
        public UserInfoResponseModel UserRegister(UserInfoRequestModel request)
        {
            UserInfoResponseModel response = new UserInfoResponseModel();
            UserInfoResponseModel userData = new UserInfoResponseModel()
            {
                UserName = request.UserName, UserNO = request.UserNO, PassWord = request.PassWord
            };

            db.UserInfo.Add(userData);
            int result = db.SaveChanges();

            if (result == 1)
            {
                response.UserNO = request.UserNO;
            }
            return(response);
        }
Ejemplo n.º 11
0
        private FtpUser CreateFtpUser()
        {
            using var context = new EntityFrameworkDbContext();

            var userId  = Guid.NewGuid();
            var ftpUser = new FtpUser
            {
                Login = Guid.NewGuid().ToString(),
                BoxId = Guid.NewGuid().ToString(),
                Id    = userId,
            };

            context.FtpUsers.Add(ftpUser);
            context.SaveChanges();

            Assert.That(GetFtpUser(userId), Is.Not.Null, "Failed to create ftp user");
            return(ftpUser);
        }
Ejemplo n.º 12
0
        public void TestAllowSort()
        {
            using (var context = new EntityFrameworkDbContext())
            {
                var serializer = new Serializer(new AllPropertiesExtractor());
                var customer   = new Customer {
                    Age = 1, Name = "13"
                };
                context.Tests.Add(new TestTable
                {
                    Id                 = 1,
                    CompositeKey       = Guid.NewGuid().ToString(),
                    String             = "123",
                    Customer           = customer,
                    CustomerSerialized = serializer.Serialize(customer),
                });
                context.Users.Add(new UsersTable
                {
                    Email      = "123",
                    Id         = Guid.NewGuid(),
                    Patronymic = "1",
                    Surname    = "2",
                    FirstName  = "3",
                    ScopeId    = "scopeId",
                });
                context.SaveChanges();
            }

            using var browser = new BrowserForTests();

            var usersPage = browser.LoginAsSuperUser().SwitchTo <BusinessObjectTablePage>("UsersTable");

            usersPage = browser.RefreshUntil(usersPage, x => x.BusinessObjectItems.IsPresent.Get());
            usersPage.TableHeader.WaitPresence();
            usersPage.TableHeader.SortByColumn("Header_Id");

            var largeObjectPage = browser.SwitchTo <BusinessObjectTablePage>("TestTable");

            largeObjectPage = browser.RefreshUntil(largeObjectPage, x => x.BusinessObjectItems.IsPresent.Get());
            largeObjectPage.TableHeader.WaitPresence();
            largeObjectPage.TableHeader.WaitNotSortable("Header_Index");
            largeObjectPage.TableHeader.WaitNotSortable("Header_String");
            largeObjectPage.TableHeader.WaitNotSortable("Header_DateTime");
        }
Ejemplo n.º 13
0
        private static void CreateUsers(int count, string scopeId, Guid?id = null)
        {
            if (count > 1 && id != null)
            {
                throw new InvalidOperationException();
            }

            using var context = new EntityFrameworkDbContext();
            context.Users.AddRange(Enumerable.Range(0, count).Select(_ => new UsersTable
            {
                Id         = id ?? Guid.NewGuid(),
                ScopeId    = scopeId,
                Email      = "*****@*****.**",
                FirstName  = "1",
                Surname    = "2",
                Patronymic = "3",
            }));
            context.SaveChanges();
        }
Ejemplo n.º 14
0
        public int UpdatePricesInMainCurrency()
        {
            Currency mainCurrency = EntityFrameworkDbContext.Currencies.SingleOrDefault(x => !x.IsDeleted && x.IsMain);

            if (mainCurrency == null)
            {
                throw new ArgumentNullException("There is no main currency in the system!");
            }
            var productsWithCurrencyRate = from product in DbSet
                                           join cr in
                                           (from currencyRate in EntityFrameworkDbContext.CurrencyRates
                                            where currencyRate.DateOfRate ==
                                            (from currencyRate1 in EntityFrameworkDbContext.CurrencyRates select currencyRate1).Max(currencyRate1 => currencyRate1.DateOfRate)
                                            select currencyRate) on product.CurrencyIdOfThePrice equals cr.CurrencyId
                                           select new { Product = product, CurrencyRate = cr };

            productsWithCurrencyRate.ToList().ForEach(x =>
            {
                x.Product.PriceInTheMainCurrency = x.Product.Price * x.CurrencyRate.Rate;
                Update(x.Product, false);
            });
            return(EntityFrameworkDbContext.SaveChanges());
        }
Ejemplo n.º 15
0
        public int UserInfoUpdate(UserInfoRequestModel request)
        {
            EntityFrameworkDbContext _db = new EntityFrameworkDbContext();
            //修改需要对主键赋值,注意:这里需要对所有字段赋值,没有赋值的字段会用NULL更新到数据库
            var user = new UserInfoResponseModel
            {
                UID       = request.UID,
                UserNO    = request.UserNO,
                UserName  = request.UserName,
                UserEmail = request.UserEmail,
                PassWord  = request.NewPassWord
            };

            //将实体附加到对象管理器中
            _db.UserInfo.Attach(user);

            //获取到状态实体,可以修改其状态
            var setEntry = ((IObjectContextAdapter)_db).ObjectContext.ObjectStateManager.GetObjectStateEntry(user);

            //只修改实体属性
            setEntry.SetModifiedProperty("PassWord");

            return(_db.SaveChanges());
        }
Ejemplo n.º 16
0
 public virtual void Delete(params TEntity[] entities)
 {
     DbSet.RemoveRange(entities);
     EntityFrameworkDbContext.SaveChanges();
 }
Ejemplo n.º 17
0
 private static void CreateSqlDocument(DocumentModel documentModel)
 {
     using var context = new EntityFrameworkDbContext();
     context.Documents.Add(documentModel.ToSqlDocument());
     context.SaveChanges();
 }
Ejemplo n.º 18
0
 public void SaveChanges()
 {
     _dbContext.SaveChanges();
 }
 public int SaveChanges(bool acceptAllChangesOnSuccess = true)
 {
     return(_context.SaveChanges(acceptAllChangesOnSuccess));
 }