Esempio n. 1
0
        public IHttpActionResult Delete(string id)
        {
            try
            {
                CallViewModel call = new CallViewModel();
                call.Id = id;
                long delRetCall = call.Delete();

                switch (delRetCall)
                {
                case 1:
                    return(Ok("Ok! Call has been deleted!"));

                case 2:
                    return(Ok("Error! Call does not Exist!"));

                default:
                    return(Ok("Call not Deleted!"));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest("Update Failed - Contact Tech Support"));
            }
        }
Esempio n. 2
0
        public IHttpActionResult Delete(CallViewModel call)
        {
            try
            {
                long retVal = call.Delete();
                switch (retVal)
                {
                case 1:
                    return(Ok("Call " + call.Notes + " Deleted!"));

                case -1:
                    return(Ok("Call " + call.Notes + " not deleted!"));

                case -2:
                    return(Ok("Data is stale for " + call.Notes + ", Call already deleted!"));

                default:
                    return(Ok("Call " + call.Notes + " not deleted!"));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest("Retrieve failed - " + ex.Message));
            }
        }
Esempio n. 3
0
        // 'DELETE' method to remove and employee from the database
        public IHttpActionResult Delete(int id)
        {
            try
            {
                // Create and EmployeeViewModel object to store the employee data
                CallViewModel call = new CallViewModel();

                // The EmployeeViewModel Object ID is that of the ID past into the methods parameters
                // when called in the JavaScript
                call.Id = id;

                // If the number of employees deleted equals 1 then display the message that it was successful
                // else display a message that it was unsuccessful
                if (call.Delete() == 1)
                {
                    return(Ok("Call " + call.Id + " deleted!"));
                }
                else
                {
                    return(Ok("Call " + call.Id + " not deleted!"));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest("Delete failed - Contact Tech Support"));
            }
        }
Esempio n. 4
0
        public void ComprehensiveVMTests()
        {
            CallViewModel     cvm = new CallViewModel();
            EmployeeViewModel evm = new EmployeeViewModel();
            ProblemViewModel  pvm = new ProblemViewModel();

            cvm.DateOpened = DateTime.Now;
            cvm.DateClosed = null;
            cvm.OpenStatus = true;
            evm.Lastname   = "Jarocki";
            evm.GetByLastname();
            cvm.EmployeeId = evm.Id;
            evm.Lastname   = "Burner";
            evm.GetByLastname();
            cvm.TechId      = evm.Id;
            pvm.Description = "Memory Upgrade";

            pvm.GetByDescription();
            cvm.ProblemId = pvm.Id;
            cvm.Notes     = "Kevin has bad RAM, Burner to fix it";
            cvm.Add();
            Console.WriteLine("New Call Generated - Id = " + cvm.Id);
            int id = cvm.Id;     //need id for delete later

            cvm.GetById();
            cvm.Notes += "\n Ordered new RAM!";

            if (cvm.Update() == 1)
            {
                Console.WriteLine("Call was updated " + cvm.Notes);
            }
            else
            {
                Console.WriteLine("Call was not updated!");
            }

            cvm.Notes = "Another change to comments that should not work";
            if (cvm.Update() == -2)
            {
                Console.WriteLine("Call was not updated data was stale");
            }

            cvm    = new CallViewModel();
            cvm.Id = id;
            cvm.GetById();

            if (cvm.Delete() == 1)
            {
                Console.WriteLine("Call was deleted!");
            }
            else
            {
                Console.WriteLine("Call was not deleted");
            }

            cvm.GetById();
        }
        public void ComprehensiveVMTests()
        {
            CallViewModel     cvm = new CallViewModel();
            EmployeeViewModel evm = new EmployeeViewModel();
            ProblemViewModel  pvm = new ProblemViewModel();

            cvm.DateOpened = DateTime.Now;
            cvm.DateClosed = null;
            cvm.OpenStatus = true;
            evm.Lastname   = "Pollock";
            evm.GetByLastname();
            cvm.EmployeeId = evm.Id;
            evm.Lastname   = "Burner";
            evm.GetByLastname();
            cvm.TechId      = evm.Id;
            pvm.Description = "Memory Upgrade";
            pvm.GetByDescription();
            cvm.ProblemId = pvm.Id;
            cvm.Notes     = "Chris has bad RAM, Burner to fix it";
            cvm.Add();
            Console.WriteLine("New Call Generated - Id = " + cvm.Id);
            int id = cvm.Id; // need Id for delete later

            cvm.GetById();
            cvm.Notes += "\n Ordered new RAM!";

            if (cvm.Update() == 1)
            {
                Console.WriteLine("Call was updated " + cvm.Notes);
            }
            else
            {
                Console.WriteLine("Call was NOT updated!");
            }

            cvm.Notes = "Another change to comments that should not work.";
            if (cvm.Update() == -2)
            {
                Console.WriteLine("Call was NOT updated, data was stale.");
            }

            cvm    = new CallViewModel(); // need to reset because of Concurrency
            cvm.Id = id;
            cvm.GetById();

            if (cvm.Delete() == 1)
            {
                Console.WriteLine("Call was deleted!");
            }
            else
            {
                Console.WriteLine("Call was NOT deleted!");
            }

            cvm.GetById(); // should throw expected exception
        }
Esempio n. 6
0
        public void Call_ComprehensiveVMTest()
        {
            CallViewModel     cvm = new CallViewModel();
            EmployeeViewModel evm = new EmployeeViewModel();
            ProblemViewModel  pvm = new ProblemViewModel();

            cvm.DateOpened = DateTime.Now;
            cvm.DateClosed = null;
            cvm.OpenStatus = true;
            evm.Email      = "*****@*****.**";
            evm.GetByEmail();
            cvm.EmployeeId = evm.Id;
            evm.Lastname   = "*****@*****.**";
            evm.GetByEmail();
            cvm.EmployeeName = evm.Lastname;
            cvm.TechId       = evm.Id;
            pvm.Description  = "Memory Upgrade";
            pvm.GetByDescription();
            cvm.ProblemId = pvm.Id;
            cvm.Notes     = "Sonia has bad RAM, Burner to fix it";
            cvm.Add();
            output.WriteLine("New Call Generated - Id = " + cvm.Id);
            int id = cvm.Id;

            cvm.GetById();
            cvm.Notes += "\n Ordered new RAM!";
            if (cvm.Update() == 1)
            {
                output.WriteLine("Call was updated " + cvm.Notes);
            }
            else
            {
                output.WriteLine("Call was not updated!");
            }
            cvm.Notes = "Another change to comments that should not work";
            if (cvm.Update() == -2)
            {
                output.WriteLine("Call was not updated data was stale");
            }
            cvm    = new CallViewModel();// need to reset because of concureency error
            cvm.Id = id;
            cvm.GetById();

            if (cvm.Delete() == 1)
            {
                output.WriteLine("Call was deleted");
            }
            else
            {
                output.WriteLine("Call was not deleted");
            }
            Exception ex = Assert.Throws <NullReferenceException>(() => cvm.GetById()); // should throw expected exception

            Assert.Equal("Object reference not set to an instance of an object.", ex.Message);
        }
Esempio n. 7
0
        public void ComprehensiveVMTestsShouldReturnTrue()
        {
            CallViewModel     cvm = new CallViewModel();
            EmployeeViewModel evm = new EmployeeViewModel();
            ProblemViewModel  pvm = new ProblemViewModel();

            cvm.DateOpened = DateTime.Now;
            cvm.DateClosed = null;
            cvm.OpenStatus = true;
            evm.Lastname   = "Smartypants";
            evm.GetByLastname();
            cvm.EmployeeId = evm.Id;
            evm.Lastname   = "Burner";
            evm.GetByLastname();
            cvm.TechId      = evm.Id;
            pvm.Description = "Memory Upgrade";
            pvm.GetByProblemDescription();
            cvm.ProblemId = pvm.Id;
            cvm.Notes     = "Bigshot has bad RAM, Burner to fix it";
            cvm.Version   = 1;
            cvm.Create();
            this.tstCtx.WriteLine("New Call Generated - Id = " + cvm.Id);
            cvm.GetById();
            this.tstCtx.WriteLine("New Call Retrieved");
            cvm.Notes = "\n Ordered new RAM!";

            if (cvm.Update() == 1)
            {
                this.tstCtx.WriteLine("Call was updated " + cvm.Notes);
            }
            else
            {
                this.tstCtx.WriteLine("Call was not updated");
            }

            if (cvm.Update() == -2)
            {
                this.tstCtx.WriteLine("Call was not updated data was stale");
            }

            if (cvm.Delete() == 1)
            {
                this.tstCtx.WriteLine("Call was deleted");
            }
            else
            {
                this.tstCtx.WriteLine("Call was not deleted");
            }

            cvm.GetById(); // should throw expected exception
        }
Esempio n. 8
0
 public IHttpActionResult Delete(string Id)
 {
     try
     {
         CallViewModel call = new CallViewModel();
         call.Id = Id;
         call.GetByID(Id);
         call.Delete();
         return(Ok("Call deleted!"));
     }
     catch (Exception ex)
     {
         return(BadRequest("Update failed - " + ex.Message));
     }
 }
 public IActionResult Delete(int id)
 {
     try
     {
         CallViewModel viewModel = new CallViewModel();
         viewModel.Id = id;
         return(viewModel.Delete() == 1
             ? Ok(new { msg = "Call " + id + " deleted!" })
             : Ok(new { msg = "Call " + id + " not deleted!" }));
     }
     catch (Exception ex)
     {
         _logger.LogError("Problem in " + GetType().Name + " " +
                          MethodBase.GetCurrentMethod().Name + " " + ex.Message);
         return(StatusCode(StatusCodes.Status500InternalServerError));
     }
 }
Esempio n. 10
0
 public IHttpActionResult Delete(int id)
 {
     try
     {
         CallViewModel call = new CallViewModel();
         call.Id = id;
         if (call.Delete() == 1)
         {
             return(Ok("Call " + id + " deleted!"));
         }
         else
         {
             return(Ok("Call not deleted!"));
         }
     }
     catch (Exception e)
     {
         return(BadRequest("Delete failed- Contact Tech Support"));
     }
 }
        public IHttpActionResult Delete(int id)
        {
            try
            {
                CallViewModel call = new CallViewModel();
                call.Id = id;

                //Use the EmployeeViewModel's delete method and check the return to see if the delete was successful
                if (call.Delete() == 1)
                {
                    return(Ok("Call deleted!"));
                }
                else
                {
                    return(Ok("Call not deleted!"));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest("Delete failed - Contact Tech Support"));
            }
        }
Esempio n. 12
0
        public void CallViewModelComprehensiveTestsReturnTrue()
        {
            CallViewModel vm = new CallViewModel();

            vm.DateOpened = DateTime.Now;
            vm.OpenStatus = true;
            vm.EmployeeId = "56464e723dd4df30e88b8b8c"; // Bigshot
            vm.TechId     = "56464e723dd4df30e88b8b92"; //Burner
            vm.ProblemId  = "56464e723dd4df30e88b8b99";
            vm.Notes      = "Bigshot has bad RAM, Burner to fix it";
            vm.Create();
            this.testContextInstance.WriteLine("New Call Id == " + vm.Id);
            vm.GetByID(vm.Id);
            this.testContextInstance.WriteLine("Call retrieved");
            vm.Notes = vm.Notes + "\nOrdered new Ram";

            if (vm.Update() == 1)
            {
                this.testContextInstance.WriteLine("Call was updated " + vm.Notes);
            }
            else
            {
                Trace.WriteLine("Call was not updated");
            }

            if (vm.Delete())
            {
                this.testContextInstance.WriteLine("Call was deleted");
            }
            else
            {
                this.testContextInstance.WriteLine("Call was not deleted");
            }

            vm.Update(); //should throw MongoException see attribute
        }