public HttpResponseMessage Post(ExerciseDescRequest registrationRequest)
        {
            ToeTrackerTrainerMobContext context = new ToeTrackerTrainerMobContext();
            ExerciseDesc account = context.ExerciseDesc.Where(a => a.ExerciseName == registrationRequest.ExerciseName).SingleOrDefault();

            if (account != null)
            {
                return(this.Request.CreateResponse(HttpStatusCode.BadRequest, "This exercise already exists"));
            }
            else
            {
                byte[]       salt       = CustomLoginProviderUtils.generateSalt();
                ExerciseDesc newAccount = new ExerciseDesc
                {
                    Id                = Guid.NewGuid().ToString(),
                    ExerciseName      = registrationRequest.ExerciseName,
                    ExerciseDescID    = registrationRequest.ExerciseId,
                    MuscleDescID      = registrationRequest.MuscleId,
                    SecondaryMuslceId = registrationRequest.SecondaryMuslceId,
                    Unit1             = registrationRequest.Unit1,
                    Unit2             = registrationRequest.Unit2,
                    Unit3             = registrationRequest.Unit3
                };
                context.ExerciseDesc.Add(newAccount);
                context.SaveChanges();
                return(this.Request.CreateResponse(HttpStatusCode.Created));
            }
        }
        // GET api/EnterExerciseActivity
        public HttpResponseMessage Post(ExcerciseInput execInput)
        {
            ToeTrackerTrainerMobContext context = new ToeTrackerTrainerMobContext();

            execInput.Id = Guid.NewGuid().ToString(); context.ExcerciseInputs.Add(execInput);
            context.SaveChanges();
            return(this.Request.CreateResponse(HttpStatusCode.Created, "Success"));
        }
Пример #3
0
        // POST api/CustomRegistration
        public HttpResponseMessage Post(RegistrationRequest registrationRequest)
        {
            if (!Regex.IsMatch(registrationRequest.username, "^[a-zA-Z0-9]{4,}$"))
            {
                return(this.Request.CreateResponse(HttpStatusCode.BadRequest, "Invalid username (at least 4 chars, alphanumeric only)"));
            }
            else if (registrationRequest.password.Length < 8)
            {
                return(this.Request.CreateResponse(HttpStatusCode.BadRequest, "Invalid password (at least 8 chars required)"));
            }

            ToeTrackerTrainerMobContext context = new ToeTrackerTrainerMobContext();
            Account account = context.Accounts.Where(a => a.Username == registrationRequest.username).SingleOrDefault();

            if (account != null)
            {
                return(this.Request.CreateResponse(HttpStatusCode.BadRequest, "That username already exists."));
            }
            else
            {
                byte[]  salt       = CustomLoginProviderUtils.generateSalt();
                Account newAccount = new Account
                {
                    Id       = Guid.NewGuid().ToString(),
                    Username = registrationRequest.username,
                    Salt     = salt,
                    SaltedAndHashedPassword = CustomLoginProviderUtils.hash(registrationRequest.password, salt),
                    FirstName = registrationRequest.FirstName,
                    LastName  = registrationRequest.LastName,
                    Phone     = registrationRequest.Phone,
                    Address   = registrationRequest.Address,
                    Email     = registrationRequest.Email,
                    Trainer   = registrationRequest.Trainer
                };
                context.Accounts.Add(newAccount);
                context.SaveChanges();
                return(this.Request.CreateResponse(HttpStatusCode.Created, "{\"UserCreation\":\"Success\"}"));
            }
        }