Example #1
0
        public ActionResult Index(RegistrantViewModel model)
        {
            if (ModelState.IsValid)
            {
                var registrant = new Registrant();
                var names      = ParseFullName(model.FullName);
                if (names.Length > 2)
                {
                    registrant.LastName   = names[0];
                    registrant.MiddleName = names[1];
                    registrant.FirstName  = names[2];
                }
                else if (names.Length > 1)
                {
                    registrant.LastName  = names[0];
                    registrant.FirstName = names[1];
                }
                else
                {
                    ViewBag.Gender = _genderListProducer.BuildList();

                    ModelState.AddModelError("", "At the very minimum, a first name and a surname are required");
                    return(View());
                }

                if (_registrantPersistenceService.GetUnique(model.EmailAddress, model.PhoneNumber) != null)
                {
                    ViewBag.Gender = _genderListProducer.BuildList();

                    ModelState.AddModelError("",
                                             "Seems like you have already registered. We already have that phone number and or Email address");
                    return(View(model));
                }

                registrant.Email       = model.EmailAddress;
                registrant.PhoneNumber = model.PhoneNumber;
                registrant.Gender      = model.Gender;
                registrant.State       = model.State;
                registrant.Institution = model.Institution;
                _registrantPersistenceService.Insert(registrant);
                TempData["Message"] = "Thanks for indicating interest!";
                return(RedirectToAction("Index"));
            }
            ViewBag.Gender = _genderListProducer.BuildList();
            return(View(model));
        }
Example #2
0
        //Post registrants to DB
        public IHttpActionResult Post(RegistrantViewModel registrant)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Invalid data."));
            }

            using (empire_dbContext dbContext = new empire_dbContext())
            {
                dbContext.tblRegistrants.Add(new tblRegistrant()
                {
                    fname = registrant.Fname,
                    lname = registrant.Lname
                });

                dbContext.SaveChanges();
            }

            return(Ok());
        }
Example #3
0
        public ActionResult Index(RegistrantViewModel registrant)
        {
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("http://hartempire.azurewebsites.net/api/registration");

                //HTTP POST
                var postTask = client.PostAsJsonAsync <RegistrantViewModel>("registration", registrant);
                postTask.Wait();

                var result = postTask.Result;
                if (result.IsSuccessStatusCode)
                {
                    return(RedirectToAction("Index"));
                }
            }

            ModelState.AddModelError(string.Empty, "Server Error. Please contact administrator.");

            return(View(registrant));
        }