Esempio n. 1
0
        //// GET api/Registration
        //public string Get(string email, string first, string last, string pass, string username)
        //{

        //	try
        //	{
        //		// Insert the record information into the database
        //		User user = new User()
        //		{
        //			EmailAddress = email,
        //			FirstName = first,
        //			LastName = last,
        //			Password = pass,
        //			Username = username
        //		};

        //		user.UserTypes.Add(UserType.StandardUser);

        //		dbContext.Users.AddOrUpdate(user);
        //		dbContext.SaveChanges();
        //	}
        //	catch (Exception ex)
        //	{
        //		throw new HttpResponseException(HttpStatusCode.BadRequest);
        //	}
        //	return "";
        //}


        public RegistrationResultViewModel Get()
        {
            string First    = Tools.IO.GetParameter(Request, "first"),
                   Last     = Tools.IO.GetParameter(Request, "last"),
                   Pass     = Tools.IO.GetParameter(Request, "pass"),
                   Username = Tools.IO.GetParameter(Request, "username"),
                   Email    = Tools.IO.GetParameter(Request, "email");

            RegistrationResultViewModel results = new RegistrationResultViewModel()
            {
                first    = First,
                last     = Last,
                pass     = Pass,
                username = Username,
                email    = Email
            };



            bool userExists = (from u in dbContext.Users where u.Username.ToLower() == Username.ToLower() || u.EmailAddress.ToLower() == Email.ToLower() select u).Any();

            if (userExists)
            {
                var resp = new HttpResponseMessage(HttpStatusCode.Conflict)
                {
                    Content = new StringContent("Username or Email already exists on the server. Please try again")
                };
                throw new HttpResponseException(resp);
            }
            else
            {
                try
                {
                    User user = new User()
                    {
                        EmailAddress = results.email,
                        FirstName    = results.first,
                        LastName     = results.last,
                        Password     = results.pass,
                        Username     = results.username
                    };

                    user.UserTypes = new List <UserType>();
                    user.UserTypes.Add(UserType.StandardUser);

                    dbContext.Users.AddOrUpdate(user);
                    dbContext.SaveChanges();
                    results.Result = user.UserId.ToString();
                }
                catch (Exception ex)
                {
                    throw ex;                // new HttpResponseException(HttpStatusCode.BadRequest);
                }

                return(results);
            }
        }
Esempio n. 2
0
        public IActionResult Index(RegistrationResultViewModel registrationResult)
        {
            if (registrationResult.IsSuccess != null)
            {
                TempData["RegistrationResult"] = registrationResult;
            }

            return(View(_mapper.Map <List <TeamListItemDto>, List <TeamListViewModel> >(_teamEngine.GetAllTeam())));
        }