Exemplo n.º 1
0
        public ActionResult CreateParticipation([Bind(Include = "ParticipationId,EventId,UserId")] Participation participation)
        {
            if (ModelState.IsValid)
            {
                Event e = eventService.GetById(participation.EventId);
                if (e.Capacite > 0)
                {
                    Participation p = new Participation();
                    p.EventId = participation.EventId;
                    p.UserId  = participation.UserId;
                    participationService.Add(p);
                    participationService.Commit();

                    e.Capacite--;
                    eventService.Update(e);
                    eventService.Commit();
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ViewBag.msg = "pas de places";
                }
            }

            ViewBag.EventId = new SelectList(eventService.GetMany(), "EventId", "Titre", participation.EventId);
            ViewBag.UserId  = new SelectList(userService.GetMany(), "UserId", "Username", participation.UserId);
            return(View("Participation/Create", participation));
        }
Exemplo n.º 2
0
        public async Task <ActionResult <ParticipationViewModel> > Add(ParticipationViewModel participationViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(CustomResponse(ModelState));
            }

            await _participationService.Add(_mapper.Map <Participation>(participationViewModel));

            return(CustomResponse(participationViewModel));
        }
        public async Task <IActionResult> Register(long eventId)
        {
            long userId         = 1; //TODO:
            var  participations = await _participationService.GetByEventId(eventId);

            if (participations.Select(x => x.UserId).Contains(userId))
            {
                return(Ok("Already registered"));
            }

            var participation = Participation.Create(eventId, userId);
            await _participationService.Add(participation);

            return(Ok("Successful registered"));
        }