public HttpResponseMessage PutEmployee(int id, ApiEmployee Employee) { if (Employee == null) { throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Incorrect form data.")); } if (GetEmployee(id) == null) { throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, string.Format("Employee {0}, does not exist.", id))); } try { if (_repository.GetAll(id.ToString()).Count() == 0) { throw new Exception("Employee does not exist in the system."); } _repository.Update(Employee, id); var response = Request.CreateResponse <ApiEmployee>(HttpStatusCode.OK, Employee); string uri = Url.Link("ApiEmployee", new { id = Employee.id }); response.Headers.Location = new Uri(uri); return(response); } catch (Exception ex) { throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message)); } }
public HttpResponseMessage DeleteEmployee(int id) { ApiEmployee employee = _repository.Get(id); _repository.Remove(id); var response = Request.CreateResponse <ApiEmployee>(HttpStatusCode.OK, employee); return(response); }
public void Get_EmptyIDParameter_ExpectedObjectnotNUll() { IRepository <ApiEmployee> _repository = FactoryClass.MakeEmployeeRepository(); List <ApiEmployee> allEmployee = _repository.GetAll().ToList(); int id = allEmployee.FirstOrDefault().id; ApiEmployee employee = _repository.Get(id); Assert.IsTrue(employee != null); }
static public Employee AsEmployee(this ApiEmployee src) { Employee dest = new Employee(); var sourceType = src.GetType(); var targetType = dest.GetType(); var propMap = GetMatchingProperties(sourceType, targetType); for (var i = 0; i < propMap.Count; i++) { var prop = propMap[i]; var sourceValue = prop.SourceProperty.GetValue(src, null); prop.TargetProperty.SetValue(dest, sourceValue, null); } return(dest); }
public HttpResponseMessage PutEmployee(int id, ApiEmployee Employee) { if (Employee == null) { throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Incorrect form data.")); } try { _repository.Update(Employee); var response = Request.CreateResponse <ApiEmployee>(HttpStatusCode.OK, Employee); return(response); } catch (Exception ex) { throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message)); } }
public void Add_ApiEmployeeAsParameter_ExpectedInsertedRow() { ApiEmployee item = new ApiEmployee(); item.aditional_info = "additional info from UnitTest"; item.aditional_service = "additional service from UnitTest"; item.another_building = "CheckAlt Building"; item.another_company = "CheckAlt Company"; item.cellphone = "777-777-7777"; item.email = "*****@*****.**"; item.fk_buildingaccess = 1; item.fk_companylist = 1; item.fk_hiredfor = 1; item.fullName = "Unit Test Phase 2"; item.hiringManagerEmail = "*****@*****.**"; item.initiationDate = DateTime.Now; item.restricted_access = ""; item.service_equipmentneeded = "Laptop"; item.startDate = DateTime.Now; IRepository <ApiEmployee> _repository = FactoryClass.MakeEmployeeRepository(); ApiEmployee employeerow = _repository.Add(item); Assert.IsTrue(employeerow.email == "*****@*****.**" && employeerow.service_equipmentneeded == "Laptop"); }