Esempio n. 1
0
 public Emp Get(int id)
 {
     using (EmpDataEntities entities = new EmpDataEntities())
     {
         return(entities.Emps.FirstOrDefault(e => e.ID == id));
     }
 }
Esempio n. 2
0
 public IEnumerable <Emp> Get()
 {
     using (EmpDataEntities entities = new EmpDataEntities())
     {
         return(entities.Emps.ToList());
     }
 }
Esempio n. 3
0
        // GET: Employee
        public ActionResult Index()
        {
            //Model is the list<EmpTable>
            var com  = new EmpDataEntities();  //The Auto Generated class for accessing data
            var data = com.EmpTables.ToList(); //All the dta is converted to List<EmpTable>

            return(View(data));
        }
Esempio n. 4
0
        public ActionResult Edit(string id)
        {
            int empId      = int.Parse(id);
            var com        = new EmpDataEntities();
            var foundedEmp = com.EmpTables.FirstOrDefault(e => e.EmpID == empId);

            if (foundedEmp != null)
            {
                return(View(foundedEmp));
            }
            else
            {
                throw new Exception("No Employee found to edit");
            }
        }
Esempio n. 5
0
        public ActionResult Edit(EmpTable postedEmp)
        {
            //get the Entity FM
            var com = new EmpDataEntities();
            //Find UR EMployee
            var emp = com.EmpTables.FirstOrDefault(e => e.EmpID == postedEmp.EmpID);

            if (emp == null)
            {
                throw new Exception("Employee not found");
            }
            //SEt the new details
            emp.EmpName    = postedEmp.EmpName;
            emp.EmpAddress = postedEmp.EmpAddress;
            emp.EmpSalary  = postedEmp.EmpSalary;
            com.SaveChanges();
            //update
            return(RedirectToAction("Index"));
        }
Esempio n. 6
0
        public HttpResponseMessage Post([FromBody] Emp emp)
        {
            try
            {
                using (EmpDataEntities entities = new EmpDataEntities())
                {
                    entities.Emps.Add(emp);
                    entities.SaveChanges();

                    var msg = Request.CreateResponse(HttpStatusCode.Created, emp);
                    msg.Headers.Location = new Uri(Request.RequestUri + emp.ID.ToString());
                    return(msg);
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
        }
Esempio n. 7
0
 public HttpResponseMessage Delete(int id)
 {
     try
     {
         using (EmpDataEntities entities = new EmpDataEntities())
         {
             var entity = entities.Emps.FirstOrDefault(e => e.ID == id);
             if (entity == null)
             {
                 return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Employee with id : " + id.ToString() + "not found to delete"));
             }
             else
             {
                 entities.Emps.Remove(entity);
                 entities.SaveChanges();
                 return(Request.CreateResponse(HttpStatusCode.OK));
             }
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
     }
 }