Пример #1
0
 public IHttpActionResult Put(EmployeeViewModel emp)
 {
     try
     {
         if (emp.Update() == 1)
         {
             return Ok("Employee " + emp.Lastname + " updated.");
         }
         else if (emp.Update() == -1)
         {
             return Ok("Employee " + emp.Lastname + " not updated!");
         }
         else if (emp.Update() == -2)
         {
             return Ok("Employee " + emp.Lastname + " not updated due to stale data.");
         }
         else
         {
             return Ok("Update Failed");
         }
     }
     catch (Exception ex)
     {
         return BadRequest("Update Failed - " + ex.Message);
     }
 }
 public IHttpActionResult Put(EmployeeViewModel emp)
 {
     try
     {
         int errorNumber = emp.Update();
         switch (errorNumber)
         {
             case 1:
                 return Ok("Employee " + emp.Lastname + " updated!");
                 break;
             case -1:
                 return Ok("Employee" + emp.Lastname + " not updated!");
                 break;
             case -2:
                 return Ok("Data is stale for " + emp.Lastname + ". Employee not updated!");
                 break;
             default:
                 return Ok("Employee" + emp.Lastname + " not updated!");
                 break;
         }
     }
     catch (Exception ex)
     {
         return BadRequest("Update failed - " + ex.Message);
     }
 }
        public void EmployeeVMUpdateShouldReturnTrue()
        {
            EmployeeViewModel vm = new EmployeeViewModel();
            vm.GetById("56201963f748f2338c59a8c7"); // Smartypants id
            vm.Phoneno = "555-555-5551";
            int rowsUpdated = vm.Update();

            Assert.IsTrue(rowsUpdated == 1);
        }
 public IHttpActionResult Post(EmployeeViewModel emp)
 {
     try
     {
         emp.Create();
         return Ok("Employee " + emp.Lastname + " Created");
     } catch (Exception ex)
     {
         return BadRequest("Update failed - " + ex.Message);
     }
 }
Пример #5
0
 public IHttpActionResult Post(EmployeeViewModel emp)
 {
     try
     {
         emp.Create();
         return Ok(emp);
     }
     catch(Exception e)
     {
         return BadRequest("Create failed - " + e.Message);
     }
 }
 public IHttpActionResult Get()
 {
     try
     {
         EmployeeViewModel emp = new EmployeeViewModel();
         List<EmployeeViewModel> allEmployees = emp.GetAll();
         return Ok(allEmployees);
     } catch (Exception ex)
     {
         return BadRequest("Retrive failed - " + ex.Message);
     }
 }
 public IHttpActionResult Get(string id)
 {
     try
     {
         EmployeeViewModel emp = new EmployeeViewModel();
         emp.GetById(id);
         return Ok(emp);
     }
     catch (Exception ex)
     {
         return BadRequest("Retrive failed - " + ex.Message);
     }
 }
Пример #8
0
 public IHttpActionResult Delete(string empId)
 {
     try
     {
         EmployeeViewModel emp = new EmployeeViewModel();
         emp.GetById(empId);
         emp.Delete();
         return Ok(emp.Lastname + " has been deleted");
     }
     catch (Exception e)
     {
         return BadRequest("Delete failed - " + e.Message);
     }
 }
        public void EmployeeVMUpdateTwiceShouldReturnNegative2()
        {
            EmployeeViewModel vm1 = new EmployeeViewModel();
            EmployeeViewModel vm2 = new EmployeeViewModel();

            vm1.GetById("56201963f748f2338c59a8c7"); // Smartypants Id
            vm2.GetById("56201963f748f2338c59a8c7");

            vm1.Phoneno = "555-555-5551";
            int rowsUpdated = vm1.Update();

            if (rowsUpdated == 1)
                rowsUpdated = vm2.Update();

            Assert.IsTrue(rowsUpdated == -2);
        }
 public IHttpActionResult Delete(string id)
 {
     try
     {
         EmployeeViewModel emp = new EmployeeViewModel();
         emp.GetById(id);
         if (emp.Delete())
             return Ok("Employee Deleted");
         else
             return BadRequest("Could not delete");
     }
     catch (Exception ex)
     {
         return BadRequest("Retrive failed - " + ex.Message);
     }
 }
        public void EmployeeVMCreateAndDeleteShouldReturnTrue()
        {
            bool deleteOK = false;
            EmployeeViewModel vm = new EmployeeViewModel();

            vm.DepartmentId = "56201963f748f2338c59a8c3"; // Sales Id
            vm.Email = "*****@*****.**";
            vm.Firstname = "Some";
            vm.Lastname = "Employee";
            vm.Phoneno = "(555)555-5555";
            vm.Title = "Mr.";
            vm.Create();

            if (vm.Id.Length == 24)
                deleteOK = vm.Delete();
            Assert.IsTrue(deleteOK);
        }
Пример #12
0
 public List<EmployeeViewModel> GetAll()
 {
     List<EmployeeViewModel> viewModels = new List<EmployeeViewModel>();
     try
     {
         List<Employee> employees = _dao.GetAll();
         foreach (Employee e in employees)
         {
             // return only fields for display, subsequent get will other fields
             EmployeeViewModel viewModel = new EmployeeViewModel();
             viewModel.EmployeeId = e._id.ToString();
             viewModel.Title = e.Title;
             viewModel.Firstname = e.Firstname;
             viewModel.Lastname = e.Lastname;
             viewModels.Add(viewModel); // add to list
         }
     }
     catch (Exception e)
     {
         ViewModelUtils.ErrorRoutine(e, "EmployeeViewModel", "GetAll");
     }
     return viewModels;
 }
 public void EmployeeVMGetAllShouldReturnList()
 {
     EmployeeViewModel vm = new EmployeeViewModel();
     List<EmployeeViewModel> emps = vm.GetAll();
     Assert.IsTrue(emps.Count > 0);
 }