Exemplo n.º 1
0
 public List <Booking> ReadAll()
 {
     using (var ctx = new BLContext())
     {
         return(ctx.Bookings.Include("Package").ToList());
     }
 }
Exemplo n.º 2
0
 public List <Package> ReadAll()
 {
     using (var ctx = new BLContext())
     {
         return(ctx.Packages.ToList());
     }
 }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            using (BLContext context = new BLContext())
            {
                //var temp=context.Course.FirstOrDefault();
                //context.Course.Add(new Course { Id = 1, Name = "name", Description = "name1" });
                //context.Category.Add(new Category { CategoryId = "1", CategoryName = "cname" });
                //context.Product.Add(new Product
                //{
                //    ProductId = "1",
                //    ProductName = "aaa"
                //});
                // var rstInt=     context.SaveChanges();
                //context.Category.Add(new Category { CategoryId = "1", CategoryName = "c1", Product = new Product { ProductId = "1", ProductName = "p1" } });
                //  context.Product.Add(new Product { ProductId = "1", ProductName = "p1" });
                context.SaveChanges();
                //var category = context.Category.ToList();
                //var product = context.Product.ToList();

                //context.SignIn.Add(new SignIn
                //{
                //    SignInId = "2",
                //    Operator = "o2"
                //});
                //context.Enroll.Add(new Enroll { EnrollId = "2", EnrollName = "e1", SignIn = new SignIn { SignInId = "2", Operator = "o2" } });
                //context.SaveChanges();
                //XmlWriterSettings settings = new XmlWriterSettings();
                //settings.Indent = true;

                //using (XmlWriter writer = XmlWriter.Create(@"Model.edmx", settings))
                //{
                //    EdmxWriter.WriteEdmx(context, writer);
                //}
            }
        }
Exemplo n.º 4
0
 /*DeleteBL*/
 public async Task <BucketList> GetBLByIDWithBLEsAsync(BLContext context, int?bucketListId)
 {
     return(await context.BucketLists
            .AsNoTracking()
            .Include(bl => bl.BLElements)
            .FirstOrDefaultAsync(bl => bl.BucketListID == bucketListId));
 }
Exemplo n.º 5
0
 public void Add(Package package)
 {
     using (var ctx = new BLContext())
     {
         ctx.Packages.Attach(package);
         ctx.Packages.Add(package);
         ctx.SaveChanges();
     }
 }
Exemplo n.º 6
0
 public void Add(Booking booking)
 {
     using (var ctx = new BLContext())
     {
         ctx.Bookings.Add(booking);
         ctx.Entry(booking.Package).State = System.Data.Entity.EntityState.Unchanged;
         ctx.SaveChanges();
     }
 }
        public async Task PopulateSelectedBLElementsListWithProgressionOrderedByNameAsync_PopulateBLEs_WhenNotOnlyPublicBLEsAreRequired()
        {
            using (var db = new BLContext(Utilities.TestDbContextOptions()))
            {
                // Arrange
                BucketListElement publicBLE2 = new BucketListElement()
                {
                    Name         = "2",
                    Visibility   = Visibility.Public,
                    BucketListID = 1,
                    Progression  = new Progression()
                    {
                        BLETasks = new List <BLETask>()
                    }
                };
                BucketListElement publicBLE1 = new BucketListElement()
                {
                    Name         = "1",
                    Visibility   = Visibility.Public,
                    BucketListID = 1,
                    Progression  = new Progression()
                    {
                        BLETasks = new List <BLETask>()
                    }
                };
                BucketListElement privateBLE1 = new BucketListElement()
                {
                    Name         = "3",
                    Visibility   = Visibility.Private,
                    BucketListID = 1,
                    Progression  = new Progression()
                    {
                        BLETasks = new List <BLETask>()
                    }
                };
                await db.Elements.AddAsync(publicBLE2);

                await db.Elements.AddAsync(publicBLE1);

                await db.Elements.AddAsync(privateBLE1);

                await db.SaveChangesAsync();

                // Act
                var actualBucketListElements = await _bucketListService.PopulateSelectedBLElementsListWithProgressionOrderedByNameAsync(db, 1, false);

                // Assert
                Assert.Equal(3, actualBucketListElements.Count());
                Assert.Equal(publicBLE1, actualBucketListElements.ElementAt(0));
                Assert.Equal(publicBLE2, actualBucketListElements.ElementAt(1));
                Assert.Equal(privateBLE1, actualBucketListElements.ElementAt(2));
                Assert.NotNull(actualBucketListElements.ElementAt(0).Progression.BLETasks);
                Assert.NotNull(actualBucketListElements.ElementAt(1).Progression.BLETasks);
                Assert.NotNull(actualBucketListElements.ElementAt(2).Progression.BLETasks);
            }
        }
Exemplo n.º 8
0
 public void Edit(Package package)
 {
     using (var ctx = new BLContext())
     {
         var packageDB = ctx.Packages.FirstOrDefault(x => x.Id == package.Id);
         packageDB.name  = package.name;
         packageDB.price = package.price;
         ctx.SaveChanges();
     }
 }
Exemplo n.º 9
0
 /*CreateBLE*/
 public async Task <BucketListElement> InitializeBLEWithBLAsync(BLContext context, int?bucketListId)
 {
     return(new BucketListElement
     {
         BucketListID = bucketListId.Value,
         BucketList = await context.BucketLists.FindAsync(bucketListId),
         ElementCategories = new List <ElementCategory>(),
         Progression = new Progression()
     });
 }
Exemplo n.º 10
0
 /*DetailsBLE + EditBLE*/
 public async Task <BucketListElement> GetBLEByIDWithBLETasksAndCategoryAsync(BLContext context, int?bucketListElementId)
 {
     return(await context.BLElements
            .Include(ble => ble.BucketList)
            .Include(ble => ble.Progression)
            .ThenInclude(p => p.BLETasks)
            .Include(ble => ble.ElementCategories)
            .ThenInclude(ec => ec.Category)
            .FirstOrDefaultAsync(ble => ble.ElementID == bucketListElementId));
 }
Exemplo n.º 11
0
        public void Delete(int id)
        {
            Booking booking = Find(id);

            using (var ctx = new BLContext())
            {
                ctx.Bookings.Attach(booking);
                ctx.Bookings.Remove(booking);
                ctx.SaveChanges();
            }
        }
Exemplo n.º 12
0
        public void PropertiesShouldNotBeNull()
        {
            var context = new BLContext();

            context.Users.Should().NotBeNull();
            context.Languages.Should().NotBeNull();
            context.Projects.Should().NotBeNull();
            context.Phrases.Should().NotBeNull();
            context.Translations.Should().NotBeNull();
            context.Votes.Should().NotBeNull();
        }
Exemplo n.º 13
0
        public void Delete(int id)
        {
            Package package = Find(id);

            using (var ctx = new BLContext())
            {
                ctx.Packages.Attach(package);
                ctx.Packages.Remove(package);
                ctx.SaveChanges();
            }
        }
Exemplo n.º 14
0
 public void Edit(Booking booking)
 {
     using (var ctx = new BLContext())
     {
         var bookingDB = ctx.Bookings.Include("Package").FirstOrDefault(x => x.Id == booking.Id);
         ctx.Entry(bookingDB).CurrentValues.SetValues(booking);
         if (bookingDB.Package.Id != booking.Package.Id)
         {
             bookingDB.Package = booking.Package;
             ctx.Entry(booking.Package).State = EntityState.Unchanged;
         }
         ctx.SaveChanges();
     }
 }
        public async Task GetCategoriesOrderedByNameWithElementsAsync_CategoriesReturnedInNameOrder_WhenDatabaseHasCategories()
        {
            using (var db = new BLContext(Utilities.TestDbContextOptions()))
            {
                // Arrange
                var expectedCategories = new Category[]
                {
                    new Category
                    {
                        Name = "1",
                        ElementCategories = new HashSet <ElementCategory>()
                        {
                            new ElementCategory
                            {
                                Element = new BucketListElement {
                                    Name = "ble"
                                }
                            }
                        }
                    },
                    new Category
                    {
                        Name = "0",
                        ElementCategories = new HashSet <ElementCategory>()
                        {
                            new ElementCategory
                            {
                                Element = new Element {
                                    Name = "e"
                                }
                            }
                        }
                    }
                };
                await db.Categories.AddRangeAsync(expectedCategories);

                await db.SaveChangesAsync();

                // Act
                var actualCategories = await _bucketListService.GetCategoriesOrderedByNameWithElementsAsync(db);

                // Assert
                Assert.Equal(2, actualCategories.Count());
                Assert.Equal(expectedCategories[1], actualCategories.ElementAt(0));
                Assert.Equal(expectedCategories[0], actualCategories.ElementAt(1));
                Assert.NotNull(actualCategories.ElementAt(0).ElementCategories.ElementAt(0).Element);
                Assert.NotNull(actualCategories.ElementAt(1).ElementCategories.ElementAt(0).Element);
            }
        }
Exemplo n.º 16
0
 public async Task <IEnumerable <BLUser> > SearchUsers(BLContext context, string searchString, ClaimsPrincipal User)
 {
     if (!String.IsNullOrEmpty(searchString))
     {
         return(await context.Users
                .AsNoTracking()
                .Where(u => u.FullName.Contains(searchString))
                .Where(u => u.Id != GetUserId(User))
                .ToListAsync());
     }
     else
     {
         return(await context.Users
                .AsNoTracking()
                .Where(u => u.SeededUser == true)
                .Where(u => u.Id != GetUserId(User))
                .ToListAsync());
     }
 }
Exemplo n.º 17
0
        public async Task UpdateBLElementCategoriesAsync(BLContext context, string[] selectedCategories, BucketListElement BLElementToUpdate)
        {
            if (selectedCategories == null)
            {
                BLElementToUpdate.ElementCategories = new List <ElementCategory>();
                return;
            }

            //Categories before editing
            var BLElementCategoriesBeforeEdit = new HashSet <int>(BLElementToUpdate.ElementCategories.Select(ec => ec.Category.CategoryID));
            //Categories selected at editing
            var BLElementCategoriesAfterEdit = new HashSet <string>(selectedCategories);
            var allCategories = await context.Categories
                                .AsNoTracking()
                                .ToListAsync();

            foreach (var category in allCategories)
            {
                if (BLElementCategoriesAfterEdit.Contains(category.CategoryID.ToString()))
                {
                    //Selected categories contain, but old categories don't -> Add
                    if (!BLElementCategoriesBeforeEdit.Contains(category.CategoryID))
                    {
                        ElementCategory categoryToAdd = new ElementCategory
                        {
                            ElementID  = BLElementToUpdate.ElementID,
                            CategoryID = category.CategoryID
                        };
                        BLElementToUpdate.ElementCategories.Add(categoryToAdd);
                    }
                }
                else
                {
                    //Selected categories don't contain, but old categories do -> Remove
                    if (BLElementCategoriesBeforeEdit.Contains(category.CategoryID))
                    {
                        ElementCategory categoryToRemove =
                            BLElementToUpdate.ElementCategories.SingleOrDefault(ec => ec.CategoryID == category.CategoryID);
                        BLElementToUpdate.ElementCategories.Remove(categoryToRemove);
                    }
                }
            }
        }
        public async Task GetBLByIDAsync_BucketListIsReturned_WhenItIsFoundInDatabase()
        {
            using (var db = new BLContext(Utilities.TestDbContextOptions()))
            {
                // Arrange
                BucketList expectedBucketList = new BucketList()
                {
                    BucketListID = 1
                };
                await db.BucketLists.AddAsync(expectedBucketList);

                await db.SaveChangesAsync();

                // Act
                var actualBucketList = await _bucketListService.GetBLByIDAsync(db, 1);

                // Assert
                Assert.Equal(expectedBucketList, actualBucketList);
            }
        }
Exemplo n.º 19
0
        /// <summary>
        /// Конструктор.
        /// </summary>
        public FormMain()
        {
            InitializeComponent();
            MyInitializeComponent();

            ContextMenuGetter.TreeView = myTreeView;
            ContextMenuGetter.Plan     = picContainer;

            Dialogs.Owner    = this;
            Dialogs.TreeView = myTreeView;
            Dialogs.Plan     = picContainer;

            using (var db = new BLContext())
            {
                db.Database.Initialize(false);
            }

            myTreeView.LoadFromContext();
            myTreeView.MouseClickSign += picContainer.LoadImage;
            ReportMenu.Click          += (s, e) => new FormReport().Show(this);
            TypesEquipmentMenu.Click  += (s, e) => new FormKinds().ShowDialog(this);
            StickersMenu.Click        += (s, e) => new FormStickers().Show(this);
            SettingsMenu.Click        += SettingsMenu_Click;
        }
 public CreateModel(BLContext context, IUserService userService)
 {
     _context     = context;
     _userService = userService;
 }
 public DeleteModel(BLContext context, IUserService userService, IBucketListService bucketListService)
 {
     _context           = context;
     _userService       = userService;
     _bucketListService = bucketListService;
 }
Exemplo n.º 22
0
 public IndexModel(BLContext context, IBucketListService bucketListService)
 {
     _context           = context;
     _bucketListService = bucketListService;
 }
Exemplo n.º 23
0
 public async Task <BLUser> FindUserByID(BLContext context, string userId)
 {
     return(await context.Users.FindAsync(userId));
 }
Exemplo n.º 24
0
        public async Task <SelectList> PopulateBucketListDropDownListOrderedByNameAsync(BLContext context, string userId, bool publicOnly, bool addDefaultValue, object selectedBucketList = null)
        {
            List <SelectListItem> SelectListItems = new List <SelectListItem>();

            if (addDefaultValue)
            {
                SelectListItems.Add(new SelectListItem()
                {
                    Text  = "--Válassz egy listát--",
                    Value = "null"
                });
            }

            IEnumerable <BucketList> BucketListsQuery;

            if (publicOnly)
            {
                BucketListsQuery = await context.BucketLists
                                   .AsNoTracking()
                                   .Where(bl => bl.UserId == userId)
                                   .Where(bl => bl.Visibility == Visibility.Public)
                                   .OrderBy(bl => bl.Name)
                                   .ToListAsync();
            }
            else
            {
                BucketListsQuery = await context.BucketLists
                                   .AsNoTracking()
                                   .Where(bl => bl.UserId == userId)
                                   .OrderBy(bl => bl.Name)
                                   .ToListAsync();
            }

            foreach (BucketList bl in BucketListsQuery)
            {
                SelectListItems.Add(new SelectListItem()
                {
                    Text  = bl.Name,
                    Value = bl.BucketListID.ToString()
                });
            }

            return(new SelectList(SelectListItems, "Value", "Text", selectedBucketList));
        }
Exemplo n.º 25
0
 public IndexModel(BLContext context, IUserService userService)
 {
     _context     = context;
     _userService = userService;
 }
Exemplo n.º 26
0
 /*Collection page*/
 public async Task <IEnumerable <Category> > GetCategoriesOrderedByNameWithElementsAsync(BLContext context)
 {
     return(await context.Categories
            .Include(c => c.ElementCategories)
            .ThenInclude(ec => ec.Element)
            .OrderBy(c => c.Name)
            .ToListAsync());
 }
Exemplo n.º 27
0
 public async Task <BucketList> GetBLByIDAsync(BLContext context, int?bucketListId)
 {
     return(await context.BucketLists.FindAsync(bucketListId));
 }
Exemplo n.º 28
0
 public static void Init(TestContext context)
 {
     _context = new BLContext();
 }
Exemplo n.º 29
0
        public async Task <IEnumerable <BucketListElement> > PopulateSelectedBLElementsListWithProgressionOrderedByNameAsync(BLContext context, int SelectedBucketListID, bool PublicOnly)
        {
            if (PublicOnly)
            {
                return(await context.BLElements
                       .Include(ble => ble.Progression)
                       .ThenInclude(p => p.BLETasks)
                       .Where(ble => ble.BucketListID == SelectedBucketListID)
                       .Where(ble => ble.Visibility == Visibility.Public)
                       .OrderBy(ble => ble.Name)
                       .ToListAsync());
            }

            else
            {
                return(await context.BLElements
                       .Include(ble => ble.Progression)
                       .ThenInclude(p => p.BLETasks)
                       .Where(ble => ble.BucketListID == SelectedBucketListID)
                       .OrderBy(ble => ble.Name)
                       .ToListAsync());
            }
        }
Exemplo n.º 30
0
        public async Task <List <AssignedCategoryData> > PopulateAssignedCategoryDataAsync(BLContext context, BucketListElement BLElement)
        {
            var allCategories = await context.Categories
                                .AsNoTracking()
                                .ToListAsync();

            var BLCategories = new HashSet <int>(BLElement.ElementCategories.Select(ec => ec.CategoryID));
            List <AssignedCategoryData> assignedCategoryDataList = new List <AssignedCategoryData>();

            foreach (var category in allCategories)
            {
                assignedCategoryDataList.Add(new AssignedCategoryData
                {
                    CategoryID = category.CategoryID,
                    Name       = category.Name,
                    Assigned   = BLCategories.Contains(category.CategoryID)
                });
            }
            return(assignedCategoryDataList);
        }