private void UpdateHero(Hero hero, HeroModel model, StoreContext context)
        {
            if (model.Name != null)
            {
                hero.Name = model.Name;
            }

            if (model.Items != null)
            {
                foreach (var i in model.Items)
                {
                    var item = context.Items.FirstOrDefault(x => x.Name == i.Name);
                    if (item == null)
                    {
                        throw new ArgumentNullException("item", "Cannot use invalid item!");
                    }

                    hero.Items.Add(item);
                }
            }

            hero.MagicAttack = model.MagicAttack;
            hero.MagicDefense = model.MagicDefense;
            hero.MeleAttack = model.MeleAttack;
            hero.MeleDefense = model.MeleDefense;
            hero.Experience = model.Experience;
            hero.HP = model.HP;
            hero.MP = model.MP;
            hero.Level = model.Level;
        }
        public HttpResponseMessage PutUpdateHero(HeroModel heroModel,
            [ValueProvider(typeof(HeaderValueProviderFactory<string>))] string sessionKey)
        {
            var responseMsg = this.PerformOperationAndHandleExceptions(
                         () =>
                         {
                             var context = new StoreContext();
                             using (context)
                             {
                                 var user = context.Users.FirstOrDefault(u => u.SessionKey == sessionKey);
                                 if (user == null)
                                 {
                                     throw new ArgumentOutOfRangeException("Invalid session key!");
                                 }

                                 var hero = user.Hero;
                                 if (hero == null)
                                 {
                                     throw new ArgumentNullException("hero", "Cannot update non-existing hero!");
                                 }

                                 UpdateHero(hero, heroModel, context);
                                 context.SaveChanges();

                                 var response =
                                     this.Request.CreateResponse(HttpStatusCode.OK);
                                 return response;
                             }
                         });

            return responseMsg;
        }