public async Task <Em.Employees> PutAsync(string id, Em.Employees updateRequest)
        {
            int empNo;

            if (!int.TryParse(id, out empNo))
            {
                return(await Task.FromResult <Em.Employees>(null));
            }

            Em.Employees employee = await _context.Employees
                                    .Where(i => i.EmpNo == empNo)
                                    .FirstOrDefaultAsync();

            // try {
            //     DataCloneExtension.CopyProperties(updateRequest, employee);
            // } catch(Exception ex) {
            //     var e = ex;
            // }
            employee.FirstName = updateRequest.FirstName;
            employee.LastName  = updateRequest.LastName;
            employee.BirthDate = updateRequest.BirthDate;
            employee.HireDate  = updateRequest.HireDate;
            employee.Gender    = updateRequest.Gender;

            _context.Entry(employee).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(updateRequest);
        }
Ejemplo n.º 2
0
        static void Task_8()
        {
            Console.Write("Введите город, который хотите удалить: ");
            string town = Console.ReadLine();

            var townDb = context.Towns
                         .Where(t => t.Name.Contains(town))
                         .FirstOrDefault();

            if (townDb == null)
            {
                Console.WriteLine("Данного города не существует, повторите попытку..");
                return;
            }
            else
            {
                context.Entry(townDb).Collection(c => c.Addresses).Load();
                context.Towns.Remove(townDb);

                try
                {
                    context.SaveChanges();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.InnerException.Message);
                    return;
                }

                Console.WriteLine("Город {0} был удалён.", town);
            }
        }
Ejemplo n.º 3
0
        static void DeleteTown()
        {
            Console.Write("Town: ");
            string town  = Console.ReadLine();
            var    towns = _context.Towns
                           .Where(t => t.Name.Contains(town))
                           .FirstOrDefault();

            _context.Entry(towns).Collection(t => t.Addresses).Load();
            _context.Towns.Remove(towns);
            _context.SaveChanges();
        }
Ejemplo 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 (EmployeesContext db = new EmployeesContext())
         {
             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", GetAllEmployee()), message = "Submitted Successfully" }, JsonRequestBehavior.AllowGet));
     }
     catch (Exception ex)
     {
         return(Json(new { success = true, message = ex.Message }, JsonRequestBehavior.AllowGet));
     }
 }
Ejemplo n.º 5
0
        public IHttpActionResult PutEmployee(int id, Employee employee)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != employee.Id)
            {
                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 async Task <IActionResult> PutEmployees([FromRoute] int id, [FromBody] Employee employee)
        {
            if (id != employee.EmployeeId)
            {
                return(BadRequest());
            }

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

            try
            {
                await CreateOrEditAddresses(employee.Addresses);

                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!EmployeeExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> PutEmployee(long id, Employee employee)
        {
            if (id != employee.Id)
            {
                return(BadRequest());
            }

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

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!EmployeeExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Ejemplo n.º 8
0
 public ActionResult Edit(Employees employees)
 {
     if (ModelState.IsValid)
     {
         db.Entry(employees).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(employees));
 }
Ejemplo n.º 9
0
 public ActionResult Edit([Bind(Include = "Id,DepartmentName,Director")] Department department)
 {
     if (ModelState.IsValid)
     {
         db.Entry(department).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(department));
 }
Ejemplo n.º 10
0
 public ActionResult Edit([Bind(Include = "Id,Name,Department")] Employee employee)
 {
     if (ModelState.IsValid)
     {
         db.Entry(employee).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(employee));
 }
Ejemplo n.º 11
0
        public async Task <Em.VwEmpDetails> PutAsync(string id, Em.VwEmpDetails updateRequest)
        {
            int empNo;

            if (!int.TryParse(id, out empNo))
            {
                return(await Task.FromResult <Em.VwEmpDetails>(null));
            }

            Em.Employees employee = await _context.Employees
                                    .Where(i => i.EmpNo == empNo)
                                    .FirstOrDefaultAsync();

            Em.VwSalariesCurrent salary = await _context.VwSalariesCurrent
                                          .Where(i => i.EmpNo == empNo)
                                          .FirstOrDefaultAsync();

            Em.VwTitlesCurrent title = await _context.VwTitlesCurrent
                                       .Where(i => i.EmpNo == empNo)
                                       .FirstOrDefaultAsync();

            Em.VwDeptEmpCurrent deptEmp = await _context.VwDeptEmpCurrent
                                          .Where(i => i.EmpNo == empNo)
                                          .FirstOrDefaultAsync();

            if (title.Title != updateRequest.Title)
            {
                throw new NotImplementedException();
            }

            if (salary.Salary != updateRequest.Salary)
            {
                throw new NotImplementedException();
            }

            if (deptEmp.DeptNo != updateRequest.DeptNo)
            {
                throw new NotImplementedException();
            }

            if (employeeBasicInfoChanged(employee, updateRequest))
            {
                employee.BirthDate = updateRequest.BirthDate;
                employee.FirstName = updateRequest.FirstName;
                employee.LastName  = updateRequest.LastName;
                employee.Gender    = updateRequest.Gender;
                employee.HireDate  = updateRequest.HireDate;

                _context.Entry(employee).State = EntityState.Modified;
            }

            await _context.SaveChangesAsync();

            return(updateRequest);
        }
Ejemplo n.º 12
0
 public ActionResult Edit([Bind(Include = "Id,Fullname,CIN,DepartmentId")] Employee employee)
 {
     if (ModelState.IsValid)
     {
         db.Entry(employee).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.DepartmentId = new SelectList(db.Departments, "Id", "DepartmentName", employee.DepartmentId);
     return(View(employee));
 }
Ejemplo n.º 13
0
        public ActionResult DeleteCrewFlight(int cId, int fId, int?jj)
        {
            using (EmployeesContext db = new EmployeesContext())
            {
                Employee ex = db.crew.Find(cId, fId);
                db.Entry(ex).State = EntityState.Deleted;
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }
        }
 public ActionResult Edit(int id, Employee employee)
 {
     try
     {
         dbEmployee.Entry(employee).State = EntityState.Modified;
         dbEmployee.SaveChanges();
         return RedirectToAction("Index");
     }
     catch
     {
         return View();
     }
 }
Ejemplo n.º 15
0
        static void Task8()
        {
            string town = Console.ReadLine();

            var towns = (
                from t in _context.Towns
                where t.Name == town
                select t
                ).First();

            _context.Entry(towns).Collection(t => t.Addresses).Load();
            _context.Towns.Remove(towns);
            _context.SaveChanges();
        }
Ejemplo n.º 16
0
        public async Task <Departments> PutAsync(string id, Departments updateRequest)
        {
            IQueryable <Departments> result =
                from d in this._context.Departments
                where d.DeptNo == id
                select d;

            var dept = await result.FirstAsync();

            dept.DeptName = updateRequest.DeptName;

            _context.Entry(dept).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(dept);
        }
Ejemplo n.º 17
0
        public IHttpActionResult PutEmployee(Employees editEmployee)
        {
            var emp = db.EmployeeList.Find(editEmployee.EmployeeID);

            if (emp != null)
            {
                emp.EmployeeName = editEmployee.EmployeeName;
                emp.Address      = editEmployee.Address;
                emp.Email        = editEmployee.Email;

                db.Entry(emp).State = EntityState.Modified;
                db.SaveChanges();
                return(Ok());
            }
            return(NotFound());
        }
Ejemplo n.º 18
0
 public void Update(Employee item)
 {
     _db.Entry(item).State = EntityState.Modified;
 }