Ejemplo n.º 1
0
        public ActionResult Create([Bind(Include = "EmployeeId,Name,HourlyWage,HoursWorked,Manager,Gross_Earnings,FWT,Net_earnings")] Employee employee)
        {
            if (ModelState.IsValid)
            {
                //calculate net pay
                double grossEarnings = employee.HourlyWage * employee.HoursWorked;
                if (employee.Manager)
                {
                    grossEarnings += grossEarnings * .2;
                }
                else
                {
                    if (employee.HoursWorked > 40)
                    {
                        grossEarnings += (employee.HoursWorked - 40) * 1.5 * employee.HourlyWage;
                    }
                }
                employee.Gross_Earnings = (float)grossEarnings;
                employee.FWT            = (float)(grossEarnings * 0.15);
                employee.Net_earnings   = employee.Gross_Earnings - employee.FWT;


                db.Employees.Add(employee);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(employee));
        }
Ejemplo n.º 2
0
        public IHttpActionResult PutSignUp(int id, SignUp signUp)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != signUp.Id)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult PutEmployeeData(string id, EmployeeData employeeData)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != employeeData.IdNumber)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public ActionResult Create([Bind(Include = "EmployeeId,Name,Gender,City,EmailId")] tblEmployee tblEmployee)
        {
            if (ModelState.IsValid)
            {
                db.tblEmployees.Add(tblEmployee);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(tblEmployee));
        }
Ejemplo n.º 5
0
        public ActionResult Create([Bind(Include = "EmployeeID,Name,Position,Office,Age,Salary")] Employee employee)
        {
            if (ModelState.IsValid)
            {
                db.Employees.Add(employee);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(employee));
        }
        public ActionResult Create([Bind(Include = "Id,FirstName,LastName,Email")] Employee employee)
        {
            if (ModelState.IsValid)
            {
                db.Employees.Add(employee);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(employee));
        }
Ejemplo n.º 7
0
        public ActionResult Create([Bind(Include = "EmployeeGuid,EmployeeNumber,FirstName,LastName,HireDate," +
                                                   "TerminationDate,Type,Status,Shift,Department,Title")] Employee employee)
        {
            if (ModelState.IsValid)
            {
                employee.EmployeeGuid = Guid.NewGuid();
                db.Employees.Add(employee);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(employee));
        }
 /*#####################################################
 * delete
 *####################################################*/
 public HttpResponseMessage Delete(int id)
 {
     try
     {
         using (EmployeesEntities entities = new EmployeesEntities())
         {
             //1.get the employee which user want to delete
             var entity = entities.Employees.FirstOrDefault(e => e.EmpID == id);
             //2.if the employee is not found (wrong id) => 404
             if (entity == null)
             {
                 return(Request.CreateErrorResponse(HttpStatusCode.NotFound,
                                                    "Employee with Id = " + id.ToString() + " not found to delete"));
             }
             //3.if the employee already exist in the database  => (200 ok)
             else
             {
                 entities.Employees.Remove(entity);
                 entities.SaveChanges();
                 return(Request.CreateResponse(HttpStatusCode.OK));
             }
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
     }
 }
 /*##########################################################
  * put
  *##########################################################*/
 public HttpResponseMessage Put(int id, [FromBody] Employee employee)
 {
     try
     {
         using (EmployeesEntities entities = new EmployeesEntities())
         {
             //1.get the employee from database
             var entity = entities.Employees.FirstOrDefault(e => e.EmpID == id);
             //2.if the employee is not found (wrong id) => 404
             if (entity == null)
             {
                 return(Request.CreateErrorResponse(HttpStatusCode.NotFound,
                                                    "Employee with Id " + id.ToString() + " not found to update"));
             }
             //3.if the employee already exist in the database  => (200 ok)
             else
             {
                 entity.EmpID  = employee.EmpID;
                 entity.Name   = employee.Name;
                 entity.Salary = employee.Salary;
                 entities.SaveChanges();
                 return(Request.CreateResponse(HttpStatusCode.OK, entity));
             }
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
     }
 }
Ejemplo n.º 10
0
        public ApiEmployee Add(ApiEmployee item)
        {
            ApiEmployee returnValue = null;

            using (var _context = new EmployeesEntities())
            {
                try
                {
                    item.id = -1;
                    Employee user = _context.Employees.Add(item.AsEmployee());
                    _context.SaveChanges();

                    returnValue = user.AsApiEmployee();
                }
                catch (DbEntityValidationException ex)
                {
                    throw ex.DBValidationEntityExceptionAsFriendlyException();
                }
                catch (Exception ex)
                {
                    throw ex.EntityExceptionAsFriendlyException();
                }
            }

            return(returnValue);
        }
        private void DeleteEmployeeExecute()
        {
            try
            {
                using (EmployeesEntities context = new EmployeesEntities())
                {
                    // geting the registration number of the user
                    string jmbg = ViewEmployee.JMBG;

                    // confirmation for the action
                    MessageBoxResult messageBoxResult = MessageBox.Show("Deleting the employee will delete all his records. \nAre you sure you want to delete?", "Delete Confirmation", MessageBoxButton.YesNo);

                    if (messageBoxResult == MessageBoxResult.Yes)
                    {
                        // getting the user from the database
                        tblEmployee employeeToDelete = (from x in context.tblEmployees where x.JMBG == jmbg select x).First();

                        // removin the user from the database
                        context.tblEmployees.Remove(employeeToDelete);

                        context.SaveChanges();

                        // logging the action
                        FileActions.Instance.DeletingEmployee(FileActions.path, FileActions.actions, DateTime.Now, employeeToDelete.FullName);

                        EmployeeList = GetAllEmployees().ToList();
                    }
                }
            }
            catch (Exception)
            {
                MessageBox.Show("The employee can not be deleted, please try again.");
            }
        }
        public bool Update(ApiEmployee item)
        {
            using (var context = new EmployeesEntities())
            {
                var employer = context.Employees.Where(p => p.id == item.id).FirstOrDefault();
                employer.fullName                = item.fullName;
                employer.aditional_info          = item.aditional_info;
                employer.aditional_service       = item.aditional_service;
                employer.another_building        = item.another_building;
                employer.another_company         = item.another_company;
                employer.fk_buildingaccess       = item.fk_buildingaccess;
                employer.cellphone               = item.cellphone;
                employer.email                   = item.email;
                employer.fk_companylist          = item.fk_companylist;
                employer.fk_hiredfor             = item.fk_hiredfor;
                employer.hiringManagerEmail      = item.hiringManagerEmail;
                employer.initiationDate          = item.initiationDate;
                employer.restricted_access       = item.restricted_access;
                employer.service_equipmentneeded = item.service_equipmentneeded;
                employer.startDate               = item.startDate;

                context.SaveChanges();
                return(true);
            }
            return(false);
        }
Ejemplo n.º 13
0
        public ActionResult Create([Bind(Include = "Id,Name,Comments")] tblComment tblComment)
        {
            StringBuilder sbComments = new StringBuilder();

            // Encode the text that is coming from comments textbox
            sbComments.Append(HttpUtility.HtmlEncode(tblComment.Comments));

            // Only decode bold and underline tags
            sbComments.Replace("&lt;b&gt;", "<b>");
            sbComments.Replace("&lt;/b&gt;", "</b>");
            sbComments.Replace("&lt;u&gt;", "<u>");
            sbComments.Replace("&lt;/u&gt;", "</u>");
            tblComment.Comments = sbComments.ToString();

            // HTML encode the text that is coming from name textbox
            string strEncodedName = HttpUtility.HtmlEncode(tblComment.Name);

            tblComment.Name = strEncodedName;

            if (ModelState.IsValid)
            {
                db.tblComments.Add(tblComment);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(tblComment));
        }
Ejemplo n.º 14
0
 public void DeleteEmployee(int id)
 {
     using (var db = new EmployeesEntities())
     {
         db.Employees.Remove(db.Employees.Find(id));
         db.SaveChanges();
     }
 }
Ejemplo n.º 15
0
 public void AddEmployee(Shared.Entities.Employee emp)
 {
     using (var db = new EmployeesEntities())
     {
         db.Employees.Add(emp);
         db.SaveChanges();
     }
 }
 public ActionResult Edit(Employee emp)
 {
     using (EmployeesEntities db = new EmployeesEntities())
     {
         db.Entry(emp).State = EntityState.Modified;
         db.SaveChanges();
         return(Json(new { success = true, message = "Updated Successfully" }, JsonRequestBehavior.AllowGet));
     }
 }
 public ActionResult AddOrEdit(Employee emp)
 {
     using (EmployeesEntities db = new EmployeesEntities())
     {
         db.Employees.Add(emp);
         db.SaveChanges();
         return(Json(new { success = true, message = "Saved Successfully" }, JsonRequestBehavior.AllowGet));
     }
 }
Ejemplo n.º 18
0
 public void UpdateEmployee(Shared.Entities.Employee emp)
 {
     using (var db = new EmployeesEntities())
     {
         db.Employees.Attach(emp);
         var entry = db.Entry(emp);
         entry.State = EntityState.Modified;
         db.SaveChanges();
     }
 }
 public void Remove(int id)
 {
     using (var context = new EmployeesEntities())
     {
         var employer = context.Employees.Where(p => p.id == id).FirstOrDefault();
         context.Employees.Attach(employer);
         context.Employees.Remove(employer);
         context.SaveChanges();
     }
 }
 public ActionResult Delete(int id)
 {
     using (EmployeesEntities db = new EmployeesEntities())
     {
         Employee emp = db.Employees.Where(x => x.EmployeeID == id).FirstOrDefault <Employee>();
         db.Employees.Remove(emp);
         db.SaveChanges();
         return(Json(new { success = true, message = "Deleted Successfully" }, JsonRequestBehavior.AllowGet));
     }
 }
        public ActionResult Delete(IEnumerable <int> employeeIdsToDelete)
        {
            var departmentList = db.DepartmentDetails1.Where(x => employeeIdsToDelete.Contains(x.DepId)).ToList();

            foreach (var item in departmentList)
            {
                db.DepartmentDetails1.Remove(item);
            }
            db.SaveChanges();

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 22
0
 static void Main(string[] args)
 {
     using (var EmpObj = new EmployeesEntities())
     {
         var emp = new Table_Employees();
         emp.Emp_ID     = 1;
         emp.Emp_Name   = "Manu";
         emp.Emp_Salary = 1200;
         EmpObj.Table_Employees.Add(emp);
         EmpObj.SaveChanges();
         Console.WriteLine("Record Inserted");
     }
     Console.ReadLine();
 }
Ejemplo n.º 23
0
        public JsonResult AddEmployee(Employee employee)
        {
            if (employee != null)
            {
                using (var db = new EmployeesEntities())
                {
                    db.Employees.Add(employee);
                    db.SaveChanges();

                    return(Json(new { success = true }));
                }
            }
            return(Json(new { success = false }));
        }
Ejemplo n.º 24
0
        public ActionResult AddOrEdit(EmployeeTbl emp)
        {
            try
            {
                if (emp.ImageUpload != null)
                {
                    string fileName  = Path.GetFileNameWithoutExtension(emp.ImageUpload.FileName);
                    string extention = Path.GetExtension(emp.ImageUpload.FileName);
                    fileName  = fileName + DateTime.Now.ToString("yymmssfff") + extention;
                    emp.Image = "~/AppFiles/Images/" + fileName;
                    emp.ImageUpload.SaveAs(Path.Combine(Server.MapPath("~/AppFiles/Images/"), fileName));
                }

                using (EmployeesEntities db = new EmployeesEntities())
                {
                    if (emp.EmployeeId == 0)
                    {
                        db.EmployeeTbls.Add(emp);
                        db.SaveChanges();
                    }
                    else
                    {
                        db.Entry(emp).State = EntityState.Modified;
                        db.SaveChanges();
                    }
                }

                return(Json(new { success = true, html = GlobalClass.RenderRazorViewToString(this, "ViewAll", GetAllEmployee()), message = "Submitted Successfully" },
                            JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(new { success = false, html = GlobalClass.RenderRazorViewToString(this, "ViewAll", GetAllEmployee()), message = ex.Message },
                            JsonRequestBehavior.AllowGet));
            }
        }
Ejemplo n.º 25
0
        public JsonResult Delete(int id)
        {
            using (var db = new EmployeesEntities())
            {
                var employee = db.Employees.Find(id);

                if (employee == null)
                {
                    return(Json(new { success = false }));
                }

                db.Employees.Remove(employee);
                db.SaveChanges();

                return(Json(new { success = true }));
            }
        }
Ejemplo n.º 26
0
 // New Employee Detals
 public IHttpActionResult AddEmployee(EmployeeViewModel employee)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest("Invalid Data"));
     }
     using (var ctx = new EmployeesEntities())
     {
         ctx.Employees.Add(new Employee()
         {
             Name        = employee.Name,
             Age         = employee.Age,
             JoiningDate = employee.JoiningDate
         });
         ctx.SaveChanges();
     }
     return(Ok());
 }
Ejemplo n.º 27
0
 internal void AddEmployee(tblEmployee employee, string sector, string location)
 {
     Thread.Sleep(2000);
     try
     {
         using (EmployeesEntities context = new EmployeesEntities())
         {
             employee.SectorID           = Convert.ToInt32(sector);
             employee.LocationOfEmployee = location;
             context.tblEmployees.Add(employee);
             context.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.Write("Exception" + ex.Message.ToString());
     }
 }
Ejemplo n.º 28
0
 public List <EmployeesModel> Create(EmployeesModel model)
 {
     if (ModelState.IsValid)
     {
         using (var db = new EmployeesEntities())
         {
             db.Employees.Add(new Employee
             {
                 Id_Employee = model.Id_Employee,
                 Fullname    = model.Fullname,
                 Position    = model.Position
             });
             db.SaveChanges();
             return //???;
         }
     }
     return //???;
 }
Ejemplo n.º 29
0
        public ActionResult Delete(int id)
        {
            try
            {
                using (EmployeesEntities db = new EmployeesEntities())
                {
                    EmployeeTbl emp = db.EmployeeTbls.Where(x => x.EmployeeId == id).FirstOrDefault <EmployeeTbl>();
                    db.EmployeeTbls.Remove(emp);
                    db.SaveChanges();
                }

                return(Json(new { success = true, html = GlobalClass.RenderRazorViewToString(this, "ViewAll", GetAllEmployee()), message = "Deleted Successfully" },
                            JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(new { success = false, html = GlobalClass.RenderRazorViewToString(this, "ViewAll", GetAllEmployee()), message = ex.Message },
                            JsonRequestBehavior.AllowGet));
            }
        }
Ejemplo n.º 30
0
        public JsonResult UpdateEmployee(Employee employee)
        {
            using (var db = new EmployeesEntities())
            {
                var updatedEmployee = db.Employees.Find(employee.EmployeeId);

                if (updatedEmployee == null)
                {
                    return(Json(new { success = false }));
                }
                else
                {
                    updatedEmployee.Name       = employee.Name;
                    updatedEmployee.Department = employee.Department;
                    updatedEmployee.Office     = employee.Office;
                    updatedEmployee.Email      = employee.Email;

                    db.SaveChanges();
                    return(Json(new { success = true }));
                }
            }
        }