예제 #1
0
        public IHttpActionResult PutUser(string email, [FromBody] string data)
        {
            //check if body is empty, white space or null
            // or appropriate JSON fields are not in post body
            if (string.IsNullOrWhiteSpace(data) || string.Equals("{}", data) || !data.Contains("name:"))
            {
                var    resp          = "Data is null. Please send formatted data: ";
                var    resp2         = "\"{name:name lklk,password:pw, age:age, weight:wt, squat:0, bench:0, deadlift:0, snatch:0, cleanjerk:0}\"";
                string emptyResponse = resp + resp2;
                return(Ok(emptyResponse));
            }

            var currEmail = email;

            //parse email and body data
            char[]   delimiterChars = { '{', '}', ',', ':', ' ' };
            string[] postParams     = data.Split(delimiterChars);

            //grab any other data that is to be changed
            var postName      = postParams[2] + " " + postParams[3];
            var postPassword  = postParams[5];
            var postAge       = postParams[7];
            var postWeight    = postParams[9];
            var postSquat     = postParams[11];
            var postBench     = postParams[13];
            var postDeadlift  = postParams[15];
            var postSnatch    = postParams[17];
            var postCleanjerk = postParams[19];
            var postWorkouts  = postParams[21];

            if (string.IsNullOrWhiteSpace(postName) && string.IsNullOrWhiteSpace(postPassword))
            {
                return(Ok("All fields are null! Send Data."));
            }

            //grab old user Hash data
            var returnedUser = redisCache.getUserHashData(currEmail);


            var currUser = new User();

            if (returnedUser != null)
            {
                currUser = returnedUser;
            }
            else
            {
                return(Ok(returnedUser));
            }

            //if null, user keeps curr name
            if (string.IsNullOrWhiteSpace(postName))
            {
                postName = currUser.Name;
            }

            //if null, user keeps curr name
            if (string.IsNullOrWhiteSpace(postAge))
            {
                postAge = currUser.Age.ToString();
            }
            //if null, user keeps curr name
            if (string.IsNullOrWhiteSpace(postWeight))
            {
                postWeight = currUser.Weight.ToString();
            }

            //if null, user keeps curr name
            if (string.IsNullOrWhiteSpace(postSquat))
            {
                postSquat = currUser.Squat.ToString();
            }

            //if null, user keeps curr name
            if (string.IsNullOrWhiteSpace(postBench))
            {
                postBench = currUser.Bench.ToString();
            }

            //if null, user keeps curr name
            if (string.IsNullOrWhiteSpace(postDeadlift))
            {
                postDeadlift = currUser.Deadlift.ToString();
            }

            //if null, user keeps curr name
            if (string.IsNullOrWhiteSpace(postSnatch))
            {
                postSnatch = currUser.Snatch.ToString();
            }

            //if null, user keeps curr name
            if (string.IsNullOrWhiteSpace(postCleanjerk))
            {
                postCleanjerk = currUser.CleanAndJerk.ToString();
            }

            //if null, user keeps curr workouts
            if (string.IsNullOrWhiteSpace(postWorkouts))
            {
                postWorkouts = currUser.WorkoutsCompleted.ToString();
            }

            //if null, user keeps curr password
            if (string.IsNullOrWhiteSpace(postPassword))
            {
                postPassword = currUser.Password;
            }
            else
            {
                postPassword = AuthController.ComputeHash(postPassword, "SHA512", null);
            }

            redisCache.updateUserHash("user:"******"Successfully Updated your profile");
            return(Ok("true"));
        }