Exemple #1
0
        public async Task <IActionResult> PutCharacter(long id, Character character)
        {
            if (id != character.CharacterId)
            {
                return(BadRequest());
            }

            _context.Entry(character).State = EntityState.Modified;
            _context.Entry(character.CharacterStats).State = EntityState.Modified;

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

            return(NoContent());
        }
        public async Task <ActionResult <Character> > GetCharacter(int id)
        {
            var character = await _context.Characters.FindAsync(id);

            if (character == null)
            {
                return(NotFound());
            }
            await _context.Entry(character).Collection(c => c.Moves).LoadAsync();

            return(character);
        }
Exemple #3
0
        public void Save(CharacterContext context)
        {
            if (saveMask == AmpSaveMask.None)
            {
                return;
            }

            var model = new CharacterActionSetAmpModel
            {
                Id        = actionSet.Owner,
                SpecIndex = actionSet.Index,
                AmpId     = (byte)Entry.Id
            };

            if ((saveMask & AmpSaveMask.Create) != 0)
            {
                context.Add(model);
            }
            else if ((saveMask & AmpSaveMask.Delete) != 0)
            {
                context.Entry(model).State = EntityState.Deleted;
            }

            saveMask = AmpSaveMask.None;
        }
Exemple #4
0
        public void Save(CharacterContext context)
        {
            if (saveMask != MailAttachmentSaveMask.None)
            {
                if ((saveMask & MailAttachmentSaveMask.Create) != 0)
                {
                    context.Add(new CharacterMailAttachmentModel
                    {
                        Id       = Id,
                        Index    = Index,
                        ItemGuid = Item.Guid
                    });
                }
                else if ((saveMask & MailAttachmentSaveMask.Delete) != 0)
                {
                    var model = new CharacterMailAttachmentModel
                    {
                        Id    = Id,
                        Index = Index
                    };

                    context.Entry(model).State = EntityState.Deleted;
                }

                saveMask = MailAttachmentSaveMask.None;
            }

            Item.Save(context);
        }
        public IActionResult UpdateCharacter(string name, Character character)
        {
            if (name != character.Name)
            {
                return(BadRequest());
            }

            _context.Entry(character).State = EntityState.Modified;

            try
            {
                _context.SaveChanges();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                if (!CharacterTableExists(name))
                {
                    return(NotFound());
                }
                else
                {
                    throw new UserFriendlyException($"error: concurrent update {character.Name}", ex);
                }
            }
            return(NoContent());
        }
Exemple #6
0
 public ActionResult Edit([Bind(Include = "CharacterID,Name")] Character character)
 {
     if (ModelState.IsValid)
     {
         db.Entry(character).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(character));
 }
Exemple #7
0
        public async Task <IActionResult> PutCharacterItem(long id, CharacterItem item)
        {
            if (id != item.Id)
            {
                return(BadRequest());
            }

            _context.Entry(item).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(NoContent());
        }
Exemple #8
0
    public int AddQuoteToCharacter(int characterId, string quoteText)
    {
        var character = GetCharacter(characterId);

        if (character is null)
        {
            return(0);
        }
        character.AddQuote(quoteText);
        _context.Entry(character.Quotes.First()).State = EntityState.Added;
        return(_context.SaveChanges());
    }
Exemple #9
0
        //Adds the item to the character,
        public void AddItem(Item item, int quantity)
        {
            using (CharacterContext db = new CharacterContext())
            {
                CharacterItem charItem = db.CharacterItems.FirstOrDefault(ci => ci.ItemParentID == item.ItemID && ci.CharacterId == CharacterID);
                if (charItem != null)
                {
                    charItem.QuantityOwned  += quantity;
                    db.Entry(charItem).State = EntityState.Modified;
                }
                else
                {
                    CharacterItems.Add(new CharacterItem(item.ItemName, item.ItemDescription, item.ItemCost, item.ItemID, quantity));
                }

                db.SaveChanges();
            }
        }
Exemple #10
0
        public void Save(CharacterContext context)
        {
            if ((saveMask & BindingSaveMask.Create) != 0)
            {
                var model = new CharacterKeybinding
                {
                    Id              = Owner,
                    InputActionId   = InputActionId,
                    DeviceEnum00    = DeviceEnum00,
                    DeviceEnum01    = DeviceEnum01,
                    DeviceEnum02    = DeviceEnum02,
                    Code00          = Code00,
                    Code01          = Code01,
                    Code02          = Code02,
                    MetaKeys00      = MetaKeys00,
                    MetaKeys01      = MetaKeys01,
                    MetaKeys02      = MetaKeys02,
                    EventTypeEnum00 = EventTypeEnum00,
                    EventTypeEnum01 = EventTypeEnum01,
                    EventTypeEnum02 = EventTypeEnum02
                };
                context.Add(model);
            }
            else
            {
                var model = new CharacterKeybinding
                {
                    Id            = Owner,
                    InputActionId = InputActionId
                };

                if ((saveMask & BindingSaveMask.Delete) != 0)
                {
                    context.Entry(model).State = EntityState.Deleted;
                }
                else
                {
                    EntityEntry <CharacterKeybinding> entity = context.Attach(model);

                    if ((saveMask & BindingSaveMask.DeviceEnum00) != 0)
                    {
                        model.DeviceEnum00 = DeviceEnum00;
                        entity.Property(p => p.DeviceEnum00).IsModified = true;
                    }

                    if ((saveMask & BindingSaveMask.DeviceEnum01) != 0)
                    {
                        model.DeviceEnum01 = DeviceEnum01;
                        entity.Property(p => p.DeviceEnum01).IsModified = true;
                    }

                    if ((saveMask & BindingSaveMask.DeviceEnum02) != 0)
                    {
                        model.DeviceEnum02 = DeviceEnum02;
                        entity.Property(p => p.DeviceEnum02).IsModified = true;
                    }

                    if ((saveMask & BindingSaveMask.Code00) != 0)
                    {
                        model.Code00 = Code00;
                        entity.Property(p => p.Code00).IsModified = true;
                    }

                    if ((saveMask & BindingSaveMask.Code01) != 0)
                    {
                        model.Code01 = Code01;
                        entity.Property(p => p.Code01).IsModified = true;
                    }

                    if ((saveMask & BindingSaveMask.Code02) != 0)
                    {
                        model.Code02 = Code02;
                        entity.Property(p => p.Code02).IsModified = true;
                    }

                    if ((saveMask & BindingSaveMask.MetaKeys00) != 0)
                    {
                        model.MetaKeys00 = MetaKeys00;
                        entity.Property(p => p.MetaKeys00).IsModified = true;
                    }

                    if ((saveMask & BindingSaveMask.MetaKeys01) != 0)
                    {
                        model.MetaKeys01 = MetaKeys01;
                        entity.Property(p => p.MetaKeys01).IsModified = true;
                    }

                    if ((saveMask & BindingSaveMask.MetaKeys02) != 0)
                    {
                        model.MetaKeys02 = MetaKeys02;
                        entity.Property(p => p.MetaKeys02).IsModified = true;
                    }

                    if ((saveMask & BindingSaveMask.EventTypeEnum00) != 0)
                    {
                        model.EventTypeEnum00 = EventTypeEnum00;
                        entity.Property(p => p.EventTypeEnum00).IsModified = true;
                    }

                    if ((saveMask & BindingSaveMask.EventTypeEnum01) != 0)
                    {
                        model.EventTypeEnum01 = EventTypeEnum01;
                        entity.Property(p => p.EventTypeEnum01).IsModified = true;
                    }

                    if ((saveMask & BindingSaveMask.EventTypeEnum02) != 0)
                    {
                        model.EventTypeEnum02 = EventTypeEnum02;
                        entity.Property(p => p.EventTypeEnum02).IsModified = true;
                    }

                    saveMask = BindingSaveMask.None;
                }
            }
        }