Пример #1
0
        public WeatherApi weather_thread(string city)
        {
            var myWeatherTask = getWeather(city);

            myWeatherTask.Wait();
            WeatherApi myWeather = myWeatherTask.Result;


            string dataTime = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss");


            var contextOptions = new DbContextOptionsBuilder <WebApplication3Context>()
                                 .UseSqlServer("Server=(localdb)\\mssqllocaldb;Database=WebApplication3Context-6c28e34d-e6cb-4189-9bb9-60ff82f2a08f;Trusted_Connection=True;MultipleActiveResultSets=true")
                                 .Options;
            var context = new WebApplication3Context(contextOptions);

            var weath = new Models.weather();

            weath.name        = myWeather.name;
            weath.temp        = Math.Round(myWeather.main.temp - 273.15, 1);
            weath.datatime    = dataTime;
            weath.description = myWeather.weather[0].description;
            context.Add(weath);
            context.SaveChanges();


            return(myWeather);
        }
Пример #2
0
        public async Task <IActionResult> Create([Bind("Id,Name")] Category category)
        {
            if (ModelState.IsValid)
            {
                _context.Add(category);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(category));
        }
Пример #3
0
        public async Task <IActionResult> Create([Bind("ComentarioId,Titulo,Descricao,DataDoComentario,Autor")] Comentario comentario)
        {
            if (ModelState.IsValid)
            {
                _context.Add(comentario);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(comentario));
        }
Пример #4
0
        public async Task <IActionResult> Create([Bind("Id,Name,Description,Price")] Product product)
        {
            if (ModelState.IsValid)
            {
                _context.Add(product);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(product));
        }
Пример #5
0
        public async Task <IActionResult> Create([Bind("RollNumber,FirstName,LastName,Phone,Birthday,Gender,Address,Action")] Student student)
        {
            if (ModelState.IsValid)
            {
                _context.Add(student);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(student));
        }
Пример #6
0
        public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,Age,Email,CreatedAt,UpdatedAt,Status")] User user)
        {
            if (ModelState.IsValid)
            {
                _context.Add(user);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(user));
        }
Пример #7
0
        public async Task <IActionResult> Create([Bind("Id,Name,StadiumName,City,NumberTitles,CoachId")] Team team)
        {
            if (ModelState.IsValid)
            {
                _context.Add(team);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CoachId"] = new SelectList(_context.Coach, "Id", "FullName", team.CoachId);
            return(View(team));
        }
        public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,NumberOfTitles,Country,BirthDate,TeamId")] Coach coach)
        {
            if (ModelState.IsValid)
            {
                _context.Add(coach);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["TeamId"] = new SelectList(_context.Set <Team>(), "Id", "City", coach.TeamId);
            return(View(coach));
        }
Пример #9
0
        public async Task <IActionResult> Create([Bind("Id,JerseyNumber,FirstName,LastName,Weight,Height,Position,PrefferedLeg,Goals,Country,BirthDate,ContractId")] Player player)
        {
            if (ModelState.IsValid)
            {
                _context.Add(player);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ContractId"] = new SelectList(_context.Contract, "Id", "Id", player.ContractId);
            return(View(player));
        }
Пример #10
0
        public async Task <IActionResult> Create([Bind("Id,Titulo,Descricao,Data,CategoriaId,ComentarioId")] Mensagem mensagem)
        {
            if (ModelState.IsValid)
            {
                _context.Add(mensagem);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CategoriaId"]  = new SelectList(_context.Categoria, "CategoriaId", "CategoriaId", mensagem.CategoriaId);
            ViewData["ComentarioId"] = new SelectList(_context.Comentario, "ComentarioId", "ComentarioId", mensagem.ComentarioId);
            return(View(mensagem));
        }
Пример #11
0
        public async Task <IActionResult> Create([Bind("Id,PlayerId,TeamId,Salary,StartingDate,FinishDate")] Contract contract)
        {
            if (ModelState.IsValid)
            {
                _context.Add(contract);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["PlayerId"] = new SelectList(_context.Set <Player>(), "Id", "FirstName", contract.PlayerId);
            ViewData["TeamId"]   = new SelectList(_context.Set <Team>(), "Id", "City", contract.TeamId);
            return(View(contract));
        }
Пример #12
0
        public async Task <ActionResult <BlogPostViewModel> > Update([FromRoute] string slug, [FromBody] BlogPost newPost)
        {
            System.Diagnostics.Debug.WriteLine("pokemoni", newPost);
            var existingPost = await _repo.Get(slug);

            if (existingPost == null)
            {
                return(NotFound());
            }

            if (newPost.Title == null)
            {
                newPost.Title = existingPost.Title;

                string s = existingPost.Title.ToLower().Normalize(NormalizationForm.FormD);
                s            = Regex.Replace(s, @"\s+", "-");
                s            = Regex.Replace(s, "[^0-9A-Za-z -]", "");
                s            = RemoveAccented.RemoveDiacritics(s);
                newPost.Slug = s;
            }
            else
            {
                string s = newPost.Title.ToLower().Normalize(NormalizationForm.FormD);
                s            = Regex.Replace(s, @"\s+", "-");
                s            = Regex.Replace(s, "[^0-9A-Za-z -]", "");
                s            = RemoveAccented.RemoveDiacritics(s);
                newPost.Slug = s;
            }

            if (newPost.Description == null)
            {
                newPost.Description = existingPost.Description;
            }

            if (newPost.Body == null)
            {
                newPost.Body = existingPost.Body;
            }

            newPost.CreatedAt = existingPost.CreatedAt;
            newPost.UpdatedAt = DateTime.Now;

            _context.Remove(existingPost);

            _context.Add(newPost);

            var updatedPost = await _repo.SaveAsync(newPost);

            System.Diagnostics.Debug.WriteLine("pokemoni", newPost.ToString());
            return(Ok(updatedPost));
        }
        public async Task <IActionResult> Create([Bind("Id,Title,ImageFile,PlayerId")] Image image)
        {
            if (ModelState.IsValid)
            {
                //Save image to wwwroot/image
                string wwwRootPath = _hostEnvironment.WebRootPath;
                string fileName    = Path.GetFileNameWithoutExtension(image.ImageFile.FileName);
                string extension   = Path.GetExtension(image.ImageFile.FileName);
                image.ImageName = fileName = fileName + DateTime.Now.ToString("yymmssfff") + extension;
                string path = Path.Combine(wwwRootPath + "/Image/", fileName);
                using (var fileStream = new FileStream(path, FileMode.Create))
                {
                    await image.ImageFile.CopyToAsync(fileStream);
                }
                //Insert record
                _context.Add(image);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["PlayerId"] = new SelectList(_context.Player, "Id", "FullName", image.PlayerId);
            return(View(image));
        }