Ejemplo n.º 1
0
        public void RegisterUnregisterTest1()
        {
            var soba = new Soba(new UVars());

            Assert.Empty(new Inspector(soba).Root);

            Assert.True(soba.Register(new StubTryComponent(soba)));

            Assert.Single(new Inspector(soba).Root);

            Assert.True(soba.Register(new StubCommentComponent()));
            Assert.True(soba.Register(new StubBoxComponent(soba)));

            Assert.Equal(3, new Inspector(soba).Root.Count());

            Assert.True(soba.Unregister(new StubCommentComponent()));

            Assert.Equal(2, new Inspector(soba).Root.Count());

            var c1 = new StubConditionComponent(soba);

            Assert.True(soba.Register(c1));
            Assert.True(soba.Register(new StubUserVariableComponent(soba)));
            Assert.True(soba.Register(new StubEvMSBuildComponent(soba)));

            Assert.True(soba.Unregister(c1));

            Assert.Equal(4, new Inspector(soba).Root.Count());

            soba.Unregister();

            Assert.Empty(new Inspector(soba).Root);
        }
        //Event dodavanja nove Sobe
        private void buttonDodaj_Click(object sender, RoutedEventArgs e)
        {
            int godina = Convert.ToInt32(GodinaInput.Text);
            int mjesec = Convert.ToInt32(MjesecInput.Text);
            int dan    = Convert.ToInt32(DanInput.Text);

            using (var db = new RRentingDbContext())
            {
                var contact = new Soba
                {
                    BrojSobe          = Convert.ToInt32(CijenaSobeInput.Text),
                    CijenaSobe        = (float)Convert.ToDouble(CijenaSobeInput.Text),
                    BrojKreveta       = Convert.ToInt32(BrojKrevetaInput.Text),
                    Status            = (StatusSobe)Enum.Parse(typeof(StatusSobe), StatusSobeListBox.SelectedItem.ToString()),
                    RezervisaniDatumi = new List <DateTime>(),
                };
                contact.RezervisaniDatumi.Add(new DateTime(godina, mjesec, dan));
                db.Sobe.Add(contact);
                //SaveChanges obavezno da se reflektuju izmjene u bazi, tek tada dolazi do komunikacije
                // sa bazom
                db.SaveChanges();

                BrojSobeInput.Text             = string.Empty;
                CijenaSobeInput.Text           = string.Empty;
                BrojKrevetaInput.Text          = string.Empty;
                StatusSobeListBox.SelectedItem = null;
                DanInput.Text    = string.Empty;
                MjesecInput.Text = string.Empty;
                GodinaInput.Text = string.Empty;


                //refresh liste restorana
                SobeIS.ItemsSource = db.Sobe.OrderBy(c => c.CijenaSobe).ToList();
            }
        }
Ejemplo n.º 3
0
        public int EditSoba(Soba so)
        {
            try
            {
                ISession s = DataLayer.GetSession();

                Soba soba = s.Query <Soba>()
                            .Where(v => v.Id == so.Id).Select(p => p).FirstOrDefault();

                soba.Broj     = so.Broj;
                soba.Sprat    = so.Sprat;
                soba.Radio    = so.Radio;
                soba.Tv       = so.Tv;
                soba.Kupatilo = so.Kupatilo;
                soba.Klima    = so.Klima;
                soba.Slobodno = so.Slobodno;
                soba.More     = so.More;
                soba.Frizider = so.Frizider;
                soba.Tip      = so.Tip;

                s.Update(soba);

                s.Flush();
                s.Close();

                return(1);
            }
            catch (Exception ec)
            {
                return(-1);
            }
        }
Ejemplo n.º 4
0
        public IActionResult OnPost(string id)
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            else
            {
                MongoClient    client = new MongoClient("mongodb://localhost:27017");
                IMongoDatabase db     = client.GetDatabase("AMTravelDb");
                kolekcija = db.GetCollection <Soba>("soba");
                NoviId    = ObjectId.Parse(id);
                Soba PostojiSoba = kolekcija.Find(x => x.BrojSobe == NovaSoba.BrojSobe && x.Smestaj.Id == NoviId).FirstOrDefault();
                kolekcijaS     = db.GetCollection <Smestaj>("smestaj");
                PostojiSmestaj = kolekcijaS.Find(x => x.Id == NoviId).FirstOrDefault();

                if (PostojiSoba != null)
                {
                    PostojiVec = 1;
                    return(this.Page());
                }

                kolekcija.InsertOne(NovaSoba);

                PostojiSmestaj.Sobe.Add(new MongoDBRef("soba", NovaSoba.Id));
                NovaSoba.Smestaj = new MongoDBRef("smestaj", NoviId);


                kolekcija.ReplaceOne(x => x.Id == NovaSoba.Id, NovaSoba);
                kolekcijaS.ReplaceOne(x => x.Id == PostojiSmestaj.Id, PostojiSmestaj);
                return(RedirectToPage("./SobaSve", new{ id = id }));
            }
        }
        public async Task <IActionResult> Edit(int id, [Bind("ID,stanjeSobe,zauzetostSobe,brojGostiju,brojKreveta,cijena")] Soba soba)
        {
            if (id != soba.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(soba);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!SobaExists(soba.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(soba));
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> OdobriPremjestanjeAsync(int id)
        {
            ZahtjevZaPremjestanje z = _context.ZahtjevZaPremjestanje.Find(id);

            Student s = _context.Student.Find(z.StudentId);

            //Student s= await GetStudentAsync(z.StudentId);

            z.Soba2Id = z.Soba2Id + (z.Paviljon2Id - 1) * 25;

            Soba soba = _context.Soba.Find(z.Soba2Id);

            List <Student> studentiUSobi = _context.Student.Where(s => s.SobaId == z.Soba2Id).ToList();

            if (studentiUSobi.Count >= soba.Kapacitet)
            {
                throw new Exception("Nema mjesta u sobi u koju student želi da se premjeti");
            }

            _context.Zahtjev.Remove(z);

            s.SobaId = z.Soba2Id;

            _context.Student.Update(s);
            _context.SaveChanges();

            return(RedirectToAction("PregledZahtjeva", "Zahtjev"));
        }
Ejemplo n.º 7
0
        public ActionResult Create([Bind(Include = "Id,Naziv,Opis,Pocetak,Trajanje,AdminId,SportId, TerenId, MaksimalniBrojIgraca")] Soba soba)
        {
            if (ModelState.IsValid)
            {
                if (soba.Pocetak < DateTime.Now)
                {
                    TempData[Constants.Message]       = "Početak mora biti u budućnosti!";
                    TempData[Constants.ErrorOccurred] = false;
                    return(RedirectToAction("Create"));
                }

                var adminId = User.Identity.GetUserId();
                var admin   = db.Korisnici.Include(a => a.MojeSobe).Include(a => a.Sobe).FirstOrDefault(k => k.Id == adminId);
                soba.AdminId = admin.Id;
                // add admina u sobu
                soba.Igraci = new List <Korisnik>()
                {
                    admin
                };
                admin.MojeSobe.Add(soba);
                admin.Sobe.Add(soba);

                db.Sobe.Add(soba);
                db.SaveChanges();
                TempData[Constants.Message]       = "Soba " + soba.Naziv + " kreirana";
                TempData[Constants.ErrorOccurred] = false;
                return(RedirectToAction("Index"));
            }

            ViewBag.AdminId = new SelectList(db.Users, "Id", "Email", soba.AdminId);
            ViewBag.SportId = new SelectList(db.Sportovi, "Id", "Naziv", soba.SportId);
            return(View(soba));
        }
Ejemplo n.º 8
0
        public static RezervacijaSobe getRezervacija(Soba soba, DateTime d1)
        {
            MojContext db = new MojContext();

            //doradi ovaj upit tako da uzmeš u obzir  datum za koji povjeravaš rezervaciju
            return(db.RezervacijeSoba.Where(r => r.SobaId == soba.Id && r.DatumOdjave >= d1 && r.DatumPrijave <= d1).FirstOrDefault());
        }
Ejemplo n.º 9
0
        public static void Load()
        {
            using (SqlConnection conn = new SqlConnection(Aplikacija.CONNECTION_STRING))
            {
                conn.Open();

                SqlCommand cmd = conn.CreateCommand();
                cmd.CommandText = @"select * from soba where postoji=1";

                SqlDataAdapter sqlDA = new SqlDataAdapter();
                sqlDA.SelectCommand = cmd;

                DataSet ds = new DataSet();
                sqlDA.Fill(ds, "sobe");

                //Console.WriteLine(ds.GetXml());
                foreach (DataRow row in ds.Tables["sobe"].Rows)
                {
                    Soba s = new Soba();
                    s.Id   = (long)row["ID"];
                    s.Broj = (int)row["BROJ"];
                    //s.TipS = row["TIP_ID"] as TipSobe;
                    s.TipS    = Aplikacija.Instanca.hotel.PronadjiTipSobePoId((long)row["TIP_ID"]);
                    s.Tv      = (bool)row["TV"];
                    s.MiniBar = (bool)row["MINI_BAR"];

                    Aplikacija.Instanca.hotel.sobe.Add(s);
                }
            }
        }
        public async Task <IActionResult> Edit(int id, [Bind("SobaID,BrojSobe,Zauzeta,Sprat")] Soba soba)
        {
            if (id != soba.SobaID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(soba);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!SobaExists(soba.SobaID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(soba));
        }
Ejemplo n.º 11
0
        public IActionResult Snimi(int Id)
        {
            KorisnickiNalog korisnik = HttpContext.GetLogiraniKorisnik();
            int             indeks   = _db.Gost.Where(g => g.NalogID == korisnik.Id).Select(l => l.id).FirstOrDefault();
            Soba            x        = _db.Soba.Find(Id);
            Rezervacija     nova     = new Rezervacija
            {
                GostID           = indeks,
                datumRezervacije = DateTime.Now,
                _ZaposlenikId    = 3,
                Aktivna          = true
            };

            _db.Rezervacija.Add(nova);
            _db.SaveChanges();
            RezervisanaSoba soba = new RezervisanaSoba
            {
                RezervacijaID = nova.Id,
                SobaID        = x.Id,
                pusenje       = false,
            };

            x.Dostupna = false;
            _db.Update(x);
            _db.SaveChanges();
            _db.RezervisanaSoba.Add(soba);
            _db.SaveChanges();

            return(RedirectToAction(nameof(Index)));
        }
        private void AddSoba()
        {
            Soba novaSoba = new Soba();

            novaSoba.Sifra     = Convert.ToInt32(SifraTb.Text);
            novaSoba.Kapacitet = Convert.ToInt32(KapacitetTb.Text);
            novaSoba.Zauzetost = Convert.ToInt32(ZauzetostTb.Text);
            novaSoba.Tip       = (TypeOfUsage)TipCb.SelectedItem;
            novaSoba.Pocetak   = (DateTime)PocetakTb.SelectedDate;
            novaSoba.Kraj      = (DateTime)KrajTb.SelectedDate;
            Sobe.Add(novaSoba);
            RoomController             roomController             = new RoomController();
            RenovationPeriodController renovationPeriodController = new RenovationPeriodController();
            RenovationPeriod           p = new RenovationPeriod();
            Room room = new Room();

            room.Capacity   = novaSoba.Kapacitet;
            room.Number     = novaSoba.Sifra;
            room.Occupation = novaSoba.Zauzetost;
            room.Usage      = novaSoba.Tip;
            if (novaSoba.Pocetak != DateTime.Today && novaSoba.Kraj != DateTime.Today)
            {
                room.Renovation = true;
                p.room          = room;
                p.BeginDate     = novaSoba.Pocetak;
                p.EndDate       = novaSoba.Kraj;
                renovationPeriodController.ScheduleRenovation(p);
            }

            roomController.AddRoom(room);
            // Resetujemo polja
            ClearFields();

            UpdateTempSoba();
        }
        public IActionResult SnimiDodavanjeStudenta(SobeDodajStudentaVM model)
        {
            KorisnickiNalog korisnik = HttpContext.GetLogiraniKorisnik();
            Zaposlenik      z        = _context.Zaposlenici.Where(x => x.Id == korisnik.Id).FirstOrDefault();

            if (korisnik == null || z == null || z._VrstaZaposlenikaId != 1)
            {
                TempData["error_poruka"] = "Nemate pravo pristupa!";
                return(Redirect("/Autentifikacija/Index"));
            }

            StudentSoba noviSS = new StudentSoba();

            noviSS.DatumDodjele  = DateTime.Now;
            noviSS._SobaId       = model.SobaId;
            noviSS._StudentId    = (int)model.StudentID;
            noviSS._ZaposlenikId = z.Id;
            noviSS.Napomena      = model.Napomena;
            _context.StudentiSobe.Add(noviSS);
            _context.SaveChanges();

            Soba s = _context.Sobe.Where(x => x.Id == model.SobaId).FirstOrDefault();

            s.BrojKreveta++;
            _context.Sobe.Update(s);
            _context.SaveChanges();

            return(Redirect("/RecepcionerModul/Sobe/Index"));
        }
Ejemplo n.º 14
0
        public void DataTest1()
        {
            var soba = new Soba(new UVars());
            var dom  = new Inspector(soba);

            Assert.Empty(dom.Root);
            Assert.Empty(dom.GetBy(new StubEvMSBuildComponent(soba)));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            Soba soba = db.Sobe.Find(id);

            db.Sobe.Remove(soba);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 16
0
        public async Task UpisiSobu(int idHotela, [FromBody] Soba soba)
        {
            var hotel = await Context.Hoteli.FindAsync(idHotela);

            soba.Hotel = hotel;
            Context.Sobe.Add(soba);
            await Context.SaveChangesAsync();
        }
Ejemplo n.º 17
0
        public IActionResult Obrisi(int sobaID)
        {
            Soba soba = _db.Soba.Find(sobaID);

            _db.Soba.Remove(soba);
            _db.SaveChanges();

            return(Redirect("/Administrator/Sobe/Index"));
        }
Ejemplo n.º 18
0
        public void RegisterUnregisterTest2()
        {
            var soba = new Soba(new UVars());

            soba.Register(new StubTryComponent(soba));
            soba.Register(new StubCommentComponent());
            soba.Register(new StubBoxComponent(soba));

            Assert.Throws <ArgumentNullException>(() => soba.Unregister(null));
        }
Ejemplo n.º 19
0
 public ActionResult Edit([Bind(Include = "SobaID,HotelID,BrojSobe,TipSobeID")] Soba soba)
 {
     if (ModelState.IsValid)
     {
         //db.ChangeState<Soba>(soba);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(soba));
 }
Ejemplo n.º 20
0
 public ActionResult Edit([Bind(Include = "idsoba,brojSobe,brojKreveta,cijenaSobe")] Soba soba)
 {
     if (ModelState.IsValid)
     {
         db.Entry(soba).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(soba));
 }
Ejemplo n.º 21
0
 private void btnDelete_Click(object sender, RoutedEventArgs e)
 {
     if (MessageBox.Show("Da li ste sigurni???", "Brisanje sobe", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
     {
         Soba s = dgSobe.SelectedItem as Soba;
         Aplikacija.Instanca.hotel.sobe.Remove(s);
         SobaDAO.DeleteLogicko(s);
         dgSobe.Items.Refresh();
     }
 }
Ejemplo n.º 22
0
 public SobaInsertRequest Insert(SobaInsertRequest model)
 {
     if (model.SobaId == 0)
     {
         Soba s = _mapper.Map <Soba>(model);
         _context.Soba.Add(s);
         _context.SaveChanges();
     }
     return(model);
 }
Ejemplo n.º 23
0
        public IActionResult CenaSobe([FromBody] Soba soba)
        {
            SmestajProvider provider = new SmestajProvider();
            double          cena     = provider.CenaSobe(soba.smestaj, soba.Tip);

            if (cena > 0)
            {
                return(Ok(cena));
            }
            return(NotFound());
        }
        public async Task <IActionResult> Create([Bind("SobaID,BrojSobe,Zauzeta,Sprat")] Soba soba)
        {
            if (ModelState.IsValid)
            {
                _context.Add(soba);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(soba));
        }
 public ActionResult Edit([Bind(Include = "Id,BrojSobe,BrojKreveta,Cena,SmestajId")] Soba soba)
 {
     if (ModelState.IsValid)
     {
         db.Entry(soba).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.SmestajId = new SelectList(db.Smestaji, "Id", "Naziv", soba.SmestajId);
     return(View(soba));
 }
Ejemplo n.º 26
0
        public IHttpActionResult GetSoba(int id)
        {
            Soba soba = db.Sobas.Find(id);

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

            return(Ok(Mapper.Map <Soba, SobaDto>(soba)));
        }
Ejemplo n.º 27
0
        public IActionResult OnGet(string id)
        {
            MongoClient    client = new MongoClient("mongodb://localhost:27017");
            IMongoDatabase db     = client.GetDatabase("AMTravelDb");

            kolekcija    = db.GetCollection <Soba>("soba");
            NoviId       = ObjectId.Parse(id);
            TrenutnaSoba = kolekcija.Find(x => x.Id == NoviId).FirstOrDefault();

            return(Page());
        }
        public async Task <IActionResult> Create([Bind("ID,stanjeSobe,zauzetostSobe,brojGostiju,brojKreveta,cijena")] Soba soba)
        {
            if (ModelState.IsValid)
            {
                _context.Add(soba);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(soba));
        }
Ejemplo n.º 29
0
        public static Soba MockingRoom()
        {
            var room = new Soba
            {
                HotelID   = 1,
                SobaID    = 2,
                BrojSobe  = 100,
                TipSobeID = 1
            };

            return(room);
        }
Ejemplo n.º 30
0
 public bool AddSoba(int hotelId, Soba s)
 {
     s.HotelId = hotelId;
     if (hdao.Read(hotelId) != null)
     {
         return sdao.Create(s);
     }
     else
     {
         return false;
     }
 }
Ejemplo n.º 31
0
 public SobaCombiSelector(int totalGram)
 {
     this.totalGram = totalGram;
     sobaA          = new Soba("A", 200, 380, 5, 20);
     sobaB          = new Soba("B", 300, 550, 4, 15);
     sobaC          = new Soba("C", 500, 850, 3, 12);
     sobas          = new List <Soba>()
     {
         sobaA, sobaB, sobaC
     };
     candidateSobaCombies = new List <SobaCombi>();
 }