// PUT: api/Shinobi/5
        public void Put(Shinobi s)
        {
            MySqlConnection conn = new MySqlConnection(connectionString);

            try
            {
                conn.Open();
                MySqlCommand cmd = conn.CreateCommand();
                string       sql = "update shinobis " +
                                   "set name = @Name, " +
                                   "age = @Age, " +
                                   "shinobis.rank = @Rank " +
                                   "where id = @Id";
                cmd.CommandText = sql;
                cmd.Parameters.AddWithValue("@Name", s.Name);
                cmd.Parameters.AddWithValue("@Age", s.Age);
                cmd.Parameters.AddWithValue("@Rank", s.Rank);
                cmd.Parameters.AddWithValue("@Id", s.Id);
                cmd.ExecuteNonQuery();
                conn.Close();
            }
            catch (Exception e)
            {
                conn.Close();
            }
        }
Example #2
0
        static void Main(string[] args)
        {
            // Map what you want ninject to do.
            IKernel kernel = new StandardKernel(new WeaponModule(), new NinjaModule());

            // Basic mapper useage
            Mapper.Initialize(cfg =>
            {
                //Create maps so mapper knows what can go to what
                cfg.CreateMap <Shinobi, Samurai>();
                cfg.CreateMap <Shinobi, Monk>();
            });

            // Display how a shinobi 'could' be built
            Shinobi ninja1 = new Shinobi(new Sword(), "Sam");
            Shinobi ninja2 = new Shinobi(new NinjaStar(), "Unknown");

            // Use ninject to create a shinobi using what it knows how to build.
            // Also displays how to pass arguements to the constructor for Shinobi.
            Shinobi ninja3 = kernel.Get <Shinobi>(new[] { new ConstructorArgument("name", "Unknown2") });

            // Use auto mapper to copy a shinobi into a samurai/monk class
            Samurai ninja4 = Mapper.Map <Samurai>(ninja3);
            Monk    ninja5 = Mapper.Map <Monk>(ninja3);

            // Build the testbed which requires both the kernal from ninject AND automapper
            TestBed temp  = kernel.Get <TestBed>();
            TestBed temp2 = kernel.Get <TestBed>();

            Console.WriteLine("Hit any key...");
            Console.ReadKey();
        }
Example #3
0
        public TestBed(IMapper mapper, IKernel kernal)
        {
            // Save the mapper
            _mapper = mapper;

            // Use the kernal to make a shinobi like before
            Shinobi ninja1 = kernal.Get <Shinobi>(new[] { new ConstructorArgument("name", "Unknown2") });

            // copy that new shinobi into a monk using the passed in Automapper
            Monk ninaj2 = mapper.Map <Monk>(ninja1);
        }
        public async Task <IActionResult> Create(ShinobiViewModel model, IList <IFormFile> file)
        {
            IFormFile imgShinobi = file.FirstOrDefault();


            if (imgShinobi != null || imgShinobi.ContentType.ToLower().StartsWith("image/"))
            {
                MemoryStream ms = new MemoryStream();
                imgShinobi.OpenReadStream().CopyTo(ms);
                model.ImagemShinobi = ms.ToArray();

                ViewData["Aldeia_Id"]      = new SelectList(_Context.Aldeia, "IdAldeia", "NomeAldeia", model.Aldeia_Id);                     //com ViewData retorna um select no html que dára as opções contidas em NomeAldeia com valores IdAldeia para o atr Id_Aldeia
                ViewData["Cla_Id"]         = new SelectList(_Context.Clas, "IdClas", "NomeClas", model.Cla_Id);                              //com ViewData retorna um select no html que dára as opções contidas em NomeAldeia com valores IdAldeia para o atr Id_Cla
                ViewData["Organizacao_Id"] = new SelectList(_Context.Organizacao, "IdOrganizacao", "NomeOrganizacao", model.Organizacao_Id); //com ViewData retorna um select no html que dára as opções contidas em NomeAldeia com valores IdAldeia para o atr Id_Aldeia

                Shinobi shinobi = new Shinobi
                {
                    Aldeia_Id      = model.Aldeia_Id,
                    Cla_Id         = model.Cla_Id,
                    Organizacao_Id = model.Organizacao_Id,
                    NomeShinobi    = model.NomeShinobi,
                    ImagemShinobi  = model.ImagemShinobi,
                    Especialidade  = model.Especialidade,
                    Renegado       = model.Renegado,
                    Vivo           = model.Vivo,
                    Elemento       = model.Elemento,
                    Graduacao      = model.Graduacao
                };

                if (shinobi != null)
                {
                    _Context.Add(shinobi);                   //Context recebe o obj
                    await _Context.SaveChangesAsync();       //context é salvo no sql

                    return(RedirectToAction(nameof(Index))); //retorno de pagina
                }
            }
            return(View(model));
        }
        // POST: api/Shinobi
        public void Post(Shinobi s)
        {
            MySqlConnection conn = new MySqlConnection(connectionString);

            try
            {
                conn.Open();
                MySqlCommand cmd = conn.CreateCommand();
                string       sql = "insert into shinobis values (@Id, @Name, @Age, @Rank)";
                cmd.CommandText = sql;
                cmd.Parameters.AddWithValue("@Id", s.Id);
                cmd.Parameters.AddWithValue("@Name", s.Name);
                cmd.Parameters.AddWithValue("@Age", s.Age);
                cmd.Parameters.AddWithValue("@Rank", s.Rank);
                cmd.ExecuteNonQuery();
                conn.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                conn.Close();
            }
        }
 // POST api/values
 public void Post(Shinobi s)
 {
 }