コード例 #1
0
 // DELETE api/employees/7
 public HttpResponseMessage Delete(int id)
 {
     var emp = new Employee { EmployeeId = id };
       _db.Employees.Attach(emp);
       var status = _db.Employees.Remove(emp);
       _db.SaveChanges();
       if (status != null) return new HttpResponseMessage(HttpStatusCode.OK);
       throw new HttpResponseException(HttpStatusCode.NotFound);
 }
コード例 #2
0
 public ActionResult SaveEmployee(CreateEmployeeViewModel cvm)
 {
     Employee emp = new Employee();
     emp.EmployeeFirstName = cvm.FirstName;
     emp.EmployeeLastName = cvm.LastName;
     emp.EmployeeSalary = Convert.ToDouble( cvm.Salary);
     if (ModelState.IsValid)
     {
         EmployeeBusinessLayer ebl = new EmployeeBusinessLayer();
         ebl.AddEmployee(emp);
         return RedirectToAction("Index");
     }
     else
     {
         CreateEmployeeViewModel cvmms = new CreateEmployeeViewModel();
         //cvmms.FooterData = new FooterViewModel();
         //cvmms.FooterData.CompanyName = "Step By Step Schools";
         //cvmms.FooterData.Year = DateTime.Now.Year.ToString(); ;
         cvmms.FirstName = cvm.FirstName;
         cvmms.LastName = cvm.LastName;
         cvmms.Salary = cvm.Salary;
         return View("CreateEmployee",cvm);
     }
 }
コード例 #3
0
 public void AddEmployee(Employee e)
 {
     MyEmpDb addemp = new MyEmpDb();
     addemp.employees.Add(e);
     addemp.SaveChanges();
 }
コード例 #4
0
 // POST api/employees
 public HttpResponseMessage Post([FromBody] EmployeeModel value)
 {
     var employee = new Employee
      {
         FirstName = value.FirstName,
         LastName = value.LastName,
         ImageSource = value.ImageSource,
         Remarks = value.Remarks,
         LastInitial=value.LastInitial,
         PhoneNumber=value.PhoneNumber,
         AlternatePhoneNumber=value.AlternatePhoneNumber,
         Address=value.Address,
         Title=value.Title,
         Gender=value.Gender
      };
       var emp=_db.Employees.Add(employee);
       _db.SaveChanges();
       if (emp != null)
       {
      var msg = new HttpResponseMessage(HttpStatusCode.Created);
      msg.Headers.Location = new Uri(Request.RequestUri + "/" + employee.EmployeeId.ToString());
      return msg;
       }
       else
       {
     var msg = new HttpResponseMessage(HttpStatusCode.BadRequest);
     return msg;
       }
 }