public static void Load()
        {
            using (SqlConnection conn = new SqlConnection(Aplikacija.CONNECTION_STRING))
            {
                conn.Open();

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

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

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

                //Console.WriteLine(ds.GetXml());
                foreach (DataRow row in ds.Tables["tipoviSobe"].Rows)
                {
                    TipSobe ts = new TipSobe();
                    ts.Id          = (long)row["ID"];
                    ts.Naziv       = (string)row["NAZIV"];
                    ts.BrojKreveta = (int)row["BR_KREVETA"];

                    Aplikacija.Instanca.hotel.tipoviSobe.Add(ts);
                }
            }
        }
예제 #2
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Naziv,Opis")] TipSobe tipSobe)
        {
            if (id != tipSobe.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(tipSobe);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TipSobeExists(tipSobe.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(tipSobe));
        }
예제 #3
0
        public async Task <IActionResult> Create([Bind("Id,Kapacitet,Naziv,Opis")] TipSobe tipSobe)
        {
            if (ModelState.IsValid)
            {
                _context.Add(tipSobe);
                await _context.SaveChangesAsync();

                List <TipSobeNamjestaj> nova = new List <TipSobeNamjestaj>();
                foreach (Namjestaj.TipNamjestaja val in Enum.GetValues(typeof(Namjestaj.TipNamjestaja)))
                {
                    nova.Add(new TipSobeNamjestaj()
                    {
                        TipNamjestaja = val,
                        Kolicina      = tipSobe.Kapacitet,
                        TipSobeID     = tipSobe.Id
                    });
                }
                _context.TipSobeNamjestaj.AddRange(nova);
                _context.SaveChanges();


                return(RedirectToAction(nameof(Index)));
            }
            return(View(tipSobe));
        }
예제 #4
0
        public void Index_ShouldReturnSameCountOfRooms()
        {
            var context = new TestHotelContext();

            Hotel   p = new Hotel();
            TipSobe c = new TipSobe();

            context.Hoteli.Add(p);
            context.TipSoba.Add(c);

            var controller = new SobaController(context);

            controller.Create(new Soba {
                Hotel = p, TipSobe = c
            });
            controller.Create(new Soba {
                Hotel = p, TipSobe = c
            });
            controller.Create(new Soba {
                Hotel = p, TipSobe = c
            });

            var result   = controller.Index() as ViewResult;
            var roomData = (IList <Soba>)result.ViewData.Model;

            Assert.IsNotNull(roomData, "There's no room data");
            Assert.AreEqual(3, roomData.Count, "The count does not match");
        }
예제 #5
0
        public ActionResult DeleteConfirmed(int id)
        {
            TipSobe tipSobe = db.TipSoba.Find(id);

            db.TipSoba.Remove(tipSobe);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 private void btnObrisi_Click(object sender, RoutedEventArgs e)
 {
     if (MessageBox.Show("Da li ste sigurni???", "Brisanje tipa sobe", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
     {
         TipSobe ts = dgTipoviSobe.SelectedItem as TipSobe;
         Aplikacija.Instanca.hotel.tipoviSobe.Remove(ts);
         TipSobeDAO.Delete(ts);
         dgTipoviSobe.Items.Refresh();
     }
 }
예제 #7
0
 public ActionResult Edit([Bind(Include = "TipSobeID,OpisSobe,CijenaPoNoci")] TipSobe tipSobe)
 {
     if (ModelState.IsValid)
     {
         // db.ChangeState<TipSobe>(tipSobe);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(tipSobe));
 }
예제 #8
0
        public ActionResult Create([Bind(Include = "TipSobeID,OpisSobe,CijenaPoNoci")] TipSobe tipSobe)
        {
            if (ModelState.IsValid)
            {
                db.TipSoba.Add(tipSobe);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(tipSobe));
        }
예제 #9
0
        // GET: TipSobe/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TipSobe tipSobe = db.TipSoba.Find(id);

            if (tipSobe == null)
            {
                return(HttpNotFound());
            }
            return(View(tipSobe));
        }
예제 #10
0
        public IActionResult SnimiTip(SobeTipSobeDodajVM model)
        {
            if (!ModelState.IsValid)
            {
                return(View("DodajTipSobe", model));
            }
            TipSobe tipSobe = new TipSobe();

            tipSobe = model.TipSobe;
            _db.TipSobe.Add(tipSobe);
            _db.SaveChanges();

            return(RedirectToAction(nameof(Dodaj)));
        }
        public static void DeleteLogicko(TipSobe ts)
        {
            using (SqlConnection conn = new SqlConnection(Aplikacija.CONNECTION_STRING))
            {
                conn.Open();

                SqlCommand cmd = conn.CreateCommand();
                cmd.CommandText = @"update tip_soba set postoji=0 where id=@id";


                cmd.Parameters.Add(new SqlParameter("@id", ts.Id));

                cmd.ExecuteNonQuery();
            }
        }
        public static void Create(TipSobe ts)
        {
            using (SqlConnection conn = new SqlConnection(Aplikacija.CONNECTION_STRING))
            {
                conn.Open();

                SqlCommand cmd = conn.CreateCommand();
                cmd.CommandText = @"insert into tip_soba (br_kreveta,naziv,postoji) values (@brKreveta, @naziv, 1)";

                cmd.Parameters.Add(new SqlParameter("@brKreveta", ts.BrojKreveta));
                cmd.Parameters.Add(new SqlParameter("@naziv", ts.Naziv));
                cmd.Parameters.Add(new SqlParameter("@id", ts.Id));

                cmd.ExecuteNonQuery();
            }
        }
        public static void Update(TipSobe ts)
        {
            using (SqlConnection conn = new SqlConnection(Aplikacija.CONNECTION_STRING))
            {
                conn.Open();

                SqlCommand cmd = conn.CreateCommand();
                cmd.CommandText = @"update tip_soba set br_kreveta=@brKreveta, naziv=@naziv where id=@id";

                cmd.Parameters.Add(new SqlParameter("@brKreveta", ts.BrojKreveta));
                cmd.Parameters.Add(new SqlParameter("@naziv", ts.Naziv));
                cmd.Parameters.Add(new SqlParameter("@id", ts.Id));

                cmd.ExecuteNonQuery();
            }
        }
예제 #14
0
        public IzmeniTipSobeWindow(TipoviSobeWindow tipoviSobeWindow, STANJE st)
            : this()
        {
            this.tipoviSobeWindow = tipoviSobeWindow;
            this.trenutnoStanje   = st;
            if (st == STANJE.IZMENA)
            {
                this.orgTipSobe = tipoviSobeWindow.dgTipoviSobe.SelectedItem as TipSobe;
                this.tipSobe    = orgTipSobe.Clone() as TipSobe;
            }
            else
            {
                this.tipSobe    = new TipSobe();
                this.orgTipSobe = tipSobe;
            }

            this.DataContext = tipSobe;
        }
예제 #15
0
        public void Create_ShouldNotCreateRoomWithoutRoomType()
        {
            var context = new TestHotelContext();

            Hotel   p = new Hotel();
            TipSobe c = new TipSobe();

            context.Hoteli.Add(p);
            context.TipSoba.Add(c);

            var controller = new SobaController(context);

            controller.Create(new Soba {
                Hotel = p, TipSobe = c, TipSobeID = 5
            });
            controller.ModelState.AddModelError("TipSobeID", "Room type does not exist");

            Assert.IsTrue(controller.ModelState.IsValid == false, "The model state is valid");
        }
예제 #16
0
        public void Update_ShouldUpdateRoomType()
        {
            mockContext = new Mock <IHotelAC>();
            mockSet     = new Mock <DbSet <TipSobe> >();
            mockContext.Setup(m => m.TipSoba).Returns(mockSet.Object);

            var controller  = new TipSobeController(mockContext.Object);
            var newRoomType = new TipSobe
            {
                CijenaPoNoci = 100,
                OpisSobe     = "Test",
                TipSobeID    = 1
            };

            controller.Create(newRoomType);
            newRoomType.CijenaPoNoci = 200;
            controller.Edit(newRoomType);

            Assert.IsTrue(200 == newRoomType.CijenaPoNoci, "The room type did not update");
        }
예제 #17
0
        public void Create_ShouldReturnInvalidModelState()
        {
            mockContext = new Mock <IHotelAC>();
            mockSet     = new Mock <DbSet <TipSobe> >();
            mockContext.Setup(m => m.TipSoba).Returns(mockSet.Object);

            var controller = new TipSobeController(mockContext.Object);

            controller.ModelState.AddModelError("CijenaSobe", "Room price needs to have a value");

            var newRoomType = new TipSobe
            {
                CijenaPoNoci = 0,
                OpisSobe     = "Test",
                TipSobeID    = 1
            };

            controller.Create(newRoomType);

            Assert.IsTrue(controller.ViewData.ModelState.IsValid == false, "Room price cannot be zero");
        }