Exemple #1
0
        public Token UpdateToken(UpdateTokenInputModel model)
        {
            var token = db.Tokens.FirstOrDefault(c => c.Id == model.Id);

            if (token == null)
            {
                return(null);
            }

            // Manual map
            token.AddressId      = (model.AddressId != 0 && model.AddressId != null)?  (int)model.AddressId : token.AddressId;
            token.Nickname       = (model.Nickname != string.Empty) ? model.Nickname : token.Nickname;
            token.TxId           = (model.TxId != string.Empty) ? model.TxId : token.TxId;
            token.Health         = (model.Health != 0 && model.Health != null) ? (int)model.Health : token.Health;
            token.Mana           = (model.Mana != 0 && model.Mana != null) ? (int)model.Mana : token.Mana;
            token.Agility        = (model.Agility != 0 && model.Agility != null) ? (int)model.Agility : token.Agility;
            token.Stamina        = (model.Stamina != 0 && model.Stamina != null) ? (int)model.Stamina : token.Stamina;
            token.CriticalStrike = (model.CriticalStrike != 0 && model.CriticalStrike != null) ? (int)model.CriticalStrike : token.CriticalStrike;
            token.AttackSpeed    = (model.AttackSpeed != 0 && model.AttackSpeed != null) ? (int)model.AttackSpeed : token.AttackSpeed;
            token.Mastery        = (model.Mastery != 0 && model.Mastery != null) ? (int)model.Mastery : token.Mastery;
            token.Versatility    = (model.Versatility != 0 && model.Versatility != null) ? (int)model.Versatility : token.Versatility;
            token.Experience     = (model.Experience != 0 && model.Experience != null) ? (int)model.Experience : token.Experience;
            token.Level          = (model.Level != 0 && model.Level != null) ? (int)model.Level : token.Level;
            token.ImageUrl       = (model.ImageUrl != string.Empty) ? model.ImageUrl : token.ImageUrl;
            token.IsBreeding     = (model.IsBreeding) ? model.IsBreeding : token.IsBreeding;
            token.IsBrawling     = (model.IsBreeding) ? model.IsBrawling : token.IsBrawling;

            db.Update(token);
            db.SaveChanges();

            return(token);
        }
        public IActionResult UpdateToken([FromBody] UpdateTokenInputModel model)
        {
            var token = this.mainService.UpdateToken(model);

            if (token == null)
            {
                return(this.NotFound("The token doesn't exist."));
            }

            return(this.Ok(token));
        }