Beispiel #1
0
        public async Task <IHttpActionResult> PostEventWithTicket(EventWithTicket eventWithTicket)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.EventsWithTickets.Add(eventWithTicket);
            await db.SaveChangesAsync();

            // New code:
            // Load Evento
            db.Entry(eventWithTicket).Reference(x => x.City).Load();

            var dto = new EventWithTicketDTO()
            {
                EventWithTicketID = eventWithTicket.EventWithTicketID,
                Name        = eventWithTicket.Name,
                Description = eventWithTicket.Description,
                City        = eventWithTicket.City.CityName,
                Transport   = eventWithTicket.Transport.TransportType,
                EventDate   = eventWithTicket.EventDate,
                Adress      = eventWithTicket.Addres,
                Price       = eventWithTicket.Price,
                MaxTickets  = eventWithTicket.MaxTicket
            };

            return(CreatedAtRoute("DefaultApi", new { id = eventWithTicket.EventWithTicketID }, eventWithTicket));
        }
        public async Task <IActionResult> Create(EventsManagerModel new_event)
        {
            Event     event_to_add = new_event.Event;
            EventType find_type    = await EventsContext.EventTypes.FirstOrDefaultAsync(p => p.Id == new_event.EventTypes_id);

            event_to_add.Type = find_type;
            EventsContext.Events.Add(event_to_add);
            await EventsContext.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Beispiel #3
0
        public async Task <ActionResult> Create([Bind(Include = "TicketID,EventWithTicketID,Description")] Tick tick)
        {
            if (ModelState.IsValid)
            {
                db.Ticks.Add(tick);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            ViewBag.EventWithTicketID = new SelectList(db.EventsWithTickets, "EventWithTicketID", "Name", tick.EventWithTicketID);
            return(View(tick));
        }
Beispiel #4
0
        public async Task AddToDb(EventCallbackModel eventCallback)
        {
            foreach (EventModel em in eventCallback.events)
            {
                if (em.objectType == "cell")
                {
                    em.cellValue = _smartsheetService.GetCellValue(eventCallback.scopeObjectId, em.rowId.Value, em.columnId.Value);
                }
            }

            _context.AddRange(eventCallback);
            await _context.SaveChangesAsync();
        }
Beispiel #5
0
        public async Task <IActionResult> Post([FromBody] Event item)
        {
            if (item == null)
            {
                return(BadRequest());
            }

            await _context.Events.AddAsync(item);

            await _context.SaveChangesAsync();

            return(CreatedAtRoute("Get", new { id = item.Id }, item));
        }
Beispiel #6
0
        public async Task <ActionResult> Create([Bind(Include = "ReservaID,TicketID,PersonID")] Ticket ticket)
        {
            if (ModelState.IsValid)
            {
                db.Tickets.Add(ticket);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            ViewBag.PersonID = new SelectList(db.Persons, "PersonID", "DNI", ticket.PersonID);
            ViewBag.TicketID = new SelectList(db.Ticks, "TicketID", "TicketID", ticket.TicketID);
            return(View(ticket));
        }
        public async Task <IActionResult> Create([Bind("id,event_type,date,place,name,hour,tickets,tickets_per_person,organisator")] EventsModel eventsModel)
        {
            var userID = HttpContext.User.Identity.Name;

            eventsModel.organizer = userID;
            if (ModelState.IsValid)
            {
                _context.Add(eventsModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(eventsModel));
        }
Beispiel #8
0
        public async Task <IActionResult> SignIn([FromServices] EventsContext eventsContext, [FromServices] BlobContext blobContext, int id)
        {
            var eventItem = await eventsContext.Events.SingleOrDefaultAsync(e => e.Id == id);

            SignInSheetState signInSheetState = default(SignInSheetState);

            if (String.IsNullOrEmpty(eventItem.SignInDocumentUrl))
            {
                using (Stream stream = new MemoryStream())
                {
                    await blobContext.UploadBlobAsync($"{eventItem.EventKey}.docx", stream);
                }
                eventItem.SignInDocumentUrl = PROCESSING_URI;
                await eventsContext.SaveChangesAsync();

                signInSheetState = SignInSheetState.SignInDocumentProcessing;
            }
            else if (eventItem.SignInDocumentUrl == PROCESSING_URI)
            {
                signInSheetState = SignInSheetState.SignInDocumentProcessing;
            }
            else
            {
                signInSheetState = SignInSheetState.SignInDocumentAlreadyExists;
            }

            SignInSheetViewModel viewModel = new SignInSheetViewModel
            {
                Event            = eventItem,
                SignInSheetState = signInSheetState
            };

            return(View(viewModel));
        }
Beispiel #9
0
        public async Task <IActionResult> Create(CreateEventModel model)
        {
            if (ModelState.IsValid)
            {
                Events even = await db.Events.FirstOrDefaultAsync(u => u.Name == model.Name);

                if (even == null)
                {
                    Random rand = new Random();
                    int    i    = rand.Next(1, 1000);
                    db.Events.Add(new Events {
                        Id = i * 5, Name = model.Name, Type = model.Type, Description = model.Description, Date = model.Date
                    });
                    await db.SaveChangesAsync();

                    return(View("Index", "Events"));
                }
                else
                {
                    ModelState.AddModelError("", "Something went wrong...");
                }
                return(View(model));
            }
            return(View(model));
        }
        public async Task <IActionResult> SignIn([FromServices] EventsContext eventsContext, [FromServices] QueueContext queueContext, int id)
        {
            var eventItem = await eventsContext.Events.SingleOrDefaultAsync(e => e.Id == id);

            SignInSheetState signInSheetState = default(SignInSheetState);

            if (String.IsNullOrEmpty(eventItem.SignInDocumentUrl))
            {
                await queueContext.SendQueueMessageAsync(eventItem.EventKey);

                eventItem.SignInDocumentUrl = PROCESSING_URI;
                await eventsContext.SaveChangesAsync();

                signInSheetState = SignInSheetState.SignInDocumentProcessing;
            }
            else if (eventItem.SignInDocumentUrl == PROCESSING_URI)
            {
                signInSheetState = SignInSheetState.SignInDocumentProcessing;
            }
            else
            {
                signInSheetState = SignInSheetState.SignInDocumentAlreadyExists;
            }

            SignInSheetViewModel viewModel = new SignInSheetViewModel
            {
                Event            = eventItem,
                SignInSheetState = signInSheetState
            };

            return(View(viewModel));
        }
Beispiel #11
0
        public async Task <bool> SetupTestData()
        {
            for (var i = 1; i < 10; i++)
            {
                await _context.Events.AddAsync(new Event
                {
                    Id        = i,
                    Name      = "Lesson " + i,
                    StartDate = DateTime.UtcNow.AddDays(i),
                    EndDate   = DateTime.UtcNow.AddDays(i).AddHours(2)
                });
            }

            await _context.SaveChangesAsync();

            return(true);
        }
Beispiel #12
0
        public async Task <ActionResult> Post([FromBody] Event evt)
        {
            try
            {
                evt.timecreated = DateTime.Now;
                _context.events.Add(evt);
                await _context.SaveChangesAsync();

                return(StatusCode(201));
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"Error: {ex.Message}");

                return(StatusCode(500, ex.Message));
            }
        }
Beispiel #13
0
 public async Task <int> SaveChanges(CancellationToken cancellationToken)
 {
     try
     {
         return(await context.SaveChangesAsync(cancellationToken));
     }
     catch (Exception ex)
     {
         return(0);
     }
 }
Beispiel #14
0
        public async Task <IHttpActionResult> PostTicket(Ticket ticket)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            EventWithTicket query =
                (from data in db.EventsWithTickets
                 where (data.EventWithTicketID == ticket.EventWithTicketID)
                 select data).SingleOrDefault();

            if (query.MaxTicket > 0)
            {
                try
                {
                    db.Tickets.Add(ticket);
                    query.MaxTicket--;
                    await db.SaveChangesAsync();

                    db.Entry(ticket).Reference(x => x.Person).Load();
                    var dto = new TicketDTO()
                    {
                        TicketID          = ticket.TicketID,
                        Price             = ticket.Price,
                        EventWithTicketID = ticket.EventWithTicketID,
                        PersonID          = ticket.DNI
                    };

                    return(CreatedAtRoute("DefaultApi", new { id = ticket.TicketID }, ticket));
                }
                catch {}
            }
            else if (query.MaxTicket == 0)
            {
                query.HasTickets = false; db.SaveChanges();
            }
            return(StatusCode(HttpStatusCode.NoContent));
        }
Beispiel #15
0
        public async Task <IActionResult> Register([FromServices] EventsContext eventsContext, [FromServices] RegistrationContext registrationsContext, [FromForm] IFormCollection form, string key)
        {
            dynamic registration = new ExpandoObject();

            foreach (var name in form.Keys.Except(new List <string> {
                "__RequestVerificationToken"
            }))
            {
                (registration as IDictionary <string, object>)[name.Replace("RegistrationStub.", String.Empty)] = form[name].FirstOrDefault();
            }

            string viewModel = await registrationsContext.UploadEventRegistrationAsync(registration);

            Event eventItem = await eventsContext.Events.SingleOrDefaultAsync(e => e.EventKey == key);

            eventItem.RegistrationCount++;
            await eventsContext.SaveChangesAsync();

            return(View("Registered", viewModel));
        }
Beispiel #16
0
        private static async Task <MemoryStream> ProcessStorageMessage(string eventKey)
        {
            SignInDocumentGenerator documentGenerator = new SignInDocumentGenerator();

            using (EventsContext eventsContext = _connection.GetSqlContext())
            {
                await eventsContext.Database.EnsureCreatedAsync();

                await _registrationsContext.ConfigureConnectionAsync();

                Event eventEntry = await eventsContext.Events.SingleOrDefaultAsync(e => e.EventKey == eventKey);

                List <string> registrants = await _registrationsContext.GetRegistrantsForEvent(eventKey);

                MemoryStream stream = documentGenerator.CreateSignInDocument(eventEntry.Title, registrants);
                stream.Seek(0, SeekOrigin.Begin);

                eventEntry.SignInDocumentUrl = $"{eventKey}.docx";
                await eventsContext.SaveChangesAsync();

                return(stream);
            }
        }
Beispiel #17
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Event = await _context.Events.Include(e => e.Attendees).FirstOrDefaultAsync(m => m.Id == id);

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

            var attendee = await _context.Attendees.FirstOrDefaultAsync();

            if (!Event.Attendees.Contains(attendee))
            {
                Event.Attendees.Add(attendee);
                await _context.SaveChangesAsync();
            }
            return(Page());
        }