Exemple #1
0
        public async Task <IActionResult> PutLocation(int id, Location location)
        {
            if (id != location.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Exemple #2
0
        public async Task <int> CreateParkrun(Parkrun parkrun)
        {
            _dbContext.Add(parkrun);
            await _dbContext.SaveChangesAsync();

            return(parkrun.Id);
        }
        public async Task <ActionResult <LocationItem> > PostLocationItem(LocationItem locationItem)
        {
            _context.LocationItems.Add(locationItem);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetLocationItem), new { id = locationItem.Id }, locationItem));
        }
Exemple #4
0
        public async Task <string> AddIt(LocationContext context, VehicleLocation vehicleLocation)
        {
            _context = context;
            _context.VehicleLocations.Add(vehicleLocation);
            await _context.SaveChangesAsync();

            string vehicleLatLong = "";

            vehicleLatLong += vehicleLocation.VehicleId;
            vehicleLatLong += "#";
            vehicleLatLong += vehicleLocation.Latitude;
            vehicleLatLong += ",";
            vehicleLatLong += vehicleLocation.Longitude;

            vehicleLocation.VehicleLatLong        = vehicleLatLong;
            _context.Entry(vehicleLocation).State = EntityState.Modified;
            _context.VehicleLocations.Update(vehicleLocation);

            try
            {
                await _context.SaveChangesAsync();

                return("Response:{ status: Succes, description: Vehicle data saved}");
            }
            catch (DbUpdateConcurrencyException e)
            {
                return("Look here " + e.Message);
            }
        }
        public async Task <IActionResult> PutComment([FromRoute] int id, [FromBody] Comment comment)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != comment.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
        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));
        }
Exemple #7
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,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));
        }
Exemple #9
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));
        }
        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));
        }
Exemple #11
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));
        }
Exemple #12
0
        public async Task <bool> DeleteLocation(int id)
        {
            var location = await context.Locations.FindAsync(id);

            if (location == null)
            {
                return(false);
            }

            context.Locations.Remove(location);
            await context.SaveChangesAsync();


            return(true);
        }
        public async Task <string> ChangeActive(int id)
        {
            var vehicleLocation = await _context.VehicleLocations.SingleOrDefaultAsync(m => m.Id == id);

            if (vehicleLocation != null)
            {
                vehicleLocation.Active = 0;
            }
            _context.Entry(vehicleLocation).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!VehicleLocationExists(id))
                {
                    return("not Found");
                }
                else
                {
                    throw;
                }
            }
            return("worked");
        }
Exemple #14
0
        public async Task <IActionResult> DeleteConfirmed(int id)
        {
            var course = await _courseContext.Course.FindAsync(id);

            var locations = _locationContext.Location.Where(l => l.CourseId == course.CourseId);

            foreach (var location in locations)
            {
                var questionsToLocations = _questionContext.Question.Where(q => q.LocationId == location.LocationId);
                foreach (var question in questionsToLocations)
                {
                    var answersToQuestion = _answerContext.Answer.Where(ans => ans.QuestionId == question.QuestionId);
                    _answerContext.Answer.RemoveRange(answersToQuestion);

                    _questionContext.Remove(question);
                }
                _locationContext.Location.Remove(location);
            }

            _courseContext.Course.Remove(course);

            await _answerContext.SaveChangesAsync();

            await _questionContext.SaveChangesAsync();

            await _locationContext.SaveChangesAsync();

            await _courseContext.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
        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));
        }
        public async Task <ActionResult <Location> > PostLocation(Location location)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            await _context.Locations.AddAsync(location);

            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetLocation), new { id = location.Id }, location));
        }
        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));
        }
Exemple #18
0
        public async Task <string> SaveAddress(string newAddress, VehicleLocation vehicleLocation)
        {
            vehicleLocation.Address = newAddress;
            _context.Entry(vehicleLocation).State = EntityState.Modified;
            _context.VehicleLocations.Update(vehicleLocation);

            try
            {
                await _context.SaveChangesAsync();

                return("Response:{ status: Succes, description: Vehicle data saved}");
            }
            catch (DbUpdateConcurrencyException e)
            {
                return("Look here " + e.Message);
            }
        }
Exemple #19
0
        private async Task ResetPings(List <Ping> pings)
        {
            if (pings.Count == 0)
            {
                return;
            }

            var timeoutOld = locatieContext.Database.GetCommandTimeout();

            locatieContext.Database.SetCommandTimeout(86400);
            var fromTime = pings.OrderBy(p => p.Time).FirstOrDefault().Time;

            await locatieContext.Database.ExecuteSqlCommandAsync(
                "UPDATE ping SET rit_id = null, locatie_id = null, dag_id = null, verwerkt = 0 WHERE tijd >= @time AND FIND_IN_SET(id, @ids) != 0",
                new MySqlParameter("@time", fromTime),
                new MySqlParameter("@ids", string.Join(',', pings.Select(p => p.Id).ToList()))
                );

            await locatieContext.SaveChangesAsync();

            locatieContext.Database.SetCommandTimeout(timeoutOld);
        }
        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());
        }
Exemple #21
0
 public Task SaveAsync()
 {
     return(db.SaveChangesAsync());
 }