Esempio n. 1
0
        public string SaveDepartmentData(DeptViewModel objDeptView)
        {
            try
            {
                Department objEnDept = new Department();
                if (objDeptView != null)
                {
                    objEnDept.DeptName = objDeptView.DeptName;

                    if (objDeptView.DeptId == 0)
                    {
                        empDb.Entry(objEnDept).State = EntityState.Added;
                    }
                    else
                    {
                        objEnDept.DeptId             = objDeptView.DeptId;
                        empDb.Entry(objEnDept).State = EntityState.Modified;
                        empDb.Entry(objEnDept).Property(x => x.IsDelete).IsModified = false;
                    }
                    empDb.SaveChanges();

                    return("SavedSuccessfully");
                }
                else
                {
                    return("SomethingWrong");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 2
0
 public ActionResult Edit([Bind(Include = "id,name,dob,nid,bgroup,email,phone,address")] Employee employee)
 {
     if (ModelState.IsValid)
     {
         db.Entry(employee).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(employee));
 }
        public void Edit([Bind(Include = "id,name,dob,nid,bgroup,email,phone,address")] Employee employee)
        {
            if (ModelState.IsValid)
            {
                db.Entry(employee).State = EntityState.Modified;
                db.SaveChanges();

                string redir = "/Employees/Edit/" + employee.id;
                Response.Redirect(redir);
            }
            
        }
Esempio n. 4
0
        public bool DeleteEmployee(int id)
        {
            if (id < 1)
            {
                throw new ArgumentException("Invalid id", "id");
            }

            Employee employ = employeeManagementEntities.Employees.FirstOrDefault(emp => emp.ID == id);

            employeeManagementEntities.Entry(employ).State = EntityState.Deleted;
            employeeManagementEntities.SaveChanges();
            return(true);
        }
        public IHttpActionResult PutEmployee(long id, Employee employee)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != employee.EmployeeID)
            {
                return(BadRequest());
            }

            db.Entry(employee).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!EmployeeExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Esempio n. 6
0
 /// <summary>
 /// Updates the specified employee.
 /// </summary>
 /// <param name="employee">The employee.</param>
 /// <returns></returns>
 public int Update(Employee employee)
 {
     try
     {
         using (EmployeeManagementEntities db = new EmployeeManagementEntities())
         {
             db.Entry(employee).State = System.Data.Entity.EntityState.Modified;
             return(db.SaveChanges());
         }
     }
     catch (Exception exception)
     {
         Console.WriteLine(exception.Message);
         return(0);
     }
 }