Exemplo n.º 1
0
        public async Task <IActionResult> AddSession(AddSessionModel model, IFormCollection image)
        {
            string storePath = "/images/session/";
            var    path      = Path.Combine(
                Directory.GetCurrentDirectory(), "wwwroot", "images", "session",
                image.Files[0].FileName);

            using (var stream = new FileStream(path, FileMode.Create))
            {
                await image.Files[0].CopyToAsync(stream);
            }

            var session = new Session
            {
                SessionName        = model.Name,
                SessionDescription = model.Description,
                SessionImageUrl    = storePath + model.Image.FileName,
                ClassPriceNoMember = model.ClassPriceNoMember,
                ClassPriceMember   = model.ClassPriceMember,
            };

            await _sessionService.Create(session);

            return(RedirectToAction("Index", "Session"));
        }
Exemplo n.º 2
0
        public ActionResult AddSession(AddSessionModel model)
        {
            repo.AddSessionsPack(new Film(model.FilmName, int.Parse(model.FilmYear), CinemaHelper.ConvertStringToGenre(model.FilmGenre),
                                          int.Parse(model.FilmYear), int.Parse(model.FilmLenghtInMinutes), model.FilmCountry),
                                 new Session(Guid.NewGuid(), int.Parse(model.SessionHall), int.Parse(model.SessionPrice), Convert.ToDateTime(model.SessionTime), Status.InStock, 1),
                                 new Hall(int.Parse(model.SessionHall)));

            return(RedirectToAction("Index", "Admin"));
        }
Exemplo n.º 3
0
 public async Task AddSession_GivenSessionWithParticipants_CourseHasSessionParticpants()
 {
     var model = new AddSessionModel()
     {
         Date = DateTime.UtcNow,
         Recordings = new[]
         {
             new Video()
             {
                 Id = 12345678L,
                 Name = "testVideo",
                 RecordTimeUtc = DateTime.UtcNow,
                 Properties = new VideoProperties()
                 {
                     MimeType = "test",
                     Duration = 0,
                     ContainerExt = "test"
                 }
             }
         },
         ParticipantUserIds = new[]
         {
             1234567L
         }
     };
     await fixture.RunWithDatabaseAsync(
         arrange: async db =>
         {
             db.Users.Add(new Admin()
             {
                 Id = 1234567L,
                 UserName = "******"
             });
             await db.SaveChangesAsync();
             return ControllerFactory(db, "testUser12345");
         },
         act: async (_, c) => await c.AddSession(-1, model),
         assert: (result, _, db) =>
         {
             result.Should().BeOfType<OkResult>();
             var courses = db.Courses.AsQueryable<Course>()
                       .Include(c => c.Sessions)
                       .ThenInclude(s => s.Recordings)
                       .Include(c => c.Sessions)
                       .ThenInclude(s => s.DbParticipants)
                       .ThenInclude(p => p.User);
             courses.Should().Contain(c => c.Sessions.Any(s => s.Recordings.Any(v => v.Id == 12345678L)));
             courses.Should().Contain(c => c.Sessions.Any(s => s.Participants.Any(p => p.Id == 1234567L)));
         });
 }
Exemplo n.º 4
0
 public async Task AddSession_GivenSessionWithoutVideos_ReturnsBadRequest()
 {
     var model = new AddSessionModel()
     {
         Date = DateTime.UtcNow
     };
     await fixture.RunWithDatabaseAsync(
         arrange: async db =>
         {
             db.Users.Add(new Admin()
             {
                 UserName = "******"
             });
             await db.SaveChangesAsync();
             return ControllerFactory(db, "testUser12345");
         },
         act: async (_, c) => await c.AddSession(-1, model),
         assert: (result, _, db) => result.Should().BeOfType<BadRequestResult>());
 }
Exemplo n.º 5
0
 public async Task AddSession_CallingUserIsNotAdmin_ReturnsNotAuthorized()
 {
     var model = new AddSessionModel()
     {
         Date = DateTime.UtcNow,
         Recordings = new[] { new Video() }
     };
     await fixture.RunWithDatabaseAsync(
         arrange: async db =>
         {
             db.Users.Add(new Student()
             {
                 UserName = "******"
             });
             await db.SaveChangesAsync();
             return ControllerFactory(db, "testUser12345");
         },
         act: async (_, c) => await c.AddSession(-1, model),
         assert: (result, _) => result.Should().BeOfType<UnauthorizedResult>());
 }
Exemplo n.º 6
0
        public async Task <IActionResult> AddSession([FromRoute] long courseId, [FromBody] AddSessionModel session)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (session == null || session.Recordings == null || session.Recordings.Count == 0)
            {
                return(BadRequest());
            }

            var course = await db.Courses.Where(c => c.Id == courseId).Include(c => c.Sessions).SingleOrDefaultAsync();

            if (course == null)
            {
                return(NotFound());
            }
            if (await this.User(db) is Admin)
            {
                List <User> users = new List <User>();
                if (session.ParticipantUserIds != null && session.ParticipantUserIds.Count > 0)
                {
                    //Contains implementation of ICollection is not supported in EF, so cast to IEnumerable:
                    users = await db.Users.Where(user => (session.ParticipantUserIds as IEnumerable <long>).Contains(user.Id)).ToListAsync();
                }

                db.Videos.AddRange(session.Recordings);
                course.Sessions.Add(new Session
                {
                    Date         = session.Date,
                    Recordings   = session.Recordings,
                    Participants = users
                });
                await db.SaveChangesAsync();

                return(Ok());
            }
            return(Unauthorized());
        }
Exemplo n.º 7
0
        public IActionResult Create()
        {
            var model = new AddSessionModel();

            return(View(model));
        }