示例#1
0
        public async Task <int> CreateParkrun(Parkrun parkrun)
        {
            _dbContext.Add(parkrun);
            await _dbContext.SaveChangesAsync();

            return(parkrun.Id);
        }
示例#2
0
        public async Task <IActionResult> Create([Bind("Id,RoomName,RoomShortCode")] LocationRoom locationRoom)
        {
            if (ModelState.IsValid)
            {
                _context.Add(locationRoom);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(locationRoom));
        }
        public async Task <IActionResult> Create([Bind("Id,AddressLine1,AddressLine2,City,State,PostalCode,AddressShortCode")] LocationAddress locationAddress)
        {
            if (ModelState.IsValid)
            {
                _context.Add(locationAddress);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(locationAddress));
        }
        public async Task <IActionResult> Create([Bind("Id,Nome,Sexo,Nascimento,Cpf,Email,Celular,Endereco,Numero,CEP,Bairro,Cidade,Uf")] Cliente cliente)
        {
            if (ModelState.IsValid)
            {
                cliente.Id = Guid.NewGuid();
                _context.Add(cliente);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(cliente));
        }
示例#5
0
        public async Task <IActionResult> Create([Bind("Id,TipoImovel")] Tipo tipo)
        {
            if (ModelState.IsValid)
            {
                tipo.Id = Guid.NewGuid();
                _context.Add(tipo);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(tipo));
        }
示例#6
0
        public async Task <IActionResult> Create([Bind("Id,ImovelId,Caminho")] Foto foto)
        {
            if (ModelState.IsValid)
            {
                foto.Id = Guid.NewGuid();
                _context.Add(foto);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ImovelId"] = new SelectList(_context.Imovel, "Id", "Bairro", foto.ImovelId);
            return(View(foto));
        }
示例#7
0
        public async Task <IActionResult> Create([Bind("Id,ImovelId,ClienteId,DataInicio,DataFim,Valor")] Contrato contrato)
        {
            if (ModelState.IsValid)
            {
                contrato.Id = Guid.NewGuid();
                _context.Add(contrato);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ClienteId"] = new SelectList(_context.Cliente, "Id", "Nome", contrato.ClienteId);
            ViewData["ImovelId"]  = new SelectList(_context.Imovel, "Id", "Nome", contrato.ImovelId);
            return(View(contrato));
        }
        public async Task <IActionResult> Create(LocationImageViewModel vm, int id)
        {
            if (ModelState.IsValid)
            {
                Location location = new Location()
                {
                    CourseId       = id,
                    Name           = vm.Name,
                    ImageGuid      = UploadImage(vm.LocationImage),
                    ImageExtension = Path.GetExtension(vm.LocationImage.FileName)
                };
                _locationContext.Add(location);
                await _locationContext.SaveChangesAsync();

                return(RedirectToAction("Details", "Courses", new { id = id }));
            }
            return(View(vm));
        }
示例#9
0
        private async Task <List <LocationSearchResult> > LocationSearchApi(string query)
        {
            using (var client = new HttpClient())
            {
                var stream = await client.GetStreamAsync($"https://www.metaweather.com/api/location/search?query={query}");

                var locations = await JsonSerializer.DeserializeAsync <List <LocationSearchResult> >(stream);

                if (locations.Count == 0)
                {
                    System.Console.WriteLine("Location not found");
                    return(null);
                }
                else
                {
                    var locationsToBeAdded = locations.Select(u => u.WOEID).Distinct().ToArray();
                    var locationsInDB      = _context.locations.Where(u => locationsToBeAdded.Contains(u.WOEID))
                                             .Select(u => u.WOEID).ToArray();
                    var locationsNotInDb = locations.Where(u => !locationsInDB.Contains(u.WOEID));

                    foreach (LocationSearchResult location in locationsNotInDb)
                    {
                        _context.Add(location);
                        _context.SaveChanges();
                    }
                }

                foreach (LocationSearchResult location in locations)
                {
                    var entity = _context.locations.FirstOrDefault(item => item.WOEID == location.WOEID);

                    if (entity != null)
                    {
                        entity.SearchCount += 1;
                        _context.SaveChanges();
                        location.SearchCount = entity.SearchCount;
                    }
                }
                return(locations);
            }
        }
示例#10
0
        public async Task <IActionResult> AddFoto(Imovel imovel, IFormFileCollection files, LocationContext _context)
        {
            var nomeFoto = string.Empty;

            //Verifica se o diretorio foi criado, se não cria um pasta para armazenar as imagens
            string path = imovel.Diretorio(_environment, imovel.Id);

            var    foto   = string.Empty;
            string PathDB = string.Empty;


            foreach (var file in files)
            {
                if (file.Length > 0)
                {
                    foto = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"');
                    var guidFoto = Convert.ToString(Guid.NewGuid());
                    var extensao = Path.GetExtension(foto);
                    nomeFoto = guidFoto + extensao;
                    foto     = Path.Combine(_environment.WebRootPath, path) + $@"\{nomeFoto}";
                    PathDB   = "Storage/" + nomeFoto;
                    using (FileStream fs = System.IO.File.Create(foto))
                    {
                        file.CopyTo(fs);
                        fs.Flush();

                        var novaFoto = new Foto
                        {
                            Imovel  = imovel,
                            Caminho = nomeFoto
                        };

                        _context.Add(novaFoto);
                        await _context.SaveChangesAsync();
                    }
                }
            }
            return(NoContent());
        }
示例#11
0
        public async Task <IActionResult> Create([Bind("Id,Nome,TipoId,QUartos,Banheiros,Vagas,Area,Endereco,Numero,CEP,Bairro,Cidade,Uf")] Imovel imovel)
        {
            if (ModelState.IsValid)
            {
                imovel.Id = Guid.NewGuid();
                _context.Add(imovel);
                await _context.SaveChangesAsync();



                if (HttpContext.Request.Form.Files != null)
                {
                    var files = HttpContext.Request.Form.Files;

                    await AddFoto(imovel, files, _context);
                }


                return(RedirectToAction(nameof(Index)));
            }
            ViewData["TipoId"] = new SelectList(_context.Tipo, "Id", "TipoImovel", imovel.TipoId);
            return(View(imovel));
        }