public async Task <IActionResult> ReadNotification(Notifikacija notifikacija)
        {
            var not = _context.Notifications.Where(e => e.Id == notifikacija.Id).FirstOrDefault();

            not.Procitana = true;
            Console.WriteLine("Citanje {0} notifikacije", notifikacija.Id);
            _context.Entry(not).State = EntityState.Modified;
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!NotifikacijaExists(notifikacija.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <ActionResult <Incident> > AddIncident(Incident incident)
        {
            _context.Incidents.Add(incident);
            List <Device> allDevices = await _context.Devices.ToListAsync();

            //var deviceDb = await _context.Devices.SingleOrDefaultAsync(d => d.Id == i)

            //foreach(Device item in incident.Devices)
            //{
            //    foreach(Device device in allDevices)
            //    {
            //        if(item.Id == device.Id)
            //        {
            //            device.IncidentId = incident.Id;
            //            _context.Devices.Update(device);
            //        }
            //    }
            //}

            await _context.SaveChangesAsync();

            List <Incident> allIncidents = await _context.Incidents.ToListAsync();


            return(CreatedAtAction("GetAllIncidents", _context.Incidents));
        }
Beispiel #3
0
        public async Task <ActionResult <Promenauloge> > AddZahtev(Promenauloge zahtev)
        {
            _context.Zahtevi.Add(zahtev);
            await _context.SaveChangesAsync();

            return(NoContent());
        }
Beispiel #4
0
        public async Task <ActionResult <Device> > AddDevice(Device device)
        {
            if (device.Type.StartsWith("Pow"))
            {
                device.Name = "POW";
            }
            else if (device.Type.StartsWith("Fu"))
            {
                device.Name = "FUS";
            }
            else if (device.Type.StartsWith("Tra"))
            {
                device.Name = "TRA";
            }
            else if (device.Type.StartsWith("Dis"))
            {
                device.Name = "DIS";
            }

            _context.Devices.Add(device);
            await _context.SaveChangesAsync();

            List <Device> devices = await _context.Devices.ToListAsync();

            device.Name += devices[devices.Count() - 1].Id;

            _context.Devices.Update(device);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetAllDevices", _context.Devices));
        }
Beispiel #5
0
        public async Task <ActionResult <Workplan> > AddWorkplan(Workplan workplan)
        {
            _context.Workplans.Add(workplan);
            await _context.SaveChangesAsync();

            return(NoContent());
        }
        public async Task <ActionResult <Incident> > AddSafetydoc(Safetydoc safetydoc)
        {
            _context.Safetydocs.Add(safetydoc);

            await _context.SaveChangesAsync();


            return(CreatedAtAction("GetAllSafetydocs", _context.Safetydocs));
        }
        public async Task <IActionResult> UpdatePotrosac(Potrosac potrosac)
        {
            var oldpotrosac = _context.Potrosaci.Where(e => e.Id == potrosac.Id).FirstOrDefault();

            oldpotrosac.Ime            = potrosac.Ime;
            oldpotrosac.Prezime        = potrosac.Prezime;
            oldpotrosac.Ulica          = potrosac.Ulica;
            oldpotrosac.Grad           = potrosac.Grad;
            oldpotrosac.Broj_telefona  = potrosac.Broj_telefona;
            oldpotrosac.Postanski_broj = potrosac.Postanski_broj;
            oldpotrosac.Tip            = potrosac.Tip;

            Lokacija l = new Lokacija();

            l.Ulica = oldpotrosac.Ulica;
            l.Grad  = oldpotrosac.Grad;
            oldpotrosac.Prioritet = getPriority(l);

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


            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PotrosacExists(oldpotrosac.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }


            return(NoContent());
        }
Beispiel #8
0
        public async Task <IActionResult> UpdateSettings(Podesavanja podesavanja)
        {
            var oldsettings = _context.Settings.First();

            oldsettings.Obavezna              = podesavanja.Obavezna;
            oldsettings.Errorvidljive         = podesavanja.Errorvidljive;
            oldsettings.Infovidljive          = podesavanja.Infovidljive;
            oldsettings.Successvidljive       = podesavanja.Successvidljive;
            oldsettings.Warningvidljive       = podesavanja.Warningvidljive;
            _context.Entry(oldsettings).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(NoContent());
        }
Beispiel #9
0
        public async Task <IHttpActionResult> DeleteProsumer(string id)
        {
            Prosumer prosumer = await _db.Prosumers.FindAsync(id);

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

            _db.Prosumers.Remove(prosumer);
            await _db.SaveChangesAsync();

            return(Ok(prosumer));
        }
        public async Task <ActionResult <PrioritetLok> > addPriority(PrioritetLok lokacijaprioritet)
        {
            //List<LokacijaPrioritet> postoji = _context.PrioritetiLokacija.Where(e => e.Ulica.ToLower().Trim() == lokacijaprioritet.Ulica.ToLower().Trim() && e.Grad.ToLower().Trim() == lokacijaprioritet.Grad.ToLower().Trim()).ToList();

            if (!CheckIfExists(lokacijaprioritet))
            {
                _context.PrioritetiLokacija.Add(lokacijaprioritet);

                var potrosaci = _context.Potrosaci.Where(e => e.Ulica.Equals(lokacijaprioritet.Ulica) && e.Grad.Equals(lokacijaprioritet.Grad)).ToList();
                foreach (Potrosac p in potrosaci)
                {
                    p.Prioritet             = lokacijaprioritet.Prioritet;
                    _context.Entry(p).State = EntityState.Modified;
                }


                await _context.SaveChangesAsync();
            }
            else
            {
                var value = _context.PrioritetiLokacija.Where(e => e.Ulica.ToLower().Trim().Equals(lokacijaprioritet.Ulica.ToLower().Trim()) && e.Grad.ToLower().Trim().Equals(lokacijaprioritet.Grad.ToLower().Trim())).FirstOrDefault();
                value.Prioritet             = lokacijaprioritet.Prioritet;
                _context.Entry(value).State = EntityState.Modified;

                var potrosaci = _context.Potrosaci.Where(e => e.Ulica.Equals(lokacijaprioritet.Ulica) && e.Grad.Equals(lokacijaprioritet.Grad)).ToList();
                foreach (Potrosac p in potrosaci)
                {
                    p.Prioritet             = lokacijaprioritet.Prioritet;
                    _context.Entry(p).State = EntityState.Modified;
                }



                await _context.SaveChangesAsync();
            }
            return(NoContent());
        }
Beispiel #11
0
        public async Task <IActionResult> UpdateUser(User user)
        {
            var userforchange = _context.Users.Where(e => e.Id == user.Id).FirstOrDefault();

            userforchange.Username = user.Username;
            userforchange.Name     = user.Name;
            userforchange.LastName = user.LastName;
            userforchange.Email    = user.Email;
            userforchange.Password = user.Password;
            userforchange.UserRole = user.UserRole;
            if (user.Address != null)
            {
                userforchange.Address = user.Address;
            }
            if (user.BirthDate != null)
            {
                userforchange.BirthDate = user.BirthDate;
            }



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

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserExists(user.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }