Esempio n. 1
0
 public HttpResponseMessage PUT(EmployeeProfile empProfile)
 {
     if (ModelState.IsValid)
     {
         HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, objEmp.AddEditEmploy(empProfile));
         return(response);
     }
     else
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
     }
 }
        public EmployeeProfile AddEditEmploy(EmployeeProfile empProfile)
        {
            EmplyeeDBEntities DBContext = new EmplyeeDBEntities();
            var employ = DBContext.EmployeeProfiles.Where(emp => emp.EmpNo == empProfile.EmpNo).FirstOrDefault();

            if (employ != null)
            {
                employ.Name     = empProfile.Name;
                employ.PhoneNo  = empProfile.PhoneNo;
                employ.Email    = empProfile.Email;
                employ.Gender   = empProfile.Gender;
                employ.Position = empProfile.Position;
                employ.DOB      = empProfile.DOB;
                employ.Salary   = empProfile.Salary;

                DBContext.SaveChanges();
            }
            else
            {
                var newEmploy = new EmployeeProfile
                {
                    EmpNo    = empProfile.EmpNo,
                    Name     = empProfile.Name,
                    PhoneNo  = empProfile.PhoneNo,
                    Email    = empProfile.Email,
                    Gender   = empProfile.Gender,
                    Position = empProfile.Position,
                    DOB      = empProfile.DOB,
                    Salary   = empProfile.Salary,
                };

                DBContext.EmployeeProfiles.Add(newEmploy);
                DBContext.SaveChanges();
            }

            var empDeails = DBContext.EmployeeProfiles.Where(emp => emp.EmpNo == empProfile.EmpNo).FirstOrDefault();

            return(empDeails);
        }