Ejemplo n.º 1
0
        public async Task <IActionResult> Create([FromForm] NewGreeting newGreeting)
        {
            var existingEvent = await _db.Events
                                .SingleOrDefaultAsync(e => e.Id == newGreeting.EventId && e.InvitationCode == newGreeting.InvitationCode);

            if (existingEvent == null)
            {
                return(Forbid());
            }
            // TODO: add validation

            var file = await Download(newGreeting.File);

            _db.Greetings.Add(new Models.Greeting
            {
                EventId   = newGreeting.EventId,
                Text      = newGreeting.Text,
                Signature = newGreeting.Signature,
                File      = file
            });

            await _db.SaveChangesAsync();

            return(RedirectToAction(
                       "Index",
                       "Greetings",
                       new { area = "Guests", InvitationCode = newGreeting.InvitationCode, EventId = newGreeting.EventId }));
        }
Ejemplo n.º 2
0
        public async Task <ActionResult <FindPersonsGreetings> > Post(string name, NewGreeting newGreeting)
        {
            await _commandProcessor.SendAsync(new AddGreeting(name, newGreeting.Greeting));

            var personsGreetings = await _queryProcessor.ExecuteAsync(new FindGreetingsForPerson(name));

            if (personsGreetings == null)
            {
                return(new NotFoundResult());
            }

            return(Ok(personsGreetings));
        }