Beispiel #1
0
        //[Route("Register")]
        public IActionResult Post([FromBody] GuestInfoViewModel model)
        {
            var vmRes = JsonConvert.DeserializeObject <GuestInfo>(JsonConvert.SerializeObject(model));
            var guest = guestInfoService.Register(vmRes);

            string msg = "There was an error registering, Please try again";

            if (guest != null)
            {
                msg = $"Sucessfully Registered {guest.FirstName}  {guest.LastName}";
                return(Ok(msg));
            }
            else
            {
                return(BadRequest(msg));
            }
        }
        public IActionResult AddOrUpdate(int?id, int?eventId)
        {
            Guest = new GuestInfoViewModel();

            if (eventId != null)
            {
                var associatedEvent = _eventService.GetById(eventId.Value);
                Guest.AssociatedEvent = new EventInfoViewModel
                {
                    Id             = associatedEvent.Id,
                    Name           = associatedEvent.Name,
                    MaxGuestsCount = associatedEvent.MaxGuestsCount,
                    AllEventTypes  = _eventService.GetAllEventTypes(),
                };
            }

            //Guest.ListOfEvents.Add(Guest.AssociatedEvent);

            if (id == null)
            {
                // Add
            }
            else
            {
                // Edit
                var guestToEdit = _guestService.GetById(id.Value);
                if (guestToEdit == null)
                {
                    return(NotFound());
                }

                Guest.Id         = guestToEdit.Id;
                Guest.FirstName  = guestToEdit.FirstName;
                Guest.LastName   = guestToEdit.LastName;
                Guest.Patronymic = guestToEdit.Patronymic;
                Guest.Email      = guestToEdit.Email;
                Guest.Comment    = guestToEdit.Comment;
            }

            return(View(Guest));
        }