示例#1
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);
        }
        public IActionResult SignUpToWebinar(AddParticipationRequest request, string code)
        {
            UserWebinar participation = _context.SignUpToWebinar(request, code);

            return(Created("", "You signed up to webinar successfully"));
        }