Beispiel #1
0
        public void GetEmployeeByID()
        {
            ProxyImplementation service  = new ProxyImplementation();
            ProxyEmployee       employee = service.GetEmployeeByID(1);

            Xunit.Assert.NotNull(employee);
            Xunit.Assert.True(employee.Id == 1);
        }
Beispiel #2
0
 public HttpResponseMessage CreateEmployee([FromBody] ProxyEmployee employee)
 {
     if (employee != null)
     {
         MyProxyService.CreateEmployee(employee);
         return(Request.CreateResponse <ProxyEmployee>(HttpStatusCode.Created, employee));
     }
     else
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "The employee is null"));
     }
 }
Beispiel #3
0
 public HttpResponseMessage CreateOrUpdateEmployee([FromBody] ProxyEmployee employee)
 {
     if (employee != null)
     {
         MyProxyService.CreateOrUpdate(employee);
         return(Request.CreateResponse(HttpStatusCode.OK, employee));
     }
     else
     {
         return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Employee Not Found"));
     }
 }
Beispiel #4
0
        public HttpResponseMessage GetEmployeeByID(int id)
        {
            ProxyEmployee pe = MyProxyService.GetEmployeeByID(id);

            if (pe != null)
            {
                return(Request.CreateResponse <ProxyEmployee>(HttpStatusCode.OK, pe));
            }
            else
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Employee Not Found"));
            }
        }
Beispiel #5
0
        public HttpResponseMessage UpdateEmployee([FromUri] int id, [FromBody] ProxyEmployee employee)
        {
            //kalw thn get id na dw an yparxei
            ProxyEmployee proxy = MyProxyService.GetEmployeeByID(id);

            if (proxy != null && employee != null)
            {
                MyProxyService.UpdateEmployee(id, employee);
                return(Request.CreateResponse <ProxyEmployee>(HttpStatusCode.OK, employee));
            }
            else
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Employee Not Found"));
            }
        }
Beispiel #6
0
        public HttpResponseMessage DeleteEmployee([FromUri] int id)
        {
            //ProxyEmployee proxy = MyProxyService.GetEmployeeByID(id);
            //deyteros tropos elegxoy
            ProxyEmployee request = MyProxyService.GetEmployees().Where(x => x.Id == id).FirstOrDefault();

            if (request != null)
            {
                MyProxyService.DeleteEmployee(id);
                return(Request.CreateResponse(HttpStatusCode.OK, "Employee Succesfull Deleted"));
            }
            else
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Employee Not Found"));
            }
        }
        public void CreateOrUpdate(ProxyEmployee employee)
        {
            var client  = new RestClient("http://localhost:50428/");
            var request = new RestRequest("api/employee/createorupdate", Method.POST);

            request.RequestFormat = DataFormat.Json;
            request.AddBody(new ProxyEmployee
            {
                Id       = employee.Id,
                Name     = employee.Name,
                Salary   = employee.Salary,
                Job      = employee.Job,
                Birthday = employee.Birthday
            });
            client.Post(request);
        }
Beispiel #8
0
        public void UpdateEmployee()
        {
            ProxyImplementation service  = new ProxyImplementation();
            ProxyEmployee       employee = new ProxyEmployee()
            {
                Id       = 1054,
                Name     = "Dimitris Kosmas",
                Salary   = 130000,
                Birthday = new DateTime(1998, 04, 30, 13, 14, 19),
                Job      = ".net developer"
            };

            service.UpdateEmployee(1054, employee);
            List <ProxyEmployee> proxylist = service.GetEmployees();

            Xunit.Assert.True(proxylist.Exists(x => x.Id == 1054 && x.Name == "Dimitris Kosmas" && x.Salary == 130000 && x.Id == 1054));
        }
        public void UpdateEmployee(int employeeid, ProxyEmployee employee)
        {
            var client  = new RestClient("http://localhost:50428/");
            var request = new RestRequest("api/employee/updateEmployee/" + employeeid, Method.PUT);

            //request.RequestFormat = DataFormat.Json;
            request.AddJsonBody(employee);
            //request.AddBody(new ProxyEmployee
            //{
            //    Id = employee.Id,
            //    Name = employee.Name,
            //    Salary = employee.Salary,
            //    Job = employee.Job,
            //    Birthday = employee.Birthday

            //});
            client.Put(request);
        }
Beispiel #10
0
        public void CreateEmployee()
        {
            ProxyImplementation service = new ProxyImplementation();

            ProxyEmployee employee = new ProxyEmployee()
            {
                Id       = 1041,
                Name     = "Dimitris K. Kosmas",
                Salary   = 25000,
                Birthday = new DateTime(1998, 04, 30, 13, 14, 19),
                Job      = "ProxyEmployee"
            };

            service.CreateEmployee(employee);
            List <ProxyEmployee> proxylist = service.GetEmployees();

            Xunit.Assert.True(proxylist.Exists(x => x.Name == "Dimitris K. Kosmas" && x.Salary == 25000));
        }