コード例 #1
0
 // Delete employee By Id
 public HttpResponseMessage Delete(int id)
 {
     using (dbEntities db = new dbEntities())
     {
         List <sp_InsUpdDelEmployee_Result> emplist = new List <sp_InsUpdDelEmployee_Result>();
         var results = db.sp_InsUpdDelEmployee(id, "", "", "", "", "", "GetById").ToList();
         if (results.Count == 0)
         {
             return(Request.CreateResponse(HttpStatusCode.NotFound));
         }
         try
         {
             emplist = db.sp_InsUpdDelEmployee(id, "", "", "", "", "", "Del").ToList();
         }
         catch (DbUpdateConcurrencyException ex)
         {
             return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex));
         }
         return(Request.CreateResponse(HttpStatusCode.OK, emplist));
     }
 }
コード例 #2
0
 // Insert Employee
 public HttpResponseMessage Post(Employee employee)
 {
     if (ModelState.IsValid)
     {
         using (dbEntities db = new dbEntities())
         {
             var emplist = db.sp_InsUpdDelEmployee(0, employee.Name, employee.Address, employee.Country, employee.City, employee.Mobile, "Ins").ToList();
             HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, emplist);
             return(response);
         }
     }
     else
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
     }
 }
コード例 #3
0
        // Update Employee
        public HttpResponseMessage Put(Employee employee)
        {
            List <sp_InsUpdDelEmployee_Result> emplist = new List <sp_InsUpdDelEmployee_Result>();

            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }
            using (dbEntities db = new dbEntities())
            {
                try
                {
                    emplist = db.sp_InsUpdDelEmployee(employee.Id, employee.Name, employee.Address, employee.Country, employee.City, employee.Mobile, "Upd").ToList();
                }
                catch (DbUpdateConcurrencyException ex)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex));
                }
            }
            return(Request.CreateResponse(HttpStatusCode.OK, emplist));
        }
コード例 #4
0
        public List <Employee> Get()
        {
            List <Employee> emplist = new List <Employee>();

            using (dbEntities db = new dbEntities())
            {
                var results = db.sp_InsUpdDelEmployee(0, "", "", "", "", "", "Get").ToList();
                foreach (var result in results)
                {
                    var employee = new Employee()
                    {
                        Id      = result.Id,
                        Name    = result.Name,
                        Address = result.Address,
                        Country = result.Country,
                        City    = result.City,
                        Mobile  = result.Mobile
                    };
                    emplist.Add(employee);
                }
                return(emplist);
            }
        }