Beispiel #1
0
        public void DeleteParticipation(DeleteParticipationRequest request, string code)
        {
            if (!WebinarExists(code))
            {
                throw new WebinarNotExistException("");
            }
            if (!UserExists(request.Login))
            {
                throw new UserNotExistException("");
            }
            if (!ParticipationExists(getIdUserByLogin(request.Login), getIdWebinarByCode(code)))
            {
                throw new NotSignedUpToWebinarException("");
            }
            if (_context.Webinars.Where(x => x.Code == code).FirstOrDefault().Date < DateTime.Now)
            {
                throw new DoneWebinarException("");
            }

            UserWebinar participation = _context.UserWebinars.
                                        Where(x => x.IdUser == getIdUserByLogin(request.Login)).
                                        Where(x => x.IdWebinar == getIdWebinarByCode(code)).
                                        FirstOrDefault();

            _context.UserWebinars.Remove(participation);
            _context.SaveChanges();
        }
Beispiel #2
0
        public void EditParticipation(EditParticipationRequest request, string code)
        {
            int IdUser    = getIdUserByLogin(request.Login);
            int IdWebinar = getIdWebinarByCode(code);

            if (!ParticipationExists(IdUser, IdWebinar))
            {
                throw new NotSignedUpToWebinarException("");
            }
            if (_context.Webinars.Where(x => x.Code == code).FirstOrDefault().Date > DateTime.Now)
            {
                throw new NotFinishedWebinarException("");
            }

            UserWebinar participation = _context.UserWebinars.
                                        Where(x => x.IdUser == IdUser).
                                        Where(x => x.IdWebinar == IdWebinar).FirstOrDefault();

            if (participation.Note != null)
            {
                throw new AlreadyNotedWebinarException("");
            }

            participation.Note = (UserWebinar.NoteName)request.Note;
            _context.SaveChanges();
        }
Beispiel #3
0
 public UserWebinar Update(UserWebinar userWebinar)
 => Execute(context =>
 {
     var entInDb = context.UserWebinars.Update(userWebinar);
     context.SaveChanges();
     return(entInDb.Entity);
 });
Beispiel #4
0
        public UserWebinar SignUpToWebinar(AddParticipationRequest request, string code)
        {
            int IdUser    = getIdUserByLogin(request.Login);
            int IdWebinar = getIdWebinarByCode(code);

            if (_context.UserWebinars
                .Where(x => x.IdUser == IdUser)
                .Where(x => x.IdWebinar == IdWebinar).Any())
            {
                throw new AlreadySignedUpToWebinarException("");
            }
            if (_context.Webinars.Where(x => x.Code == code).FirstOrDefault().Date.AddDays(1) < DateTime.Now)
            {
                throw new SignUpToFinishedWebinarException("");
            }

            UserWebinar participation;

            _context.UserWebinars.Add(participation = new UserWebinar
            {
                IdUser    = IdUser,
                IdWebinar = IdWebinar,
            });
            _context.SaveChanges();
            return(participation);
        }
Beispiel #5
0
 public UserWebinar Create(UserWebinar userWebinar)
 => Execute(context =>
 {
     var createUserWebinar = context.UserWebinars.Add(userWebinar);
     context.SaveChanges();
     return(createUserWebinar.Entity);
 });
Beispiel #6
0
        public IActionResult Put(int id, [FromBody] UserWebinar userWebinar)
        {
            userWebinar.Id = id;
            var updateUserWebinar = userWebinarBL.Update(userWebinar);

            return(Ok(updateUserWebinar));
        }
Beispiel #7
0
 public void Delete(int id)
 => Execute(context =>
 {
     var entity = new UserWebinar {
         Id = id
     };
     context.UserWebinars.Remove(entity);
     context.SaveChanges();
 });
Beispiel #8
0
        public WebinarResponse GetWebinar(string studentLogin, string code)
        {
            if (!WebinarExists(code))
            {
                throw new WebinarNotExistException("");
            }
            Webinar webinar = _context.Webinars.Where(x => x.Code == code).FirstOrDefault();

            User user;

            if (!(studentLogin == null))
            {
                if (!UserExists(studentLogin))
                {
                    throw new UserNotExistException("");
                }
                user = _context.Users.Where(x => x.Login == studentLogin).FirstOrDefault();
            }

            int?   idTeacher = _context.Webinars.Where(x => x.Code == code).FirstOrDefault().IdUser;
            string teacher   = null;

            if (!(idTeacher == null))
            {
                teacher = _context.Users.Where(x => x.IdUser == idTeacher).FirstOrDefault().Name
                          + " " + _context.Users.Where(x => x.IdUser == idTeacher).FirstOrDefault().Surname;
            }

            UserWebinar participation  = null;
            int?        note           = null;
            Boolean     isNotedByUser  = false;
            Boolean     isUserSignedUp = false;

            if (!(studentLogin == null))
            {
                if (ParticipationExists(getIdUserByLogin(studentLogin), getIdWebinarByCode(code)))
                {
                    participation = _context.UserWebinars.Where(x => x.IdUser == getIdUserByLogin(studentLogin))
                                    .Where(x => x.IdWebinar == getIdWebinarByCode(code)).FirstOrDefault();
                    isUserSignedUp = true;
                    note           = (int?)participation.Note;
                    if (note != null)
                    {
                        isNotedByUser = true;
                    }
                }
            }
            Boolean isUserATeacher = false;

            if (!(studentLogin == null))
            {
                if (idTeacher == getIdUserByLogin(studentLogin))
                {
                    isUserATeacher = true;
                }
            }

            Boolean isFinished = false;

            if (DateTime.Now > webinar.Date.AddDays(1))
            {
                isFinished = true;
            }


            var webinarResponse = new WebinarResponse
            {
                Topic          = webinar.Topic,
                Code           = webinar.Code,
                Date           = webinar.Date.ToString("yyyy-MM-dd"),
                Start          = webinar.StartTime.ToString("hh:mm"),
                End            = webinar.EndTime.ToString("hh:mm"),
                Teacher        = teacher,
                Note           = note,
                IsFinished     = isFinished,
                IsNotedByUser  = isNotedByUser,
                IsUserATeacher = isUserATeacher,
                IsUserSignedUp = isUserSignedUp
            };

            return(webinarResponse);
        }
        public IActionResult SignUpToWebinar(AddParticipationRequest request, string code)
        {
            UserWebinar participation = _context.SignUpToWebinar(request, code);

            return(Created("", "You signed up to webinar successfully"));
        }
Beispiel #10
0
 public UserWebinar Update(UserWebinar userWebinar)
 {
     return(userWebinarRepository.Update(userWebinar));
 }
Beispiel #11
0
 public UserWebinar Create(UserWebinar userWebinar)
 {
     return(userWebinarRepository.Create(userWebinar));
 }