Пример #1
0
        public static void UpdateUser(Uzer u)
        {
            SmallSimpleOAContext ctx = new SmallSimpleOAContext();

            ctx.Update(u);
            ctx.SaveChanges();
        }
Пример #2
0
        public IActionResult Home(string ep, string tp)
        {
            const int PAGE_SIZE = 10;
            int?      uid       = HttpContext.Session.GetInt32("uid");

            if (uid == null)
            {
                return(RedirectToAction("Login", "Login"));
            }
            int eventPage, todoPage;

            if (!Int32.TryParse(ep, out eventPage))
            {
                eventPage = 1;
            }
            if (!Int32.TryParse(tp, out todoPage))
            {
                todoPage = 1;
            }

            Uzer u = UserService.FindUserByID((int)uid);

            int eventCount = AskForLeaveService.FindCountByCurrentAt(u);
            int todoCount  = TodoTaskService.FindUndoneCountByUser((int)uid);

            int eventPages = eventCount % PAGE_SIZE == 0 ? eventCount / PAGE_SIZE : eventCount / PAGE_SIZE + 1;
            int todoPages  = todoCount % PAGE_SIZE == 0 ? todoCount / PAGE_SIZE : todoCount / PAGE_SIZE + 1;

            if (eventPage > eventPages)
            {
                eventPage = eventPages;
            }
            if (todoPage > todoPages)
            {
                todoPage = todoPages;
            }

            if (eventPage <= 0)
            {
                eventPage = 1;
            }
            if (todoPage <= 0)
            {
                todoPage = 1;
            }

            List <AskForLeave> asks  = AskForLeaveService.FindAskForLeaveByCurrentAtAndPageAndPagesize(u, eventPage, PAGE_SIZE);
            List <TodoTask>    todos = TodoTaskService.FindUndoneTodoTaskByUserAndPageAndPagesize((int)uid, todoPage, PAGE_SIZE);

            List <Attendance> attendanceList    = AttendanceService.FindAttendanceByUserAndDateAndType((int)uid, DateTime.Now, AttendanceType.In);
            Boolean           need              = (attendanceList == null || attendanceList.Count <= 0) ? true : false;
            HomeHomeViewModel homeHomeViewModel = new HomeHomeViewModel(asks, eventPages, eventPage, todos, todoPages, todoPage, need);

            return(View(homeHomeViewModel));
        }
Пример #3
0
        public IActionResult Message(string d, string u)
        {
            int?uid = HttpContext.Session.GetInt32("uid");

            if (uid == null)
            {
                return(RedirectToAction("Login", "Login"));
            }
            List <Department> deps   = DepartmentService.FindDepartment();
            Department        selDep = null;

            int targetId = 0;

            if (Int32.TryParse(u, out targetId) && targetId > 0)
            {
                //find target's deparment
                Uzer target = UserService.FindUserByID(targetId);

                foreach (Department department in deps)
                {
                    if (department.Id == target.Department)
                    {
                        selDep = department;
                        break;
                    }
                }
            }
            else
            {
                //try find selected department
                int depId = 0;
                Int32.TryParse(d, out depId);
                foreach (Department department in deps)
                {
                    if (department.Id == depId)
                    {
                        selDep = department;
                        break;
                    }
                }
            }

            List <Uzer> staffs = new List <Uzer>();

            if (selDep == null && deps.Count > 0)
            {
                selDep = deps[0];
            }
            staffs = UserService.FindUserByDepartment(selDep.Id);


            MessageMessageViewModel messageMessageViewModel = new MessageMessageViewModel(deps, staffs, selDep, targetId);

            return(View(messageMessageViewModel));
        }
Пример #4
0
        private Uzer GetUzer(string name)
        {
            var uzer = repository.GetFiltered <Uzer>(u => u.Name == name).FirstOrDefault();

            if (uzer == null)
            {
                uzer = new Uzer(name);
                repository.SaveNewEntity(uzer);
            }
            return(uzer);
        }
Пример #5
0
        public static Uzer FindSupervisorByUid(int uid)
        {
            Uzer       u          = FindUserByID(uid);
            Department department = DepartmentService.FindDepartmentByID((int)u.Department);

            if (u.UzerLevel >= department.TotalStaffLevel)
            {
                return(null);
            }
            Uzer supervisor = new SmallSimpleOAContext().Uzer.FirstOrDefault(s => s.Valid == true && s.Department == u.Department && s.UzerLevel == (u.UzerLevel + 1));

            return(supervisor);
        }
Пример #6
0
        public static void AddUser(string email, string password, string firstName, string lastName, int department, int level)
        {
            Uzer u = new Uzer();

            u.Valid      = true;
            u.Email      = email;
            u.FirstName  = firstName;
            u.LastName   = lastName;
            u.Department = department;
            u.UzerLevel  = level;
            string salt = UserPasswordUtil.GenerateSalt();

            u.Salt     = salt;
            u.Password = UserPasswordUtil.GeneratePasswordAfterSalt(password, salt);
            SmallSimpleOAContext ctx = new SmallSimpleOAContext();

            ctx.Add(u);
            ctx.SaveChanges();
        }
Пример #7
0
        public static AskForLeave AddAskForLeave(Uzer u, DateTime startTime, DateTime endTime, DateTime appTime, string reason, string memo)
        {
            AskForLeave afl = new AskForLeave();

            afl.Valid     = true;
            afl.StartTime = startTime;
            afl.EndTime   = endTime;
            afl.AppTime   = appTime;
            afl.Reason    = reason;
            afl.Memo      = memo;
            afl.Status    = (int)AskForLeaveStatus.Applied;

            SmallSimpleOAContext ctx = new SmallSimpleOAContext();

            ctx.Update(u);
            u.AskForLeaves.Add(afl);
            u.LeaveRequests.Add(afl);
            ctx.SaveChanges();
            return(afl);
        }
Пример #8
0
        public async Task SendMessage(string to, string message)
        {
            int?uid = Context.GetHttpContext().Session.GetInt32("uid");

            if (uid != null)
            {
                Uzer u = UserService.FindUserByID((int)uid);
                int  t;
                if (Int32.TryParse(to, out t))
                {
                    MessageService.AddMessage((int)uid, t, message, DateTime.Now);
                }

                string connId = _store.GetConnectionIdByUserId(to);
                if (connId != null)
                {
                    await Clients.Client(connId).SendAsync("ReceiveMessage", uid.ToString(), u.FirstName + " " + u.LastName, message);
                }
            }
        }
Пример #9
0
        public void closeBrowser()
        {
            driver.Close();

            ABase  aBaseObject;
            BChild bChildObject = new BChild();
            string i            = "dfsgrs";
            //aBaseObject.A();


            var varajan = new Human("Vara", "33");
            //var varajan2 = new Human(age: "45", "34", weight: "195");
            //Assert.Greater(100, varajan2.WeightIndex());

            var rudik    = new Customer("asdfsa123123123", "Siroga");
            var andrulik = new Uzer("50");

            andrulik.email = "sesfgsdf";
            andrulik.Age   = 33;
        }
Пример #10
0
        public IActionResult DoNew(string email, string password, string firstName, string lastName, string department, string uzerLevel)
        {
            string result = "0";

            if (email == null ||
                password == null ||
                firstName == null ||
                lastName == null ||
                department == null ||
                uzerLevel == null ||
                email.Trim().Equals("") ||
                password.Trim().Equals("") ||
                firstName.Trim().Equals("") ||
                lastName.Trim().Equals("") ||
                department.Trim().Equals("") ||
                uzerLevel.Trim().Equals("")
                )
            {
                result = "All fields should be filled.";
                return(RedirectToAction("New", "StaffManage", new { r = result }));
            }
            Int32 dep, lev;

            if (!Int32.TryParse(department, out dep) || !Int32.TryParse(uzerLevel, out lev))
            {
                result = "Sorry unknown error, try again please.";
                return(RedirectToAction("New", "StaffManage", new { r = result }));
            }

            Uzer u = UserService.FindUserByEmail(email);

            if (u != null)
            {
                result = "Duplicated user email. Try another email please.";
                return(RedirectToAction("New", "StaffManage", new { r = result }));
            }

            UserService.AddUser(email, password, firstName, lastName, dep, lev);

            return(RedirectToAction("New", "StaffManage", new { r = result }));
        }
        public IActionResult DoNew(string startTime, string endTime, string reason, string memo)
        {
            string result = "0";

            if (startTime == null ||
                endTime == null ||
                reason == null ||
                startTime.Trim().Equals("") ||
                endTime.Trim().Equals("") ||
                reason.Trim().Equals("")
                )
            {
                result = "Fields of 'From', 'To' and 'Reason' should be filled.";
                return(RedirectToAction("New", "AskForLeave", new { r = result }));
            }

            int?uid = HttpContext.Session.GetInt32("uid");

            DateTime st, et;

            if (!DateTime.TryParse(startTime, out st) || !DateTime.TryParse(endTime, out et))
            {
                result = "Time format not valid.";
                return(RedirectToAction("New", "AskForLeave", new { r = result }));
            }
            if (uid == null)
            {
                return(RedirectToAction("Login", "Login"));
            }

            Uzer u = UserService.FindUserByID((int)uid);

            AskForLeave ask = AskForLeaveService.AddAskForLeave(u, st, et, DateTime.Now, reason, memo);

            AskForLeaveService.AskFlowToNextSupervisor(ask);

            return(RedirectToAction("New", "AskForLeave", new { r = result }));
        }
Пример #12
0
        public IActionResult DoLogin(string email, string password)
        {
            //HttpContext.Session.SetInt32("uid", 2007);
            //return RedirectToAction("Home", "Home");

            if (email == null || password == null)
            {
                return(RedirectToAction("Login", "Login", new { pwdNotCorrect = "1" }));
            }

            Uzer user = UserService.FindUserByEmail(email);

            if (user == null)
            {
                return(RedirectToAction("Login", "Login", new { pwdNotCorrect = "1" }));
            }

            string hash = MD5Util.MD5Value(password + user.Salt);

            if (hash.Equals(user.Password))
            {
                string salt = UserPasswordUtil.GenerateSalt();
                user.Salt = salt;
                string newPwd = UserPasswordUtil.GeneratePasswordAfterSalt(password, salt);
                user.Password  = newPwd;
                user.LastLogin = DateTime.Now;
                UserService.UpdateUser(user);
                HttpContext.Session.SetInt32("uid", user.Id);
                HttpContext.Session.SetInt32("ulevel", (int)user.UzerLevel);
                HttpContext.Session.SetString("uname", user.FirstName + " " + user.LastName);
                return(RedirectToAction("Home", "Home"));
            }
            else
            {
                return(RedirectToAction("Login", "Login", new { pwdNotCorrect = "1" }));
            }
        }
        // GET: /<controller>/
        public IActionResult List(string p)
        {
            const int PAGE_SIZE = 10;
            int?      uid       = HttpContext.Session.GetInt32("uid");

            if (uid == null)
            {
                return(RedirectToAction("Login", "Login"));
            }
            int page;

            if (!Int32.TryParse(p, out page))
            {
                page = 1;
            }

            Uzer u = UserService.FindUserByID((int)uid);

            int count = AskForLeaveService.FindCountByApplicant(u);
            int pages = count % PAGE_SIZE == 0 ? count / PAGE_SIZE : count / PAGE_SIZE + 1;

            if (page > pages)
            {
                page = pages;
            }

            if (page <= 0)
            {
                page = 1;
            }

            List <AskForLeave> asks = AskForLeaveService.FindAskForLeaveByApplicantAndPageAndPagesize(u, page, PAGE_SIZE);

            AskForLeaveListViewModel askForLeaveListViewModel = new AskForLeaveListViewModel(asks, pages, page);

            return(View(askForLeaveListViewModel));
        }
Пример #14
0
        public static void AskFlowToNextSupervisor(AskForLeave ask)
        {
            SmallSimpleOAContext ctx = new SmallSimpleOAContext();

            Uzer supervisor = UserService.FindSupervisorByUid(ask.CurrentAt.Id);

            if (supervisor == null)
            {
                ctx.Update(ask);
                ask.Status = (int)AskForLeaveStatus.Approved;
                ask.CurrentAt.LeaveRequests.Remove(ask);
                ctx.SaveChanges();
            }
            else
            {
                ctx.Update(ask);
                ask.Status = (int)AskForLeaveStatus.Reviewing;
                ask.CurrentAt.LeaveRequests.Remove(ask);
                ctx.SaveChanges();
                ctx.Update(supervisor);
                supervisor.LeaveRequests.Add(ask);
                ctx.SaveChanges();
            }
        }
Пример #15
0
        public static int FindCountByApplicant(Uzer u)
        {
            SmallSimpleOAContext ctx = new SmallSimpleOAContext();

            return(ctx.AskForLeave.Count(a => a.Applicant.Equals(u) && a.Valid == true));
        }
Пример #16
0
 public static UserModel ToModel(this Uzer uzer)
 {
     return(new UserModel(uzer));
 }
Пример #17
0
 internal UserModel(Uzer user)
 {
     UserID = user.ID;
     Name   = user.Name;
 }
Пример #18
0
        public static List <AskForLeave> FindAskForLeaveByCurrentAt(Uzer u)
        {
            SmallSimpleOAContext ctx = new SmallSimpleOAContext();

            return(ctx.AskForLeave.Where(a => a.CurrentAt.Equals(u) && a.Valid == true).ToList());
        }
Пример #19
0
        public static List <AskForLeave> FindAskForLeaveByCurrentAtAndPageAndPagesize(Uzer u, int page, int size)
        {
            SmallSimpleOAContext ctx = new SmallSimpleOAContext();

            return(ctx.AskForLeave.Where(a => a.CurrentAt.Equals(u) && a.Valid == true).OrderByDescending(a => a.AppTime).Skip((page - 1) * size).Take(size).ToList());
        }
Пример #20
0
        public IActionResult Attendance(string d)
        {
            int?uid = HttpContext.Session.GetInt32("uid");

            if (uid == null)
            {
                return(RedirectToAction("Login", "Login"));
            }
            Uzer user = UserService.FindUserByID((int)uid);


            if (user.Department == null)
            {
                return(Content("You do not have a department"));
            }

            Department userDep = DepartmentService.FindDepartmentByID((int)user.Department);

            List <Department> deps   = new List <Department>();
            Department        selDep = null;
            List <Uzer>       staffs = new List <Uzer>();


            //hard code, a little bit ugly
            if (userDep.Name.Equals("HR"))
            {
                //HR department can check other guys' attendance.
                deps = DepartmentService.FindDepartment();
                int depId = 0;
                Int32.TryParse(d, out depId);

                foreach (Department department in deps)
                {
                    if (department.Id == depId)
                    {
                        selDep = department;
                        break;
                    }
                }
                if (selDep == null && deps.Count > 0)
                {
                    selDep = deps[0];
                }


                if (selDep.Name.Equals("HR"))
                {
                    //user of HR department can only check the attendance of the staffs whose level is lower than him/her
                    staffs = UserService.FindUserByDepartmentAndUnderLevel((int)user.Department, (int)user.UzerLevel);
                    staffs.Insert(0, user);
                }
                else
                {
                    staffs = UserService.FindUserByDepartment(selDep.Id);
                }
            }
            else
            {
                //other guys can only check the attendance of the staffs with lower lever in the same department
                selDep = userDep;
                staffs = UserService.FindUserByDepartmentAndUnderLevel((int)user.Department, (int)user.UzerLevel);
                staffs.Insert(0, user);
            }


            AttendanceAttendanceViewModel attendanceAttendanceViewModel = new AttendanceAttendanceViewModel(deps, staffs, selDep);

            return(View(attendanceAttendanceViewModel));
        }