public void Post([FromBody] SpeakerViewModel speakerVM)
        {
            var speaker = new Speaker {
                name = speakerVM.name
            };

            _context.Speakers.Add(speaker);
            _context.SaveChanges();
        }
 public void Post([FromBody] Speaker speaker)
 {
     using (var context = new SignToSeminarDBContext())
     {
         context.Speakers.Add(speaker);
         context.SaveChanges();
     }
 }
 public void Delete(int id)
 {
     using (var context = new SignToSeminarDBContext())
     {
         var speaker = new Speaker {
             id = id
         };
         context.Speakers.Attach(speaker);
         context.Speakers.Remove(speaker);
         context.SaveChanges();
     }
 }
        public ActionResult <object> PostUser([FromBody] UserViewModel userVM)
        {
            var userSeminar = new UserSeminar();

            var seminar = _context.Seminars.Where(s => s.id == userVM.seminarId).FirstOrDefault();

            var message = "Successfully signed up for " + seminar.name + "!";

            var existingUser = _context.Users.Where(e => e.email == userVM.email).FirstOrDefault();


            if (existingUser != null)
            {
                userSeminar.user    = existingUser;
                userSeminar.seminar = seminar;
                _context.UserSeminars.Add(userSeminar);
            }
            else
            {
                var user = new User {
                    name = userVM.name, email = userVM.email,
                };
                _context.Users.Add(user);

                userSeminar.user    = user;
                userSeminar.seminar = seminar;
                _context.UserSeminars.Add(userSeminar);
            }

            try
            {
                _context.SaveChanges();
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
            return(Ok(new { message }));
        }
        public ActionResult <object> PostSeminar([FromBody] SeminarViewModel seminarVM)
        {
            var message = "New seminar added to list!";

            var speaker = new Speaker {
                name = seminarVM.SpeakersName
            };

            _context.Speakers.Add(speaker);

            var stringDate   = seminarVM.Date + " " + seminarVM.Time + ":00";
            var dateTimeDate = new Day {
                day = Convert.ToDateTime(stringDate)
            };

            _context.Days.Add(dateTimeDate);

            var seminar = new Seminar
            {
                name        = seminarVM.name,
                description = seminarVM.description,
                speaker     = speaker,
                day         = dateTimeDate
            };

            _context.Seminars.Add(seminar);

            try
            {
                _context.SaveChanges();
            }
            catch (Exception)
            {
                message = "Seminar not saved, try again.";
                return(new { message });
            }
            return(Ok(new { message }));
        }