Example #1
0
        public IHttpActionResult UpdateEmployee(Employee_tb updatedata)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                Employee_tb objEmp = new Employee_tb();
                objEmp = db.Employee_tb.Find(updatedata.empno);
                if (objEmp != null)
                {
                    objEmp.empname  = updatedata.empname;
                    objEmp.jobrole  = updatedata.jobrole;
                    objEmp.location = updatedata.location;
                }
                int i = this.db.SaveChanges();
            }
            catch (Exception)
            {
                throw;
            }

            return(Ok(updatedata));
        }
Example #2
0
        public IHttpActionResult DeleteEmployee(int id)
        {
            Employee_tb deleteEmp = db.Employee_tb.Find(id);

            if (deleteEmp == null)
            {
                return(NotFound());
            }

            db.Employee_tb.Remove(deleteEmp);
            db.SaveChanges();

            return(Ok(deleteEmp));
        }
Example #3
0
        public IHttpActionResult InsertEmployee(Employee_tb data)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                db.Employee_tb.Add(data);
                db.SaveChanges();
            }
            catch (Exception)
            {
                throw;
            }
            return(Ok(data));
        }