Ejemplo n.º 1
0
        public async Task <IActionResult> Delete(int id)
        {
            var workshopToDelete = await _service.GetById(id);

            if (workshopToDelete == null)
            {
                return(NotFound());
            }

            await _service.Delete(workshopToDelete);

            return(Ok());
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> PostRegistration(CreateRegistrationRequest request)
        {
            var existingRegistration = await _registrationService.GetByUserAndWorkshopIds(request.UserId, request.WorkshopId);

            var workshopToUpdate = await _workshopService.GetById(request.WorkshopId);

            if (existingRegistration == null && request.IsPaid)
            {
                await _registrationService.Create(new Registration
                {
                    UserId     = request.UserId,
                    WorkshopId = request.WorkshopId,
                    IsPaid     = request.IsPaid,
                    IsDesired  = false,
                });

                workshopToUpdate.CurrentUsersCount++;
                await _workshopService.Update(workshopToUpdate);
            }
            else if (request.IsDesired)
            {
                await _registrationService.Create(new Registration
                {
                    UserId     = request.UserId,
                    WorkshopId = request.WorkshopId,
                    IsPaid     = false,
                    IsDesired  = request.IsDesired,
                });
            }
            else
            {
                existingRegistration.IsPaid    = true;
                existingRegistration.IsDesired = false;
                await _registrationService.Update(existingRegistration);

                workshopToUpdate.CurrentUsersCount++;
                await _workshopService.Update(workshopToUpdate);
            }

            return(Ok());
        }
        public async Task <IActionResult> GetById([FromRoute] Guid id)
        {
            var workshop = await service.GetById(id);

            return(Ok(workshop));
        }