/// <summary>
        ///
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool DeleteEmployee(int id)
        {
            //using (var context = new EmployeeDBEntities())
            //{
            //    var employee = context.Employee.FirstOrDefault(x => x.Id == id);
            //    if (employee != null)
            //    {
            //        context.Employee.Remove(employee);
            //        context.SaveChanges();
            //        return true;
            //    }
            //    return false;
            //}

            //Deleting using entity state
            using (var context = new EmployeeDBEntities())
            {
                var employee = new Employee()
                {
                    Id = id
                };
                //changing the state to Deleted
                context.Entry(employee).State = System.Data.Entity.EntityState.Deleted;
                context.SaveChanges();
                return(false);
            }
        }
        public HttpResponseMessage Put(int id, [FromBody] Emp employee)
        {
            try
            {
                var emp = entities.Emps.FirstOrDefault(x => x.ID == id);
                if (emp == null)
                {
                    var message = Request.CreateResponse(HttpStatusCode.NotFound, "This employee is not found.");

                    return(message);
                }
                else
                {
                    entities.Entry(employee).State = EntityState.Modified;

                    entities.SaveChanges();
                    var message = Request.CreateResponse(HttpStatusCode.OK, "Successfully updated");

                    return(message);
                }
            }
            catch (Exception ex)
            {
                var message = Request.CreateResponse(HttpStatusCode.BadRequest, ex);
                return(message);
            }
        }
Esempio n. 3
0
        public IHttpActionResult PutDESIGNATION(string id, DESIGNATION dESIGNATION)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != dESIGNATION.DepartmentId)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Esempio n. 4
0
        public ActionResult AddorEdit(Employee emp)
        {
            try
            {
                if (emp.ImageUpload != null)
                {
                    string fileName  = Path.GetFileNameWithoutExtension(emp.ImageUpload.FileName);
                    string extension = Path.GetExtension(emp.ImageUpload.FileName);
                    fileName      = fileName + DateTime.Now.ToString("yymmssfff") + extension;
                    emp.ImagePath = "~/AppFiles/Images/" + fileName;
                    emp.ImageUpload.SaveAs(Path.Combine(Server.MapPath("~/AppFiles/Images/"), fileName));
                }

                using (EmployeeDBEntities db = new EmployeeDBEntities())
                {
                    if (emp.EmployeeID == 0)
                    {
                        db.Employees.Add(emp);
                        db.SaveChanges();
                    }
                    else
                    {
                        db.Entry(emp).State = EntityState.Modified;
                        db.SaveChanges();
                    }
                }
                return(Json(new { success = true, html = GlobalClass.RenderRazorViewToString(this, "ViewAll", GetAllEmployees()), message = "Submitted Successfully" }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(new { success = false, message = ex.Message }, JsonRequestBehavior.AllowGet));
            }
        }
        public IHttpActionResult PutEmployee(int id, Employee employee)
        {
            /* the validation will be done in Angular, we don't need this checking here !!!
             * 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
        public IHttpActionResult PutEmployee(int id, Employee employee)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult PutDETAIL(string id, DETAIL dETAIL)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != dETAIL.PanCardNumber)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Esempio n. 8
0
 private void Delete_Click(object sender, EventArgs e)
 {
     using (EmployeeDBEntities db = new EmployeeDBEntities())
     {
         DialogResult dr = MessageBox.Show("Are you sure???", "Alert", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
         if (dr == DialogResult.Yes)
         {
             model = db.Employee.Where(x => x.id == id).FirstOrDefault();
             db.Entry(model).State = EntityState.Deleted;
             int a = db.SaveChanges();
             if (a > 0)
             {
                 MessageBox.Show("Data Deleted Sussesfully!!!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 bindGridView();
                 resetControls();
             }
             else
             {
                 MessageBox.Show("Data Deletion failed!!!", "Failued", MessageBoxButtons.OK, MessageBoxIcon.Information);
             }
         }
         else
         {
             MessageBox.Show("You have cancelled this operation");
         }
     }
 }
Esempio n. 9
0
 public ActionResult Edit([Bind(Include = "EmployeeID,ManagerID,FirstName,LastName,Title,Country,City,Address,HireDate,BirthDate")] Employee employee)
 {
     if (ModelState.IsValid)
     {
         db.Entry(employee).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(employee));
 }
Esempio n. 10
0
 public ActionResult Edit([Bind(Include = "Id,Name,Designation,Salary")] Employee2 employee2)
 {
     if (ModelState.IsValid)
     {
         db.Entry(employee2).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(employee2));
 }
Esempio n. 11
0
 public ActionResult Edit([Bind(Include = "id,name,gender,age,disignation")] emp emp)
 {
     if (ModelState.IsValid)
     {
         db.Entry(emp).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(emp));
 }
Esempio n. 12
0
 public ActionResult Edit([Bind(Include = "Id,Name,Description,Number,Department")] Employee employee)
 {
     if (ModelState.IsValid)
     {
         db.Entry(employee).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(employee));
 }
 public ActionResult Edit([Bind(Include = "Id,EmployeeId,Name,Email,SalaryAmount")] Employee employee)
 {
     if (ModelState.IsValid)
     {
         db.Entry(employee).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(employee));
 }
Esempio n. 14
0
 public ActionResult Edit([Bind(Include = "Id,Ad,Sifre,Role")] Kullanici kullanici)
 {
     if (ModelState.IsValid)
     {
         db.Entry(kullanici).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(kullanici));
 }
 public ActionResult Edit([Bind(Include = "ID,Employee_Id,Date,Total")] Payment payment)
 {
     if (ModelState.IsValid)
     {
         db.Entry(payment).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.Employee_Id = new SelectList(db.Employees, "EmployeeID", "Name", payment.Employee_Id);
     return(View(payment));
 }
Esempio n. 16
0
        public async Task <ActionResult> Edit([Bind(Include = "AddressId,Address1,Address2,City,PostalCode")] EmployeeAddress employeeAddress)
        {
            if (ModelState.IsValid)
            {
                db.Entry(employeeAddress).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(employeeAddress));
        }
 public ActionResult Edit([Bind(Include = "Id,FirstName,LastName,Email,AddressId,Code")] Employee employee)
 {
     if (ModelState.IsValid)
     {
         db.Entry(employee).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.AddressId = new SelectList(db.Addresses, "Id", "Details", employee.AddressId);
     return(View(employee));
 }
Esempio n. 18
0
        //[HttpDelete]
        //public int Delete(int announcementId)
        //{
        //    return 1;
        //}


        public void NewDelete(string Id)
        {
            int Eid = Convert.ToInt32(Id);

            using (EmployeeDBEntities entity = new EmployeeDBEntities())
            {
                Employee emp = entity.Employees.Where(e => e.Id == Eid).FirstOrDefault <Employee>();
                entity.Entry(emp).State = System.Data.Entity.EntityState.Deleted;

                entity.SaveChanges();
            }
        }
        public async Task <ActionResult> Edit([Bind(Include = "EmpId,FirstName,LastName,Phone,EmailID,AddressID")] Employee employee)
        {
            if (ModelState.IsValid)
            {
                db.Entry(employee).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewBag.AddressID = new SelectList(db.EmployeeAddresses, "AddressId", "Address1", employee.AddressID);
            return(View(employee));
        }
Esempio n. 20
0
        //Delete records from database the databse first method

        /*public bool DeleteEmployee(int id)
         * {
         *  using (var context = new EmployeeDBEntities())
         *  {
         *      var employee = context.Employee.FirstOrDefault(a => a.Id == id);
         *      if (employee != null)
         *      {
         *          context.Employee.Remove(employee);
         *          context.SaveChanges();
         *          return true;
         *      }
         *      return false;
         *  }
         * }*/
        //Delete records from database the databse second method
        public bool DeleteEmployee(int id)
        {
            using (var context = new EmployeeDBEntities())
            {
                var emp = new Employee()
                {
                    Id = id
                };
                context.Entry(emp).State = System.Data.Entity.EntityState.Deleted;
                context.SaveChanges();
                return(false);
            }
        }
Esempio n. 21
0
 public void Post(Employee employee)
 {
     using (EmployeeDBEntities entity = new EmployeeDBEntities())
     {
         if (employee.Id <= 0)
         {
             entity.Employees.Add(employee);
             entity.SaveChanges();
         }
         else
         {
             //Employee emp = entity.Employees.Where(e => e.Id == employee.Id).FirstOrDefault<Employee>();
             entity.Entry(employee).State = System.Data.Entity.EntityState.Modified;
             entity.SaveChanges();
         }
     }
 }
        public IHttpActionResult PuttblEmployee(int id, EmployeeModel employee)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

            tblEmployee tblEmployee = new tblEmployee()
            {
                ID           = employee.ID,
                DepartmentId = employee.DepartmentId,
                FirstName    = employee.FirstName,
                LastName     = employee.LastName,
                Gender       = employee.Gender,
                Salary       = employee.Salary,
                JobTitle     = employee.JobTitle,
                JoiningDate  = employee.JoiningDate == DateTime.MinValue ? (DateTime)SqlDateTime.Null : (DateTime)employee.JoiningDate,
                InService    = employee.InService,
                LeavingDate  = employee.LeavingDate == null ? (DateTime)SqlDateTime.Null : employee.LeavingDate
            };

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

            try
            {
                db.SaveChanges();
                return(Ok(new { Message = "SUCCESS" }));
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TblEmployeeExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
        }
Esempio n. 23
0
        public IHttpActionResult DeleteEmployeeByEmpCode(int empCode)
        {
            if (empCode <= 0)
            {
                return(BadRequest("employee code is not valid."));
            }

            using (var ctx = new EmployeeDBEntities())
            {
                var employee = ctx.Employees
                               .Where(s => s.EmpCode == empCode)
                               .FirstOrDefault();

                ctx.Entry(employee).State = System.Data.Entity.EntityState.Deleted;
                ctx.SaveChanges();
            }
            return(Ok());
        }
        public IHttpActionResult Delete(int id)
        {
            if (id < 0)
            {
                return(BadRequest("Not a valid Employee Id"));
            }

            using (var ctx = new EmployeeDBEntities())
            {
                var employee = ctx.Employees
                               .FirstOrDefault(s => s.ID == id);

                ctx.Entry(employee).State = System.Data.Entity.EntityState.Deleted;
                ctx.SaveChanges();
            }

            return(Ok());
        }
Esempio n. 25
0
        //Update the databse first method

        /*  public bool UpDateEmployee(int id,EmployeeModel model)
         * {
         *    using (var context = new EmployeeDBEntities())
         *    {
         *        var employee = context.Employee.FirstOrDefault(a => a.Id == id);
         *        if (employee !=null)
         *        {
         *            employee.FirstName = model.FirstName;
         *            employee.LastName = model.LastName;
         *            employee.Email = model.Email;
         *            employee.Code = model.Code;
         *        }
         *        context.SaveChanges();
         *        return true;
         *    }
         * }*/

        //Update the databse second method
        public bool UpDateEmployee(int id, EmployeeModel model)
        {
            using (var context = new EmployeeDBEntities())
            {
                var employee = new Employee();
                if (employee != null)
                {
                    employee.Id        = model.Id;
                    employee.FirstName = model.FirstName;
                    employee.LastName  = model.LastName;
                    employee.Email     = model.Email;
                    employee.Code      = model.Code;
                    employee.AddressId = model.AddressId;
                }
                context.Entry(employee).State = System.Data.Entity.EntityState.Modified;
                context.SaveChanges();
                return(true);
            }
        }
        public ActionResult Edit([Bind(Include = "EmployeeID,CityID,Name,Email,Salary")] VMEmployee vmemployee)
        {
            if (ModelState.IsValid)
            {
                Employee employee = db.Employees.Find(vmemployee.EmployeeID);


                employee.Name   = vmemployee.Name;
                employee.Email  = vmemployee.Email;
                employee.Salary = vmemployee.Salary;
                employee.CityID = vmemployee.CityID;

                db.Entry(employee).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(vmemployee));
        }
        public bool UpdateEmployee(int id, EmployeeModel employeeModel)
        {
            //using (var context = new EmployeeDBEntities())
            //{
            //    var employee = context.Employee.FirstOrDefault(x => x.Id == id);

            //    if (employee != null)
            //    {
            //        employee.FirstName = employeeModel.FirstName;
            //        employee.LastName = employeeModel.LastName;
            //        employee.Code = employeeModel.Code;
            //        employee.Email = employeeModel.Email;
            //        //  employee.Address = employeeModel.Email;
            //    }
            //    context.SaveChanges();

            //    return true;
            //}

            //update using entity state in single hit to database
            using (var context = new EmployeeDBEntities())
            {
                var employee = new Employee();

                if (employee != null)
                {
                    employee.Id        = employeeModel.Id;
                    employee.FirstName = employeeModel.FirstName;
                    employee.LastName  = employeeModel.LastName;
                    employee.Code      = employeeModel.Code;
                    employee.Email     = employeeModel.Email;
                    employee.AddressId = employeeModel.AddressId;
                }

                //changing the state to Modified
                context.Entry(employee).State = System.Data.Entity.EntityState.Modified;
                context.SaveChanges();

                return(true);
            }
        }
Esempio n. 28
0
 public bool DeleteEmployee(int id)
 {
     using (var context = new EmployeeDBEntities())
     {
         var result = new Employee()
         {
             Id = id
         };
         context.Entry(result).State = System.Data.Entity.EntityState.Deleted;
         //var result = context.Employee.FirstOrDefault(x => x.Id == id);
         //{
         //    if(result != null)
         //    {
         //        context.Employee.Remove(result);
         context.SaveChanges();
         return(true);
         //    }
         //    return false;
         //}
     }
 }
 /// <summary>
 /// Delete Employee Information
 /// </summary>
 /// <param name="Emp"></param>
 /// <returns></returns>
 public string Delete_Employee(Employee Emp)
 {
     if (Emp != null)
     {
         using (EmployeeDBEntities Obj = new EmployeeDBEntities())
         {
             var Emp_ = Obj.Entry(Emp);
             if (Emp_.State == System.Data.Entity.EntityState.Detached)
             {
                 Obj.Employees.Attach(Emp);
                 Obj.Employees.Remove(Emp);
             }
             Obj.SaveChanges();
             return("Employee Deleted Successfully");
         }
     }
     else
     {
         return("Employee Not Deleted! Try Again");
     }
 }
 /// <summary>
 /// Update Employee Information
 /// </summary>
 /// <param name="Emp"></param>
 /// <returns></returns>
 public string Update_Employee(Employee Emp)
 {
     if (Emp != null)
     {
         using (EmployeeDBEntities Obj = new EmployeeDBEntities())
         {
             var      Emp_   = Obj.Entry(Emp);
             Employee EmpObj = Obj.Employees.Where(x => x.ID == Emp.ID).FirstOrDefault();
             EmpObj.FirstName = Emp.FirstName;
             EmpObj.LastName  = Emp.LastName;
             EmpObj.Gender    = Emp.Gender;
             EmpObj.Salary    = Emp.Salary;
             Obj.SaveChanges();
             return("Employee Updated Successfully");
         }
     }
     else
     {
         return("Employee Not Updated! Try Again");
     }
 }