Пример #1
0
        public ActionResult Create([Bind(Include = "CharacterID,Name")] Character character)
        {
            if (ModelState.IsValid)
            {
                db.Characters.Add(character);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(character));
        }
 private void PopulateDataBase(int length = 5)
 {
     for (int i = 0; i < length; i++)
     {
         context.Add(new Character(i.ToString(), new List <string>(new string[] { "One", "Two" }), "planet", new List <Friend>(new Friend[] { new Friend {
                                                                                                                                                  Name = "LeftFriend"
                                                                                                                                              }, new Friend {
                                                                                                                                                  Name = "RightFriend"
                                                                                                                                              } })));
     }
     context.SaveChanges();
 }
Пример #3
0
        public RedirectToRouteResult CreateCharacter_POST()
        {
            Character newCharacter = new Character();

            UpdateModel(newCharacter);

            if (ModelState.IsValid)
            {
                characterContext.Characters.Add(newCharacter);
                characterContext.SaveChanges();
            }
            return(RedirectToAction("AllCharacters"));
        }
 public IActionResult CreateNewCharacter(Character character)
 {
     try
     {
         _context.Add(character);
         _context.SaveChanges();
     }
     catch (System.Exception ex)
     {
         throw new UserFriendlyException(ex.Message);
     }
     return(Created(character.Name, new { name = character.Name }));
 }
Пример #5
0
        public void Setup()
        {
            _dbFileName = Path.GetTempFileName();
            var options = new DbContextOptionsBuilder <CharacterContext>()
                          .UseSqlite("Filename=" + _dbFileName)
                          .Options;

            _db = new CharacterContext(options);
            _db.Database.EnsureCreated();
            _controller = new CharacterController(_db);
            var character = new Character()
            {
                Name          = CharName,
                MaxHitPoints  = CharHP,
                CurHitPoints  = CharHP,
                TempHitPoints = CharTempHP
            };

            character.Defenses.Add(new Defense()
            {
                DamageType = DamageImmune,
                IsImmune   = true
            });
            character.Defenses.Add(new Defense()
            {
                DamageType = DamageResist,
                IsImmune   = false
            });
            _db.Characters.Add(character);
            _db.SaveChanges();
        }
Пример #6
0
 public async Task lu(CommandContext cmct, int up = 1)
 {
     using (CharacterContext cc = new CharacterContext())
     {
         try
         {
             foreach (var temp in prty[cmct.Channel.Name])
             {
                 var chara = cc.Characters.Where(c => c.name == temp).FirstOrDefault();
                 chara.level = chara.level + up;
                 for (int i = 0; i < up; i++)
                 {
                     chara.max_HP = chara.max_HP + Commands.r.Next(1, chara.dice) + (chara.bod - 10) / 2;
                 }
                 chara.HP = chara.max_HP;
             }
             cc.SaveChanges();
         }
         catch (Exception ex)
         {
             await cmct.RespondAsync("ERROR! " + ex.Message);
         }
     }
     await cmct.RespondAsync("Party level up.");
 }
Пример #7
0
        public IActionResult Post([FromBody] string name)
        {
            var character = new Character(name);

            _context.Characters.Add(character);
            _context.SaveChanges();
            return(CreatedAtRoute("GetChar", new { id = character.Id }, character));
        }
Пример #8
0
 public void CreateCharacter(Character character)
 {
     using (var db = new CharacterContext())
     {
         db.Characters.Add(character);
         db.SaveChanges();
     }
 }
Пример #9
0
 public ActionResult Create([Bind(Include = "Pseudonym, Kind, Position, Universe")] Character character)
 {
     try
     {
         if (ModelState.IsValid)
         {
             db.Characters.Add(character);
             db.SaveChanges();
             return(RedirectToAction("Index"));
         }
     }
     catch (DataException /* dex */)
     {
         //Log the error (uncomment dex variable name and add a line here to write a log.
         ModelState.AddModelError("", "Невозможно сохранить изменения. Попробуйте ещё раз. Если проблема не ушла - обратитесь к системному администратору");
     }
     return(View(character));
 }
Пример #10
0
    public string CreateNewCharacter(string name)
    {
        var character = new Character(name);

        _context.Characters.Add(character);
        _context.SaveChanges();
        return(character.Id.ToString());
    }
Пример #11
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();
            }
        }
Пример #12
0
        public CharacterController(CharacterContext context)
        {
            _context = context;

            if (_context.CharacterItems.Count() == 0)
            {
                // Create a new Character item if collection is empty,
                // which means you can't delete all CharacterItems.
                _context.CharacterItems.Add(new CharacterItem {
                    Name = "Emmet", BasedOn = "The Lego movie"
                });
                _context.CharacterItems.Add(new CharacterItem {
                    Name = "CoolTag", BasedOn = "The Lego movie"
                });
                _context.CharacterItems.Add(new CharacterItem {
                    Name = "Vitruvius", BasedOn = "The Lego movie"
                });
                _context.CharacterItems.Add(new CharacterItem {
                    Name = "StarLord", BasedOn = "Marvel / Lego Avengers"
                });
                _context.CharacterItems.Add(new CharacterItem {
                    Name = "Nebula", BasedOn = "Marvel / Lego Avengers"
                });
                _context.CharacterItems.Add(new CharacterItem {
                    Name = "Batman", BasedOn = "DC Comics / Lego Batman"
                });
                _context.CharacterItems.Add(new CharacterItem {
                    Name = "Joker", BasedOn = "DC Comics / Lego Batman"
                });
                _context.CharacterItems.Add(new CharacterItem {
                    Name = "Bilbo Sacket", BasedOn = "The Hobbit"
                });
                _context.CharacterItems.Add(new CharacterItem {
                    Name = "Frodo Sacket", BasedOn = "Lord of the ring"
                });
                _context.CharacterItems.Add(new CharacterItem {
                    Name = "Gollum", BasedOn = "The Hobbit / Lord of the ring"
                });
                _context.CharacterItems.Add(new CharacterItem {
                    Name = "Chase McCain", BasedOn = "Lego city"
                });
                _context.SaveChanges();
            }
        }
Пример #13
0
        static void CreateNewCharacter()
        {
            Console.WriteLine("Character Name:");
            string characterName = Console.ReadLine();

            Console.WriteLine("Character Health:");
            int characterHealth = int.Parse(Console.ReadLine());

            Console.WriteLine("Character Attack:");
            int characterAttack = int.Parse(Console.ReadLine());

            Console.WriteLine("Create (y/n)");
            if (Console.ReadLine() == "y")
            {
                Character character = new Character(characterHealth, characterAttack, characterName);

                characterContext.Add(character);
                characterContext.SaveChanges();
            }
            ModeSelection();
        }
Пример #14
0
 public void SaveChanges()
 {
     if (_context != null)
     {
         _context.SaveChanges();
     }
     if (_spellsContext != null)
     {
         _spellsContext.SaveChanges();
     }
     if (_itemsContext != null)
     {
         _itemsContext.SaveChanges();
     }
     if (_playableClassContext != null)
     {
         _playableClassContext.SaveChanges();
     }
     if (_raceContext != null)
     {
         _raceContext.SaveChanges();
     }
 }
Пример #15
0
        public override void Install(ModuleManager manager)
        {
            _manager = manager;
            _client  = manager.Client;


            _manager.CreateCommands("", cgb =>
            {
                cgb.MinPermissions((int)PermissionLevel.User);

                cgb.CreateCommand("create")
                .Description("Create a new character. Examples:\n\n $create [name] [PHY] [MEN] [VIT] [LUC]\n $create Test1 5 5 5 5\n$create \"Test 2\" 1 15 2 2")
                .Parameter("text", ParameterType.Multiple)
                .Do(async e =>
                {
                    if (Beta.CheckModuleState(e, "cram", e.Channel.IsPrivate))
                    {
                        if (!(e.Args.Count() == 5))
                        {
                            await e.Channel.SendMessage("Sorry, doesn't look like you've provided the right number of arguments.");
                        }
                        else
                        {
                            string name = e.Args[0];
                            int phy     = 0;
                            int men     = 0;
                            int vit     = 0;
                            int luc     = 0;
                            bool successfulConversion = false;
                            try
                            {
                                phy = Convert.ToInt32(e.Args[1]);
                                men = Convert.ToInt32(e.Args[2]);
                                vit = Convert.ToInt32(e.Args[3]);
                                luc = Convert.ToInt32(e.Args[4]);
                                successfulConversion = true;
                            }
                            catch
                            {
                                await e.Channel.SendMessage("Looks like one of your stats wasn't in number format, bub.");
                            }
                            if (successfulConversion)
                            {
                                if (ValidateScores(phy, men, vit, luc))
                                {
                                    CramManager.AddNewCharacter(name, phy, men, vit, luc, e.User.Id);
                                    await e.Channel.SendMessage("Ok, I've added that character for you!");
                                }
                                else
                                {
                                    await e.Channel.SendMessage("Those scores aren't valid! Either they don't add up to 20, or you have a score above 15 or below 1.");
                                }
                            }
                        }
                    }
                });

                cgb.CreateCommand("listchars")
                .Description("Lists all of your characters across all games.")
                .Alias("listchar")
                .Do(async e =>
                {
                    string msg = "Character List\n";
                    msg       += "Character ID | Character Name | PHY | MEN | VIT | LUC | Cash | Skill Points\n";
                    msg       += CramManager.GetCharacters(e.User.Id.ToString());
                    await e.Channel.SendMessage(msg);
                });

                cgb.CreateCommand("selectchar")
                .Description("Select one of your characters by ID. You can check 'listchars' to get the ID. Example: \n\n$selectchar 2.")
                .Parameter("id", ParameterType.Required)
                .Do(async e =>
                {
                    int charId;
                    string characterName = "";
                    if (Int32.TryParse(e.GetArg("id"), out charId))
                    {
                        using (CharacterContext db = new CharacterContext())
                        {
                            Character selectedChar = db.Characters.FirstOrDefault(chr => chr.CharacterID == charId);
                            if (selectedChar != null)
                            {
                                if (selectedChar.UserId == e.User.Id.ToString())
                                {
                                    characterName             = selectedChar.Name;
                                    UserState usr             = Beta.UserStateRepository.GetUserState(e.User.Id);
                                    usr.SelectedCharacter     = charId;
                                    usr.SelectedCharacterName = characterName;
                                    await e.Channel.SendMessage("Awesome, I selected " + characterName + "!");
                                }
                                else
                                {
                                    await e.Channel.SendMessage("Hey! THAT ISN'T YOUR CHARACTER!");
                                }
                            }
                            else
                            {
                                await e.Channel.SendMessage("Sorry, I don't see a character with that ID...");
                            }
                        }
                    }
                    else
                    {
                        await e.Channel.SendMessage("That's not a digit, my dude.");
                    }
                });

                cgb.CreateCommand("selectedchar")
                .Description("Shows the currently selected character, if any.")
                .Do(async e =>
                {
                    UserState usr = Beta.UserStateRepository.GetUserState(e.User.Id);
                    if (usr.SelectedCharacter != 0)
                    {
                        await e.Channel.SendMessage(usr.SelectedCharacter + " | " + usr.SelectedCharacterName);
                    }
                    else
                    {
                        await e.Channel.SendMessage("Looks like you don't actually have a character selected, buddy.");
                    }
                });

                cgb.CreateCommand("buy")
                .Description("Purchase an item. Provide the iteam id found from the 'listitems' command. Example: \n\n$buy 3.")
                .Parameter("id", ParameterType.Required)
                .Do(async e =>
                {
                    UserState usr = Beta.UserStateRepository.GetUserState(e.User.Id);
                    if (usr.SelectedCharacter != 0)
                    {
                        int itemId;
                        if (Int32.TryParse(e.GetArg("id"), out itemId))
                        {
                            using (CharacterContext db = new CharacterContext())
                            {
                                List <Item> items = db.Items.ToList <Item>();
                                Item item         = items.FirstOrDefault(i => i.ItemID == itemId);
                                if (item != null)
                                {
                                    Character selectedCharacter = db.Characters.FirstOrDefault(c => c.CharacterID == usr.SelectedCharacter);
                                    if (selectedCharacter.Cash >= item.ItemCost)
                                    {
                                        selectedCharacter.Cash -= item.ItemCost;
                                        selectedCharacter.AddItem(item, 1);
                                        await e.Channel.SendMessage("Ok cool, thanks for the cash! I've added " + item.ItemName + " to your inventory!");
                                        db.SaveChanges();
                                    }
                                    else
                                    {
                                        await e.Channel.SendMessage("Sorry pal, you don't have enough cash.");
                                    }
                                }
                                else
                                {
                                    await e.Channel.SendMessage("Sorry, I don't see that item. You should check the 'listitems' command again to verify the ID!");
                                }
                            }
                        }
                        else
                        {
                            await e.Channel.SendMessage("That's not a digit, my dude!");
                        }
                    }
                    else
                    {
                        await e.Channel.SendMessage("Looks like you don't actually have a character selected, buddy.");
                    }
                });

                cgb.CreateCommand("craminv")
                .Description("Lists the items in your inventory.")
                .Do(async e =>
                {
                    UserState usrState = Beta.UserStateRepository.GetUserState(e.User.Id);
                    if (usrState.SelectedCharacter != 0)
                    {
                        string msg = usrState.SelectedCharacterName + "'s Inventory\n";
                        msg       += "Item ID | Item Name | Item Description | Item Cost | Quantity";
                        msg       += CramManager.GetCharacterItems(usrState.SelectedCharacter);
                        await e.Channel.SendMessage(msg);
                    }
                });

                cgb.CreateCommand("listskills")
                .Description("Lists the generic list of skills.")
                .Do(async e =>
                {
                    string msg = "Skill List\n";
                    msg       += "Skill ID | Skill Name | Skill Description\n";
                    msg       += CramManager.GetSkills();
                    await e.Channel.SendMessage(msg);
                });

                cgb.CreateCommand("listitems")
                .Description("Lists the generic list of items..")
                .Do(async e =>
                {
                    string msg = "Item List\n";
                    msg       += "Item ID | Item Name | Item Description | Item Cost\n";
                    msg       += CramManager.GetItems();
                    await e.Channel.SendMessage(msg);
                });
            });
        }
Пример #16
0
        //public int Count()
        //{
        //    return db.Set<T>().Count();
        //}

        public void Create(T entity)
        {
            db.Set <T>().Add(entity);
            db.SaveChanges();
        }
Пример #17
0
 public async Task <bool> SaveChanges()
 {
     return(_context.SaveChanges() >= 0);
 }
Пример #18
0
 public bool SaveChanges()
 {
     return(_context.SaveChanges() >= 0);
 }