Example #1
0
        public CarpoolFoodUser CheckUser(string loginName, string pwd)
        {
            CarpoolFoodUser carpoolFoodUser = null;

            try
            {
                using (var con = new SqlConnection(ConnString))
                {
                    con.Open();

                    using (var cmd = new SqlCommand("UserLogin", con)
                    {
                        CommandType = CommandType.StoredProcedure
                    })
                    {
                        cmd.Parameters.Add(new SqlParameter("@uloginName", loginName));
                        cmd.Parameters.Add(new SqlParameter("@pword", pwd));

                        var outputParameter = cmd.Parameters.Add("@responseMessage", SqlDbType.VarChar, 256);
                        outputParameter.Direction = ParameterDirection.Output;

                        using (var reader = cmd.ExecuteReader())
                        {
                            if (reader.Read())
                            {
                                carpoolFoodUser = new CarpoolFoodUser()
                                {
                                    Id           = int.Parse(reader["userID"].ToString()),
                                    LoginName    = reader["loginName"].ToString(),
                                    FirstName    = reader["firstName"].ToString(),
                                    LastName     = reader["lastName"].ToString(),
                                    Email        = reader["email"].ToString(),
                                    Phone        = reader["phone"].ToString(),
                                    IsDriverUser = reader.GetBoolean(6),
                                    IsPickupUser = reader.GetBoolean(7)
                                };
                            }

                            reader.Close();

                            var outputValue = outputParameter.Value.ToString();

                            if (outputValue.Equals("Incorrect passwor") || outputValue.Equals("Invalid login"))
                            {
                                carpoolFoodUser = null;
                            }
                        }
                    }
                }
            }
            catch (Exception E)
            {
                Debug.WriteLine(E.Message);
                throw new Exception("CheckUser", E);
            }

            return(carpoolFoodUser);
        }
        public IActionResult Post([FromBody] CarpoolFoodUser carpoolFoodUser)
        {
            var result = _database.SaveNewUser(carpoolFoodUser);

            if (result.ToLower().Equals("success"))
            {
                return(Ok("success"));
            }
            else
            {
                return(BadRequest(result));
            }
        }
Example #3
0
        public string SaveNewUser(CarpoolFoodUser carpoolFoodUser)
        {
            var message = "";

            using (var con = new SqlConnection(ConnString))
            {
                try
                {
                    con.Open();

                    using (var cmd = new SqlCommand("AddUser", con)
                    {
                        CommandType = CommandType.StoredProcedure
                    })
                    {
                        SqlParameter[] sqlParameters =
                        {
                            new SqlParameter("@loginName", carpoolFoodUser.LoginName),
                            new SqlParameter("@password",  carpoolFoodUser.Password),
                            new SqlParameter("@firstName", carpoolFoodUser.FirstName),
                            new SqlParameter("@lastName",  carpoolFoodUser.LastName),
                            new SqlParameter("@email",     carpoolFoodUser.Email),
                            new SqlParameter("@phone",     carpoolFoodUser.Phone),
                            new SqlParameter("@isPickup",  carpoolFoodUser.IsPickupUser),
                            new SqlParameter("@isDriver",  carpoolFoodUser.IsDriverUser)
                        };

                        cmd.Parameters.AddRange(sqlParameters);

                        var returnParameter = cmd.Parameters.Add("@responseMessage", SqlDbType.VarChar, 256);
                        returnParameter.Direction = ParameterDirection.Output;

                        cmd.ExecuteNonQuery();

                        var result = returnParameter.Value;

                        return(message = result.ToString());
                    }
                }catch (Exception E)
                {
                    Debug.WriteLine(E.Message);
                    throw new Exception("SaveNewUser", E);
                }
            }
        }