Exemplo n.º 1
0
        public void OnGet(int id)

        {
            ViewData["Modules"] = _dbReadService.GetSelectList <Module>("Id", "Title");

            Input = _dbReadService.Get <Video>(id, true);
        }
Exemplo n.º 2
0
        public IActionResult IsItemNumberUnique()
        {
            string itemNumber = Request.QueryString.Value.Split('=')[1];
            var    result     = _dbReadService.Get <Product>().Any(p => p.ItemNumber.Equals(itemNumber));

            return(Json(!result));
        }
Exemplo n.º 3
0
 public void OnGet(int courseId, string userId)
 {
     ViewData["Genres"]     = _dbReadService.GetSelectList <Genre>("Id", "Title");
     Input.UserGenre        = _dbReadService.Get <UserGenre>(userId, courseId);
     Input.UpdatedUserGenre = Input.UserGenre;
     Input.GenreTitle       = _dbReadService.Get <Genre>(courseId).Title;
     Input.Email            = _userService.GetUser(userId).Email;
 }
Exemplo n.º 4
0
        public void OnGet(int courseId, string userId)
        {
            var user   = _userService.GetUser(userId);
            var course = _dbReadService.Get <Course>(courseId);

            Input.UserCourse  = _dbReadService.Get <UserCourse>(userId, courseId);
            Input.Email       = user.Email;
            Input.CourseTitle = course.Title;
        }
Exemplo n.º 5
0
        public Course GetCourse(string userId, int courseId)
        {
            // Check that the user is allowed to access the requested course by calling the Get method on the _db service variable
            // Use the UserCourse entity to define the method’s type. Pass in the values of the userId and courseId parameters to the method and check that the result isn’t null
            var hasAccess = _db.Get <UserCourse>(userId, courseId) != null;

            // Return the default value (null) for the Course entity if the user doesn’t have access to the course.
            if (!hasAccess)
            {
                return(default(Course));
            }

            // Fetch the course by calling the Get method on the _db service variable.
            // Pass in the value form the courseId parameter and the value true to specify that related entities should be filled with data.
            var course = _db.Get <Course>(courseId, true);

            // Iterate over the modules in the Modules property of the course and add the downloads and videos
            foreach (var module in course.Modules)
            {
                module.Downloads = _db.Get <Download>().Where(d =>
                                                              d.ModuleId.Equals(module.Id)).ToList();
                module.Videos = _db.Get <Video>().Where(d =>
                                                        d.ModuleId.Equals(module.Id)).ToList();
            }

            return(course);
        }
        public Course GetCourse(string userId, int courseId)

        {
            var hasAccess = _db.Get <UserCourse>(userId, courseId) != null;

            if (!hasAccess)
            {
                return(default(Course));
            }



            var course = _db.Get <Course>(courseId, true);



            foreach (var module in course.Modules)

            {
                module.Downloads = _db.Get <Download>().Where(d =>

                                                              d.ModuleId.Equals(module.Id)).ToList();



                module.Videos = _db.Get <Video>().Where(d =>

                                                        d.ModuleId.Equals(module.Id)).ToList();
            }



            return(course);
        }
Exemplo n.º 7
0
        public void OnGet(int courseId, string userId)
        {
            ViewData["Courses"]     = _dbReadService.GetSelectList <Course>("Id", "Title");
            Input.UserCourse        = _dbReadService.Get <UserCourse>(userId, courseId);
            Input.UpdatedUserCourse = Input.UserCourse;
            var course = _dbReadService.Get <Course>(courseId);
            var user   = _userService.GetUser(userId);

            Input.CourseTitle = course.Title;
            Input.Email       = user.Email;
        }
Exemplo n.º 8
0
 public void OnGet(int id)
 {
     Input                  = _dbReadService.Get <Video>(id, true);
     Input.Album.Band       = _dbReadService.Get <Band>(Input.Album.BandId);
     ViewData["Thumbnails"] = new SelectList(
         new List <string>
     {
         "/images/video1.jpg",
         "/images/video2.jpg",
         "/images/video3.jpg",
         "/images/video4.jpg",
         "/images/video5.jpg"
     });
 }
Exemplo n.º 9
0
        public void OnGet(string itemNumber, int catId = 0, int styleId = 0, int locationId = 0)
        {
            items                  = _dbReadService.GetWithIncludes <ProductInventory>();
            productList            = _dbReadService.GetWithIncludes <Product>();
            ViewData["Categories"] = _dbReadService.GetSelectList <Category>("CategoryId", "Name");
            ViewData["Styles"]     = _dbReadService.GetSelectList <Style>("StyleId", "Name");
            ViewData["Locations"]  = _dbReadService.GetSelectList <Location>("LocationId", "Name");

            if (styleId > 0)
            {
                items = items.Where(pv => pv.StyleId == styleId);
            }
            if (locationId > 0)
            {
                items = items.Where(pv => pv.LocationId == locationId);
            }
            if (catId > 0)
            {
                var products = _dbReadService.Get <Product>()
                               .Where(p => p.CategoryId == catId)
                               .Select(p => p.ProductId);
                if (products.Count() > 0)
                {
                    items = items.Where(pv => products.Contains(pv.ProductId));
                }
                else
                {
                    //never true, we do this because we cannot set items to null directly
                    items = items.Where(pv => pv.ProductId < 0);
                }
            }
            if (!string.IsNullOrEmpty(itemNumber))
            {
                var product = _dbReadService.Get <Product>()
                              .Where(p => p.ItemNumber.Equals(itemNumber))
                              .FirstOrDefault();
                if (product != null)
                {
                    items = items.Where(pv => pv.ProductId == product.ProductId);
                }
                else
                {
                    items = items.Where(pv => pv.ProductId < 0);
                }
            }
            //sort items by category, itemNumber, style and location
            items = items.OrderBy(pi => pi.Product.CategoryId).ThenBy(pi => pi.Product.ItemNumber)
                    .ThenBy(pi => pi.Style.Name).ThenBy(pi => pi.Location.Name);
        }
Exemplo n.º 10
0
        public async Task <IActionResult> OnPostAsync()
        {
            //Retrive data for drop downs and store them in view data
            StoreSelectListInViewData();

            //Retreive the names for item, style, and location based on Ids
            var itemNumber = _dbReadService.Get <Product>(Input.ProductId)?.ItemNumber;
            var style      = _dbReadService.Get <Style>(Input.StyleId)?.Name;
            var location   = _dbReadService.Get <Location>(Input.LocationId)?.Name;

            //check if composite primary key already exists in the database
            var pi = _dbReadService.Get <ProductInventory>(Input.ProductId, Input.StyleId, Input.LocationId);

            if (pi != null)
            {
                ModelState.AddModelError("DuplicateKey", "Duplicate Keys");

                ErrorMsg = "There is already an inventory entry for " +
                           $"item # <strong>{itemNumber}</strong> with style of <strong>{style}</strong> at <strong>{location}</strong>." +
                           " Please select a different item number, style, and location combination or click " +
                           $@"<a href='/ProductInventories/Edit?ProductId={Input.ProductId}&StyleId={Input.StyleId}&LocationId={Input.StyleId}'>here</a>" +
                           " to edit the existing entry.";

                MsgInHtmlString = new HtmlString(ErrorMsg);
                return(Page());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var result = await _dbWriteService.Add(Input);

                    if (result)
                    {
                        //Message sent back to Index razor page
                        StatusMessage = $"Created a new inventory entry for Item {itemNumber}, Style: {style}, Location: {location}.";
                        return(RedirectToPage("Index"));
                    }
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("", ex.Message);
                }
            }
            //something failed, redisplay the form
            return(Page());
        }
Exemplo n.º 11
0
        public async Task <IActionResult> OnPostAsync()
        {
            Input.Band  = _dbReadService.Get <Band>(Input.BandId, true);
            Input.Genre = _dbReadService.Get <Genre>(Input.Band.GenreId, true);
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            var success = await _dbWriteService.Add(Input);

            if (!success)
            {
                return(Page());
            }
            StatusMessage = $"Created a new Album: {Input.Title}.";
            return(RedirectToPage("Index"));
        }
Exemplo n.º 12
0
 public void OnGet()
 {
     Items = _dbReadService.GetWithIncludes <AlbumInfo>();
     foreach (var item in Items)
     {
         item.Album.Band = _dbReadService.Get <Band>(item.Album.BandId);
     }
 }
Exemplo n.º 13
0
 public void OnGet(int id)
 {
     Input = _dbReadService.Get <Genre>(id);
     ViewData["Images"] = new SelectList(
         new List <string>
     {
         "/images/genre1.jpg",
         "/images/genre2.jpg",
         "/images/genre3.jpg",
     });
 }
Exemplo n.º 14
0
        public void OnGet()
        {
            var videos     = _dbReadService.GetWithIncludes <Video>();
            var enumerable = videos as Video[] ?? videos.ToArray();

            foreach (var video in enumerable)
            {
                video.Album.Band = _dbReadService.Get <Band>(video.Album.BandId);
            }
            Items = enumerable;
        }
Exemplo n.º 15
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            Input.AlbumId  = _dbReadService.Get <Album>(Input.AlbumId).Id;
            Input.Position = 1;
            var success = await _dbWriteService.Add(Input);

            if (!success)
            {
                return(Page());
            }
            StatusMessage = $"Created a new Video: {Input.Title}.";
            return(RedirectToPage("Index"));
        }
Exemplo n.º 16
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (ModelState.IsValid)
            {
                Input.CourseId = _dbReadService.Get <Module>(Input.ModuleId).CourseId;
                var success = await _dbWriteService.Add(Input);

                if (success)
                {
                    StatusMessage = $"Created a new Download: {Input.Title}.";
                    return(RedirectToPage("Index"));
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }
Exemplo n.º 17
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            var success = await _dbWriteService.Add(Input);

            if (!success)
            {
                return(Page());
            }
            var genre = _dbReadService.Get <Genre>(Input.GenreId);
            var user  = _userService.GetUser(Input.UserId);

            StatusMessage = $"User-Genre combination {genre.Title}/{user.Email} was created.";
            return(RedirectToPage("Index"));
        }
Exemplo n.º 18
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (ModelState.IsValid)
            {
                var success = await _dbWriteService.Add(Input);

                if (success)
                {
                    var user   = _userService.GetUser(Input.UserId);
                    var course = _dbReadService.Get <Course>(Input.CourseId);
                    StatusMessage = $"User-Course combination [{course.Title} | {user.Email}] was created.";
                    return(RedirectToPage("Index"));
                }
            }

            // If we got this far, something failed, redisplay form
            ViewData["Users"]   = _dbReadService.GetSelectList <User>("Id", "Email");
            ViewData["Courses"] = _dbReadService.GetSelectList <Course>("Id", "Title");
            return(Page());
        }
Exemplo n.º 19
0
 public void OnGet(int id)
 {
     Input = _dbReadService.Get <Band>(id);
 }
Exemplo n.º 20
0
 public void OnGet()
 {
     Items = _dbReadService.Get <Instructor>();
 }
Exemplo n.º 21
0
 public void OnGet(int id)
 {
     Input = _dbReadService.Get <Album>(id, true);
 }
Exemplo n.º 22
0
 public void OnGet(int productId, int styleId, int locationId)
 {
     Input = _dbReadService.Get <ProductInventory>(productId, styleId, locationId, includeRelatedEntities: true);
     ViewData["Category"] = _dbReadService.Get <Category>().Where(c => c.CategoryId == Input.Product.CategoryId).FirstOrDefault()?.Name;
 }
Exemplo n.º 23
0
 public void OnGet(int id)
 {
     ViewData["Albums"] = _dbReadService.GetSelectList <Album>("Id", "Title");
     Input = _dbReadService.Get <AlbumInfo>(id, true);
 }
Exemplo n.º 24
0
 public void OnGet(int id)
 {
     Input = _dbReadService.Get <Band>(id);
     ViewData["Genres"] = _dbReadService.GetSelectList <Genre>("Id", "Title");
 }
Exemplo n.º 25
0
 public void OnGet(int id)
 {
     ViewData["Categories"] = _dbReadService.GetSelectList <Category>("CategoryId", "Name");
     Input = _dbReadService.Get <Product>(id, false);
 }
Exemplo n.º 26
0
 public void OnGet(int id)
 {
     Input = _dbReadService.Get <Instructor>(id);
 }
Exemplo n.º 27
0
 public void OnGet(int id)
 {
     Input = _dbReadService.Get <Course>(id, true);
 }
Exemplo n.º 28
0
        public void OnGet(int id)

        {
            Input = _dbReadService.Get <Video>(id, true);
        }
Exemplo n.º 29
0
 public void OnGet(int id)
 {
     ViewData["Instructors"] = _dbReadService.GetSelectList <Instructor>("Id", "Name");
     Input = _dbReadService.Get <Course>(id);
 }
Exemplo n.º 30
0
 public void OnGet(int id)
 {
     Input = _dbReadService.Get <Location>(id, false);
 }