public async Task <IHttpActionResult> PutPersonalityCommand(int id, PersonalityCommand personalityCommand)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != personalityCommand.Id)
            {
                return(BadRequest());
            }

            db.Entry(personalityCommand).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PersonalityCommandExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public async Task <IHttpActionResult> GetPersonalityCommand(int id)
        {
            PersonalityCommand personalityCommand = await db.PersonalityCommands.FindAsync(id);

            if (personalityCommand == null)
            {
                return(NotFound());
            }

            return(Ok(personalityCommand));
        }
        public async Task <IHttpActionResult> PostPersonalityCommand(PersonalityCommand personalityCommand)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.PersonalityCommands.Add(personalityCommand);
            await db.SaveChangesAsync();

            return(CreatedAtRoute("DefaultApi", new { id = personalityCommand.Id }, personalityCommand));
        }
        public async Task <IHttpActionResult> DeletePersonalityCommand(int id)
        {
            PersonalityCommand personalityCommand = await db.PersonalityCommands.FindAsync(id);

            if (personalityCommand == null)
            {
                return(NotFound());
            }

            db.PersonalityCommands.Remove(personalityCommand);
            await db.SaveChangesAsync();

            return(Ok(personalityCommand));
        }
        public async Task <IHttpActionResult> DeletePersonalityCommand(int personalityId, string id)
        {
            PersonalityCommand personalityCommand = await db.PersonalityCommands
                                                    .Where(c => c.PersonalityId == personalityId && c.Trigger == id.ToLower())
                                                    .FirstOrDefaultAsync();

            if (personalityCommand == null)
            {
                return(NotFound());
            }

            db.PersonalityCommands.Remove(personalityCommand);
            await db.SaveChangesAsync();

            return(Ok(personalityCommand));
        }
        public async Task <IHttpActionResult> PostPersonalityCommand(int personalityId, PersonalityCommand personalityCommand)
        {
            personalityCommand.PersonalityId = personalityId;
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            //We want all command triggers to be in lower case
            personalityCommand.Trigger = personalityCommand.Trigger.ToLower();

            //Check if command exists; if it does return 409
            var result = await db.PersonalityCommands
                         .Where(c => c.PersonalityId == personalityId && c.Trigger == personalityCommand.Trigger)
                         .FirstOrDefaultAsync();

            if (result != null)
            {
                return(Conflict());
            }

            db.PersonalityCommands.Add(personalityCommand);
            await db.SaveChangesAsync();

            return(CreatedAtRoute("Personality", new { personalityId = personalityCommand.PersonalityId, controller = "Personalities", id = personalityCommand.Trigger }, personalityCommand));
        }