예제 #1
0
        public bool OpdaterEnOpgave(int nr, Opgave opgave)
        {
            //Eksempel på brud med DRY
            //String OpgaveUri = "http://localhost:59327/api/Opgave/" + nr;
            //s**t på eksempel

            String        json    = JsonConvert.SerializeObject(opgave);
            StringContent content = new StringContent(json);

            content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            using (HttpClient client = new HttpClient())
            {
                HttpResponseMessage resultMessage = client.PutAsync(Uri + nr, content).Result;

                if (resultMessage.IsSuccessStatusCode)
                {
                    string resultStr = resultMessage.Content.ReadAsStringAsync().Result;
                    bool   res       = JsonConvert.DeserializeObject <bool>(resultStr);
                    return(res);
                }
            }

            return(false);
        }
        /// <summary>
        /// Constructor
        /// </summary>
        public OpgaveViewModel()
        {
            OpgaveHandler = new OpgaveHandler(this);
            Logbog        = LogbogSingleton.Instance;

            //2. iteration
            AddCommand    = new RelayCommand(OpgaveHandler.IndsætOpgave);
            UpdateCommand = new RelayCommand(OpgaveHandler.OpdaterOpgave);
            RemoveCommand = new RelayCommand(OpgaveHandler.SletOpgave);

            NyOpgave = new Opgave();

            StatusListe = new List <StatusType>()
            {
                StatusType.Løst, StatusType.Fejlet, StatusType.IkkeLøst
            };

            //3. iteration
            UdstyrsListe = new ObservableCollection <Udstyr>(Logbog.UFacade.HentAltUdstyr());

            HentCommand = new RelayCommand(OpgaveHandler.HentOpgaver);

            //Pop up test
            PopUpTestCommand = new RelayCommand(OpgaveHandler.TestPopUp);
        }
        public Opgave SletOpgave(int opgaveID)
        {
            Opgave opgave = HentOpgaveFraId(opgaveID);

            if (opgave == null)
            {
                return(null);
            }

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                SqlCommand command = new SqlCommand(deleteSql, connection);
                command.Parameters.AddWithValue("@ID", opgaveID);

                command.Connection.Open();

                int noOfRows = command.ExecuteNonQuery();

                if (noOfRows == 1)
                {
                    return(opgave);
                }
                return(null);
            }
        }
예제 #4
0
        /// <summary>
        /// Metode til at opdatere en række i RisoeOpgave Tabellen
        /// </summary>
        /// <param name="opgave"></param>
        /// <param name="opgaveID"></param>
        /// <returns>bool</returns>
        public bool OpdaterOpgave(Opgave opgave, int opgaveID)
        {
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                SqlCommand command = new SqlCommand(updateSql, connection);
                //command.Parameters.AddWithValue("@OpgaveID", opgave.ID);
                //command.Parameters.AddWithValue("@Beskrivelse", opgave.Beskrivelse);
                //command.Parameters.AddWithValue("@Status", opgave.Status.ToString());
                //command.Parameters.AddWithValue("@Ventetid", opgave.VentetidIDage);

                //Brug af TilføjVærdiOpgave metode (DRY)
                TilføjVærdiOpgave(opgave, command);
                command.Parameters.AddWithValue("@ID", opgaveID);

                command.Connection.Open();

                int noOfRows = command.ExecuteNonQuery();

                if (noOfRows == 1)
                {
                    return(true);
                }
                return(false);
            }
        }
예제 #5
0
        public ActionResult DeleteConfirmed(int id)
        {
            Opgave opgave = db.Opgave.Find(id);

            db.Opgave.Remove(opgave);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 //Indsæt og Opdater (DRY)
 private void TilføjVærdiOpgave(Opgave opgave, SqlCommand command)
 {
     command.Parameters.AddWithValue("@OpgaveID", opgave.ID);
     command.Parameters.AddWithValue("@Beskrivelse", opgave.Beskrivelse);
     command.Parameters.AddWithValue("@Status", opgave.Status.ToString());
     command.Parameters.AddWithValue("@Ventetid", opgave.VentetidIDage);
     command.Parameters.AddWithValue("@UdstyrID", opgave.Udstyr.UdstyrId);
 }
예제 #7
0
 public ActionResult Edit([Bind(Include = "ID,elementID,inhoud,score,typeScore,categorie,antwoorden,openbaar,makerID,aanmaakdatum,laatstGewijzigDoor,datumGewijzigd,isBackup")] Opgave opgave)
 {
     if (ModelState.IsValid)
     {
         db.Entry(opgave).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.elementID = new SelectList(db.Kenniselement, "ID", "inhoud", opgave.elementID);
     return(View(opgave));
 }
        public Opgave HentEnOpgave(int nr)
        {
            using (HttpClient client = new HttpClient())
            {
                string jsonStr = client.GetStringAsync(Uri + nr).Result; // info fra body
                Opgave opgave  = new Opgave();

                opgave = JsonConvert.DeserializeObject <Opgave>(jsonStr);

                return(opgave);
            }
        }
예제 #9
0
        // GET: Opgave/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Opgave opgave = db.Opgave.Find(id);

            if (opgave == null)
            {
                return(HttpNotFound());
            }
            return(View(opgave));
        }
예제 #10
0
        // GET: Opgave/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Opgave opgave = db.Opgave.Find(id);

            if (opgave == null)
            {
                return(HttpNotFound());
            }
            ViewBag.elementID = new SelectList(db.Kenniselement, "ID", "inhoud", opgave.elementID);
            return(View(opgave));
        }
        public Opgave SletOpgave(int nr)
        {
            using (HttpClient client = new HttpClient())
            {
                HttpResponseMessage resultMessage = client.DeleteAsync(Uri + nr).Result;

                if (resultMessage.IsSuccessStatusCode)
                {
                    string resultStr = resultMessage.Content.ReadAsStringAsync().Result;
                    Opgave opgave    = JsonConvert.DeserializeObject <Opgave>(resultStr);
                    return(opgave);
                }
            }

            return(null);
        }
예제 #12
0
        public void IndsætOgHentOpgaverTest()
        {//arrange
            int    listelængde1;
            int    listelængde2;
            Opgave testOpgave = new Opgave(999, "testopgave", StatusType.IkkeLøst, 2, new Udstyr(2));

            //act
            testListe    = opgaveTester.HentAlleOpgaver();
            listelængde1 = testListe.Count;
            opgaveTester.IndsætOpgave(testOpgave);
            testListe    = opgaveTester.HentAlleOpgaver();
            listelængde2 = testListe.Count;
            opgaveTester.SletOpgave(999);

            //assert
            Assert.AreEqual(listelængde1 + 1, listelængde2);
        }
        public void InputTest()
        {
            //arrange
            StatusType st  = StatusType.Fejlet;
            int        id  = 1;
            string     ts  = "Beskrivelse";
            Udstyr     uds = new Udstyr();


            //act
            Opgave TestOpgave = new Opgave(id, ts, st, id, uds);

            //assert
            Assert.AreEqual(id, TestOpgave.ID);
            Assert.AreEqual(ts, TestOpgave.Beskrivelse);
            Assert.AreEqual(st, TestOpgave.Status);
            Assert.AreEqual(uds, TestOpgave.Udstyr);
        }
        public bool IndsætOpgave(Opgave opgave)
        {
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                SqlCommand command = new SqlCommand(insertSql, connection);

                TilføjVærdiOpgave(opgave, command);

                command.Connection.Open();

                int noOfRows = command.ExecuteNonQuery();

                if (noOfRows == 1)
                {
                    return(true);
                }
                return(false);
            }
        }
예제 #15
0
        public Opgave SletOpgave(int nr)
        {
            //Eksempel på brud med DRY
            //String OpgaveUri = "http://localhost:59327/api/Opgave/" + nr;
            //s**t på eksempel

            using (HttpClient client = new HttpClient())
            {
                HttpResponseMessage resultMessage = client.DeleteAsync(Uri + nr).Result;

                if (resultMessage.IsSuccessStatusCode)
                {
                    string resultStr = resultMessage.Content.ReadAsStringAsync().Result;
                    Opgave opgave    = JsonConvert.DeserializeObject <Opgave>(resultStr);
                    return(opgave);
                }
            }

            return(null);
        }
        public bool OpdaterOpgave(Opgave opgave, int opgaveID)
        {
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                SqlCommand command = new SqlCommand(updateSql, connection);

                TilføjVærdiOpgave(opgave, command);
                command.Parameters.AddWithValue("@ID", opgaveID);

                command.Connection.Open();

                int noOfRows = command.ExecuteNonQuery();

                if (noOfRows == 1)
                {
                    return(true);
                }
                return(false);
            }
        }
예제 #17
0
        public Opgave HentEnOpgave(int nr)
        {
            //Eksempel på brud med DRY
            //String OpgaveUri = "http://localhost:59327/api/Opgave/" + nr;
            //s**t på eksempel

            using (HttpClient client = new HttpClient())
            {
                string jsonStr = client.GetStringAsync(Uri + nr).Result; // info fra body
                Opgave opgave  = new Opgave();
                try
                {
                    opgave = JsonConvert.DeserializeObject <Opgave>(jsonStr);
                }
                catch (Exception ex)
                {
                    MessageDialogHandler.Show(ex.ToString(), "Status kan ikke hentes fra database.");
                }
                return(opgave);
            }
        }
        public bool OpdaterEnOpgave(int nr, Opgave opgave)
        {
            String        json    = JsonConvert.SerializeObject(opgave);
            StringContent content = new StringContent(json);

            content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            using (HttpClient client = new HttpClient())
            {
                HttpResponseMessage resultMessage = client.PutAsync(Uri + nr, content).Result;

                if (resultMessage.IsSuccessStatusCode)
                {
                    string resultStr = resultMessage.Content.ReadAsStringAsync().Result;
                    bool   res       = JsonConvert.DeserializeObject <bool>(resultStr);
                    return(res);
                }
            }

            return(false);
        }
        //2. iteration, men skrevet i 1. iteration
        public void OpdaterOpgave()
        {
            Opgave opgave   = OpgaveViewModel.NyOpgave;
            int    udstyrID = OpgaveViewModel.AdminUdstyr.UdstyrId;

            int opgaveID = OpgaveViewModel.ValgtOpgave.ID;

            OpgaveViewModel.Logbog.OFacade.OpdaterEnOpgave(opgaveID, opgave);

            //ListView opdatering
            OpgaveViewModel.Logbog.OpgaveListe.Clear();

            var opgaver = OpgaveViewModel.Logbog.OFacade.HentOpgaverForUdstyrID(udstyrID);

            foreach (var o in opgaver)
            {
                OpgaveViewModel.Logbog.AddO(o);
            }

            OpgaveViewModel.OpgaveErValgt = false;
        }
예제 #20
0
 public void AddO(Opgave opgave)
 {
     OpgaveListe.Add(opgave);
 }
        //This is the main running program for testing the code
        public void Main()
        {
            //Code below this line-----------------------------------------------------------------------------------------------------
            //Hent Opgave (test)
            Console.WriteLine("Test af hentning af alle opgave");
            Console.WriteLine("");

            List <Opgave> mineOpgaver = HentAlleOpgaver();

            foreach (var op in mineOpgaver)
            {
                Console.WriteLine(op);
            }

            Console.ReadKey();
            Console.Clear();

            //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            //Hent en Opgave (test)
            Console.WriteLine("Test af hentning af specifikke opgaver (1 og 3)");
            Console.WriteLine("");

            Console.WriteLine(HentOpgaveFraId(1));
            Console.WriteLine(HentOpgaveFraId(3));

            Console.ReadKey();
            Console.Clear();

            //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            //Indsæt en Opgave (test)
            Console.WriteLine("Test af indsætning af opgave");
            Console.WriteLine("");

            Opgave OP = new Opgave(10, "test", StatusType.IkkeLøst, 1, HentUdstyrFraId(3));

            IndsætOpgave(OP);

            Console.WriteLine(HentOpgaveFraId(10));

            Console.ReadKey();
            Console.Clear();

            //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            //Opdater Opgave (test)
            Console.WriteLine("Test af opdatering af opgave");
            Console.WriteLine("");

            Opgave NewOP = new Opgave(10, "test2", StatusType.Løst, 2, HentUdstyrFraId(1));

            OpdaterOpgave(NewOP, 10);

            Console.WriteLine(HentOpgaveFraId(10));

            Console.ReadKey();
            Console.Clear();

            //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            //Slet Opgave (Test)
            Console.WriteLine("Test af sletning af opgave");
            Console.WriteLine("");

            SletOpgave(10);

            List <Opgave> mineOpgaverNy = HentAlleOpgaver();

            foreach (var op in mineOpgaverNy)
            {
                Console.WriteLine(op);
            }

            //Code above this line---------------------------------------------------------------------------------------------------
        }
        //
        public void Test()
        {
            Console.WriteLine("Test af REST service");
            //---------------------------------------(Test af HentAlleOpgaver())
            Console.WriteLine("Test af hentning af alle opgaver");
            Console.WriteLine("Her bør være en komplet liste af alle nuværende opgaver.");
            Console.WriteLine("");

            List <Opgave> opgaveListe = HentAlleOpgaver();

            foreach (var o in opgaveListe) //<=== udskriver opgaven hentet fra Databasen.
            {
                Console.WriteLine(o);
            }

            Console.WriteLine("");
            Console.ReadKey();

            //---------------------------------------(test af HentEnOpgave())
            Console.Clear();
            Console.WriteLine("Test af hentning af en enkelt opgave (Opgave 1).");
            Console.WriteLine("Her bør være opgave 1.");
            Console.WriteLine("");

            Console.WriteLine(HentEnOpgave(1));

            Console.WriteLine("");
            Console.ReadKey();
            //---------------------------------------(test af IndsætOpgave())
            Console.Clear();
            Console.WriteLine("Test af indsætning af en opgave (Opgave 10).");
            Console.WriteLine("Her indsættets en ny opgave, opgave 10, som så bliver vist bagefter.");
            Console.WriteLine("");
            Opgave testOpgave10 = new Opgave(10, "en testopgave", StatusType.IkkeLøst, 2, HentUdstyrFraId(2));

            IndsætOpgave(testOpgave10);

            Console.WriteLine(HentEnOpgave(10));

            Console.WriteLine("");
            Console.ReadKey();

            //---------------------------------------(Test af OpdaterOpgave())
            Console.Clear();
            Console.WriteLine("Test af opdatering af en opgave (Opgave 10).");
            Console.WriteLine("Her ser vi den nuværende opgave 10, som så bliver opdateret og skrevet ud igen.");
            Console.WriteLine("");
            testOpgave10 = new Opgave(10, "Test af opdatering", StatusType.IkkeLøst, 5, HentUdstyrFraId(3));

            Console.WriteLine("Nuværende:\n" + HentEnOpgave(10));

            OpdaterEnOpgave(10, testOpgave10);

            Console.WriteLine("Opdateret:\n" + HentEnOpgave(10));

            Console.WriteLine("");
            Console.ReadKey();

            //---------------------------------------(test af SletOpgave())
            Console.Clear();
            Console.WriteLine("Test af sletning af en opgave (Opgave 10).");
            Console.WriteLine("Her slettes opgave 10 og hele listen bliver så vist bagefter.");
            Console.WriteLine("");

            SletOpgave(10);

            foreach (var o in HentAlleOpgaver())
            {
                Console.WriteLine(o);
            }

            Console.WriteLine("");
            Console.ReadKey();

            //---------------------------------------
        }
 // PUT: api/Opgave/5
 public bool Put(int id, [FromBody] Opgave value)
 {
     return(manager.OpdaterOpgave(value, id));
 }
 // POST: api/Opgave/
 public bool Post([FromBody] Opgave value)
 {
     return(manager.IndsætOpgave(value));
 }