Example #1
0
        // GET: Companies
        public ActionResult Index(int?id, string mode)
        {
            if (@Session["UserID"] == null)
            {
                return(RedirectToAction("../Login/Index"));
            }
            else
            {
                CompaniesCl           model = new CompaniesCl();
                HumanResourceEntities dbcon = new HumanResourceEntities();

                if (id == null)
                {
                    id = 0;
                    model.idCompany       = null;
                    model.SelectedCompany = null;
                }

                else
                {
                    model.idCompany       = id.ToString();
                    model.SelectedCompany = dbcon.Companies.Find(id);
                    model.DisplayMode     = mode;
                }

                model.CompaniesList = dbcon.Companies.OrderBy(m => m.CompanyName).ToList();

                return(View(model));
            }
        }
        private IList <NameItem> GetCityList()
        {
            IList <CityModel> cities;

            using (HumanResourceEntities db = new HumanResourceEntities())
            {
                cities = (from b in db.Cities
                          select new CityModel
                {
                    Id = b.Id,
                    Name = b.Name
                }).OrderBy(e => e.Name).ToList();
            }

            IList <NameItem> list = new List <NameItem>();

            list.Insert(0, new NameItem()
            {
                Id = null, Name = string.Empty
            });
            foreach (var m in cities)
            {
                list.Add(new NameItem()
                {
                    Id = m.Id, Name = m.Name
                });
            }
            return(list);
        }
Example #3
0
        public ActionResult Login(LoginModel login)
        {
            if (ModelState.IsValid)
            {
                HumanResourceEntities db = new HumanResourceEntities();

                var user = (from r in db.Recruitments
                            where r.UserName == login.UserName && r.Password == login.Password
                            select new
                {
                    r.idUser_,
                    r.Name,
                    r.Paternal
                }).ToList();
                if (user.FirstOrDefault() != null)
                {
                    Session["UserName"] = user.FirstOrDefault().Name + " " + user.FirstOrDefault().Paternal;
                    Session["UserID"]   = user.FirstOrDefault().idUser_;
                    return(RedirectToAction("../Home/Index"));
                    //return View(login);
                }
                else
                {
                    //return Content("<script language='javascript' type='text/javascript'>alert('Invalid login credentials');</script>");
                    //return RedirectToAction("../Home/Index");
                    ModelState.AddModelError("", "Invalid login credentials.");
                }
            }
            return(View("Index"));
        }
        public ActionResult Index()
        {
            // получаем из бд все объекты Book
            using (HumanResourceEntities db = new HumanResourceEntities())
            {
                var employees = (from b in db.Employees
                                 select new EmployeeModel
                {
                    Id = b.Id,
                    CityId = b.CityId,
                    CityName = b.City.Name,
                    Name = b.Name,
                    Surname = b.Surname,
                    Patronymic = b.Patronymic,
                    Address = b.Address,
                    StartDate = b.StartDate,
                    EndDate = b.EndDate,
                    MobilePhone = b.MobilePhone,
                    ManagerId = b.ManagerId,
                    ManagerName = b.ManagerId == null ? null : b.Employee2.Surname,
                    DateOfBirth = b.DateOfBirth,
                    Position = b.Position,
                    Phone = b.Phone
                }).ToList();

                // передаем все объекты в динамическое свойство Books в ViewBag
                ViewBag.Employees = employees;
            }
            // возвращаем представление
            return(View());
        }
Example #5
0
        // GET: Recruitments
        public ActionResult Index(int?id, string mode)
        {
            if (@Session["UserID"] == null)
            {
                return(RedirectToAction("../Login/Index"));
            }
            else
            {
                RecruiterCl           model = new RecruiterCl();
                HumanResourceEntities dbcon = new HumanResourceEntities();

                if (id == null)
                {
                    id                      = 0;
                    model.idUser            = 0;
                    model.SelectedRecruiter = null;
                }

                else
                {
                    model.idUser            = (int)id;
                    model.SelectedRecruiter = dbcon.Recruitments.Find(id);
                    model.DisplayMode       = mode;
                }

                model.DateCreate    = @DateTime.Now.ToString("MM/dd/yyyy");
                model.RecruiterList = dbcon.Recruitments.OrderBy(m => m.Name).ToList();

                return(View(model));
            }
        }
Example #6
0
        // GET: Positions
        public ActionResult Index(int?id, string mode)
        {
            if (@Session["UserID"] == null)
            {
                return(RedirectToAction("../Login/Index"));
            }
            else
            {
                PositionsCl           model = new PositionsCl();
                HumanResourceEntities dbcon = new HumanResourceEntities();

                if (id == null)
                {
                    id = 0;
                    model.idPosition       = 0;
                    model.SelectedPosition = null;
                }

                else
                {
                    model.idPosition       = (int)id;
                    model.SelectedPosition = (Position)dbcon.Positions.Find(id);
                    model.DisplayMode      = mode;
                }

                model.IdUser       = (int)Session["UserID"];
                model.DateCreate   = @DateTime.Now.ToString("MM/dd/yyyy");
                model.PositionList = dbcon.Positions.OrderBy(m => m.PositionName).ToList();
                int selectedId = 0;
                model.CompanyName = new SelectList(db.Companies, "idCompany", "CompanyName", selectedId);
                ViewBag.idCompany = new SelectList(db.Companies, "idCompany", "CompanyName", selectedId);

                return(View(model));
            }
        }
        public ActionResult Create(EmployeeModel employee)
        {
            if (!ModelState.IsValid)
            {
                return(Create());
            }

            Employee dbEmployee = new Employee()
            {
                Name        = employee.Name,
                Surname     = employee.Surname,
                Patronymic  = employee.Patronymic,
                CityId      = employee.CityId,
                StartDate   = employee.StartDate,
                EndDate     = employee.EndDate,
                MobilePhone = employee.MobilePhone,
                DateOfBirth = employee.DateOfBirth,
                Position    = employee.Position,
                Phone       = employee.Phone,
                Address     = employee.Address,
                ManagerId   = employee.ManagerId
            };

            using (HumanResourceEntities db = new HumanResourceEntities())
            {
                db.Employees.Add(dbEmployee);
                db.SaveChanges();
            }

            // перенаправляем на главную страницу
            return(RedirectToAction("Index"));
        }
        public ActionResult Edit(int?id, EmployeeModel employee)
        {
            if (!ModelState.IsValid)
            {
                LoadDropDowns(id);
                return(View(employee));
            }

            Employee dbEmployee = new Employee()
            {
                Id          = employee.Id,
                Name        = employee.Name,
                Surname     = employee.Surname,
                Patronymic  = employee.Patronymic,
                CityId      = employee.CityId,
                StartDate   = employee.StartDate,
                EndDate     = employee.EndDate,
                MobilePhone = employee.MobilePhone,
                DateOfBirth = employee.DateOfBirth,
                Position    = employee.Position,
                Phone       = employee.Phone,
                Address     = employee.Address,
                ManagerId   = employee.ManagerId
            };

            using (HumanResourceEntities db = new HumanResourceEntities())
            {
                db.Entry(dbEmployee).State = EntityState.Modified;

                db.SaveChanges();
            }

            // перенаправляем на главную страницу
            return(RedirectToAction("Index"));
        }
        private IList <NameItem> GetEmployeeList(int?exceptId)
        {
            IList <EmployeeModel> employees;

            using (HumanResourceEntities db = new HumanResourceEntities())
            {
                employees = (from b in db.Employees
                             where (exceptId == null || exceptId != b.Id) && b.EndDate == null // проверяем, что сотрудник не уволился
                             select new EmployeeModel
                {
                    Id = b.Id,
                    Surname = b.Surname,
                    Name = b.Name,
                    Patronymic = b.Patronymic
                }).OrderBy(e => e.Surname).ThenBy(e => e.Name).ToList();
            }

            IList <NameItem> list = new List <NameItem>();

            list.Insert(0, new NameItem()
            {
                Id = null, Name = string.Empty
            });
            foreach (var m in employees)
            {
                list.Add(new NameItem()
                {
                    Id = m.Id, Name = EmployeeModel.GetDisplayName(m.Surname, m.Name, m.Patronymic)
                });
            }
            return(list);
        }
        public ActionResult Display(int?id)
        {
            using (HumanResourceEntities db = new HumanResourceEntities())
            {
                var employee = (from e in db.Employees
                                where e.Id == id
                                select new EmployeeModel
                {
                    Id = e.Id,
                    Name = e.Name,
                    Surname = e.Surname,
                    Patronymic = e.Patronymic,
                    CityId = e.CityId,
                    CityName = e.City.Name,
                    StartDate = e.StartDate,
                    EndDate = e.EndDate,
                    MobilePhone = e.MobilePhone,
                    ManagerId = e.ManagerId,
                    DateOfBirth = e.DateOfBirth,
                    Position = e.Position,
                    Phone = e.Phone,
                    Address = e.Address,
                    ManagerName = e.ManagerId == null ? null : e.Employee2.Surname,
                }).FirstOrDefault();

                if (employee == null)
                {
                    return(HttpNotFound());
                }

                return(View(employee));
            }
        }
Example #11
0
        public ActionResult Delete(int?id)
        {
            HumanResourceEntities dbcon = new HumanResourceEntities();
            Employee idEmployee         = dbcon.Employees.Find(id);

            dbcon.Employees.Remove(idEmployee);
            dbcon.SaveChanges();

            return(RedirectToAction("Index"));
        }
Example #12
0
        public ActionResult Delete(int?id)
        {
            HumanResourceEntities dbcon = new HumanResourceEntities();
            Position idPosition         = dbcon.Positions.Find(id);

            dbcon.Positions.Remove(idPosition);
            dbcon.SaveChanges();

            return(RedirectToAction("Index"));
        }
Example #13
0
        public ActionResult Delete(int?id)
        {
            HumanResourceEntities dbcon       = new HumanResourceEntities();
            Recruitment           idRecruiter = dbcon.Recruitments.Find(id);

            dbcon.Recruitments.Remove(idRecruiter);
            dbcon.SaveChanges();

            return(RedirectToAction("Index"));
        }
Example #14
0
        public ActionResult Delete(int?id)
        {
            HumanResourceEntities dbcon = new HumanResourceEntities();
            Company idCompany           = dbcon.Companies.Find(id);

            dbcon.Companies.Remove(idCompany);
            dbcon.SaveChanges();

            return(RedirectToAction("Index"));
        }
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(HttpNotFound());
            }

            using (HumanResourceEntities db = new HumanResourceEntities())
            {
                Employee employee = new Employee {
                    Id = id.Value
                };
                db.Entry(employee).State = EntityState.Deleted;
                db.SaveChanges();

                // перенаправляем на главную страницу
                return(RedirectToAction("Index"));
            }
        }
Example #16
0
        // GET: Messages
        public ActionResult Index(int?id, string mode)
        {
            if (@Session["UserID"] == null)
            {
                return(RedirectToAction("../Login/Index"));
            }
            else
            {
                MessagesCl            model = new MessagesCl();
                HumanResourceEntities dbcon = new HumanResourceEntities();

                if (id == null)
                {
                    id = 0;
                    model.idMessage       = 0;
                    model.SelectedMessage = null;
                }

                else
                {
                    model.idMessage       = (int)id;
                    model.SelectedMessage = dbcon.Messages.Find(id);
                    model.DisplayMode     = mode;
                }

                model.DateSend    = @DateTime.Now.ToString("MM/dd/yyyy");
                model.MessageList = dbcon.Messages.OrderBy(m => m.DateSend).ToList();
                int selectedId = (int)Session["UserID"];
                //model.NameSendBy = new SelectList(db.Recruitments, "idUser", "Name"+" "+"Paternal", selectedId);
                //ViewBag.idSendBy = new SelectList(db.Recruitments, "idUser_", "Name", selectedId);
                //ViewBag.idSendTo = new SelectList(db.Employees, "IdEmployee", "Name", selectedId);

                ViewBag.idSendBy = new SelectList((from s in db.Recruitments.OrderBy(x => x.Name) select new { ID = s.idUser_, FullName = s.Name + " " + s.Paternal }), "ID", "FullName", selectedId);

                ViewBag.idEmployee = new SelectList((from s in db.Employees.OrderBy(x => x.Name) select new { ID = s.IdEmployee, FullName = s.Name + " " + s.LastName }), "ID", "FullName", 0);

                return(View(model));
            }
        }
Example #17
0
        // GET: Employees
        public ActionResult Index(int?id, string mode, string sortOrder, string searchString, int?page, string currentFilter)
        {
            if (@Session["UserID"] == null)
            {
                return(RedirectToAction("../Login/Index"));
            }
            else
            {
                EmployeeCl            model = new EmployeeCl();
                HumanResourceEntities dbcon = new HumanResourceEntities();

                if (id == null)
                {
                    id = 0;
                    model.IdEmployee       = 0;
                    model.SelectedEmployee = null;
                }

                else
                {
                    model.IdEmployee       = (int)id;
                    model.SelectedEmployee = (Employee)dbcon.Employees.Find(id);
                    model.DisplayMode      = mode;
                }

                model.IdUser             = (int)Session["UserID"];
                ViewBag.NameSortParm     = String.IsNullOrEmpty(sortOrder) ? "name_desc" : "";
                ViewBag.LastNameSortParm = String.IsNullOrEmpty(sortOrder) ? "last_desc" : "";
                //ViewBag.DateSortParm = sortOrder == "Date" ? "date_desc" : "Date";

                /*if (searchString != null)
                 * {
                 *  page = 1;
                 * }
                 * else
                 * {
                 *  searchString = currentFilter;
                 * }*/

                ViewBag.CurrentFilter = searchString;


                var data = from s in db.Employees select s;

                if (!String.IsNullOrEmpty(searchString))
                {
                    data = data.Where(s => s.Name.Contains(searchString) || s.LastName.Contains(searchString) || s.Email.Contains(searchString));
                }

                switch (sortOrder)
                {
                case "name_desc":
                    data = data.OrderByDescending(s => s.Name);
                    break;

                /*case "last_desc":
                 *  data = data.OrderByDescending(s => s.LastName);
                 *  break;*/
                default:
                    data = data.OrderBy(s => s.Name);
                    break;
                }

                int pageSize   = 3;
                int pageNumber = (page ?? 1);

                model.EmployeeList = data.ToList();
                //model.EmployeeList = dbcon.Employees.OrderBy(m => m.Name).ToList();
                //model.EmployeeList = data.ToPagedList(pageNumber, pageSize).ToList();

                int selectedId = 0;
                model.PositionName = new SelectList(db.Positions, "idPosition", "PositionName", selectedId);

                ViewBag.idPosition = new SelectList(db.Positions, "idPosition", "PositionName", selectedId);

                return(View(model));
            }
        }
Example #18
0
 public UnitOfWork()
 {
     _dbContext = new HumanResourceEntities();
 }