Ejemplo n.º 1
0
        public string AllUser(int mode)
        {
            Validator validator = new Validator();
            if (! validator.MatchRule(mode + "", "required", "mode"))
            {
                return view.Error(validator.GetDetail());
            }

            var result = userRepo.GetAllUserByMode(mode);

            return view.Show(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Remove a absence record which has not been apply yet
        /// </summary>
        /// <returns></returns>
        public string Destroy(int id)
        {
            Validator validator = new Validator();
            if (!validator.MatchRule(id.ToString(), "required", "reasonId"))
            {
                return absenceView.Error(validator.GetDetail());
            }

            bool ret = absenceReasonRepo.Destroy(id, Auth.User().Id);

            return ret ? absenceView.Success() : absenceView.Error();
        }
Ejemplo n.º 3
0
        public string Destroy(int id)
        {
            Validator validator = new Validator();
            // Validate the user input here.
            // Validate the user input here.
            if (!validator.MatchRule(id + "", "required", "id"))
            {
                return resultSetView.Error(validator.GetDetail());
            }

            bool ret = attendanceRepo.Destroy(id, Auth.User().Id);
            return ret ? resultSetView.Success() : resultSetView.Error();
        }
Ejemplo n.º 4
0
        public string Destroy(int id, int mode)
        {
            Validator validator = new Validator();
            // Validate the user input here.
            if (!validator.Make(new string[] { id + "", mode + "" },
                new string[] { "required", "required"},
                new string[] { "userId", "mode" }))
            {
                return view.Error(validator.GetDetail());
            }

            userRepo.Destroy(id, mode);

            return view.Success();
        }
Ejemplo n.º 5
0
        public string ResetPassword(int id, int mode)
        {
            Validator validator = new Validator();
            if (!validator.Make(new string[] { id + "", mode + "" },
                new string[] { "required", "required" },
                new string[] { "userId", "mode" }))
            {
                return view.Error(validator.GetDetail());
            }

            string pwd = Guard.GenerateRandomPassword();
            bool bRet = userRepo.ResetPassword(id, pwd, mode);

            return bRet ? view.Show(pwd) : view.Error();
        }
Ejemplo n.º 6
0
        public string CreateDispatch(int id)
        {
            GenericView view = new GenericView();
            DispatchRepository dispatchRepo = new DispatchRepository();

            Validator validator = new Validator();
            if (!validator.MatchRule(id + "", "required", "id"))
            {
                return view.Error(validator.GetDetail());
            }

            bool Ret = dispatchRepo.JoinCourse(Auth.User().Id, id);

            return Ret ? view.Success() : view.Error();
        }
Ejemplo n.º 7
0
        public string Update(int id, string name, string desc)
        {
            Validator validator = new Validator();

            // Validate the user input here.
            if (!validator.Make(new string[] { id + "", name, desc },
                new string[] { "required", "required", "required" },
                new string[] { "id", "name", "desc" }))
            {
                return view.Error(validator.GetDetail());
            }

            bool bRet = majorRepo.Update(id, name, desc);

            return bRet ? view.Success() : view.Error();
        }
Ejemplo n.º 8
0
        public string Destroy(int id)
        {
            Validator validator = new Validator();

            // Validate the user input here.
            if (!validator.Make(new string[] { id + "" },
                new string[] { "required" },
                new string[] { "id" }))
            {
                return view.Error(validator.GetDetail());
            }

            bool bRet = majorRepo.Destroy(id);

            return bRet ? view.Success() : view.Error();
        }
Ejemplo n.º 9
0
        public string RemoveDispatch(string id)
        {
            GenericView view = new GenericView();
            DispatchRepository dispatchRepo = new DispatchRepository();

            Validator validator = new Validator();
            if (!validator.MatchRule(id, "required", "id"))
            {
                return view.Error(validator.GetDetail());
            }

            string[] idArr = id.Split(',');
            bool Ret = dispatchRepo.RemoveCourseList(Auth.User().Id, Array.ConvertAll(idArr, int.Parse));

            return Ret ? view.Success() : view.Error();
        }
Ejemplo n.º 10
0
        public string Profile(int id, int mode)
        {
            UserView view = new UserView();
            Validator validator = new Validator();
            // Validate the user input here.
            if (!validator.Make(new string[] { id + "", mode + "" },
                new string[] { "required", "required" },
                new string[] { "userId", "mode" }))
            {
                return view.Error(validator.GetDetail());
            }

            return userRepo.Exists(id, mode) ?
                view.Show(userRepo.CurrentUser) :
                view.Error();
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Record a student who absent on the course
        /// </summary>
        /// <param name="type"></param>
        /// <param name="studentId"></param>
        /// <param name="dispatchId"></param>
        /// <returns></returns>
        public string AddStudentAbsence(string type, int studentId, int dispatchId)
        {
            Validator validator = new Validator();
            // Validate the user input here.
            if (!validator.Make(new string[] { type, studentId + "", dispatchId + "" },
                new string[] { "required", "required", "required" },
                new string[] { "type", "studentId", "dispatchId" }))
            {
                return resultSetView.Error(validator.GetDetail());
            }

            AbsenceRepository absenceRepo = new AbsenceRepository();

            bool ret = absenceRepo.AddStudentAbsence(type, studentId, dispatchId, Auth.User().Id);

            return ret ? resultSetView.Success() : resultSetView.Error();
        }
Ejemplo n.º 12
0
        public string OnRegister(string email, string user, string pass)
        {
            RegisterView view = new RegisterView();
            Validator validator = new Validator();

            // Validate the user input here.
            if (!validator.Make(new string[] { email, user, pass },
                new string[] { "email", "minLength:1", "minLength:8" },
                new string[] { "email", "username", "password" }))
            {
                return view.Error(validator.GetDetail());
            }

            UserRepository userRepo = new UserRepository();
            int result = userRepo.Register(email, user, pass, 0);

            return view.Show(result);
        }
Ejemplo n.º 13
0
        public string OnLogin(string email, string pass, int mode)
        {
            LoginView view = new LoginView();
            Validator validator = new Validator();

            // Validate the user input here.
            if (!validator.MatchRule(email, "email", "email") )
            {
                return view.Error(validator.GetDetail());
            }

            UserRepository userRepo = new UserRepository();
            if (userRepo.Login(email, pass, mode))
            {
                return view.Show(userRepo.SessionId);
            }

            return view.Error();
        }
Ejemplo n.º 14
0
        public string Store(string weekday, DateTime at,
            int limit,
            int teacherId, int courseId, int roomId)
        {
            Validator validator = new Validator();

            // Validate the user input here.
            if (!validator.Make(new string[] { weekday, at.ToString(), limit + "",
                            teacherId + "", courseId + "", roomId + ""},
                new string[] { "required", "required", "required", "required", "required", "required" },
                new string[] { "weekday", "at", "limit", "teacherId", "courseId", "roomId" }))
            {
                return view.Error(validator.GetDetail());
            }

            bool bRet = dispatchMgrRepo.Create(weekday, at, limit, teacherId, courseId, roomId);

            return bRet ? view.Success() : view.Error();
        }
Ejemplo n.º 15
0
        public string Update(int id, int mode, 
            string name, string avatar, string cellphone)
        {
            Validator validator = new Validator();
            // Validate the user input here.
            if (!validator.Make(new string[] { id + "", mode + "", name},
                new string[] { "required", "required", "required" },
                new string[] { "userId", "mode", "username" }))
            {
                return view.Error(validator.GetDetail());
            }

            bool bRet = false;
            if (userRepo.Exists(id, mode))
            {
                userRepo.Update(userRepo.CurrentUser, name, avatar, cellphone, null);
                bRet = true;
            }

            return bRet ? view.Success() : view.Error();
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Add a new absence record
        /// </summary>
        /// <returns></returns>
        public string Store(string reason, int courseId)
        {
            Validator validator = new Validator();
            if (! validator.Make(new string[] { reason, courseId + "" },
                new string[] { "required", "required" },
                new string[] { "reason", "courseId" }))
            {
                return absenceView.Error(validator.GetDetail());
            }

            bool ret = absenceReasonRepo.Create(reason, courseId, Auth.User().Id);

            return ret ? absenceView.Success() : absenceView.Error();
        }
Ejemplo n.º 17
0
        public string Update(string name, string avatar, string cellphone, 
            string newPwd, string pwdConfirm, string originPwd)
        {
            Validator validator = new Validator();
            // Validate the user input here.
            if (!validator.Make(new string[] { name, originPwd, newPwd, pwdConfirm },
                new string[] { "required", "required", "match:newPassword_confirmation", "" },
                new string[] { "username", "password", "newPassword", "newPassword_confirmation" }))
            {
                return userView.Error(validator.GetDetail());
            }

            UserRepository userRepo = new UserRepository();

            UserEntity user = Auth.User();
            if (! userRepo.Attempt(user.Email, originPwd, user.Mode))
            {
                return userView.Error();
            }

            userRepo.Update(user, name, avatar, cellphone, newPwd);

            return userView.Success();
        }
Ejemplo n.º 18
0
        public string Store(string email, string user, string pass, int mode)
        {
            RegisterView view = new RegisterView();
            Validator validator = new Validator();

            // Validate the user input here.
            if (!validator.Make(new string[] { email, user, pass, mode + "" },
                new string[] { "email", "required", "required", "required" },
                new string[] { "email", "username", "password", "mode" }))
            {
                return view.Error(validator.GetDetail());
            }

            int result = userRepo.Register(email, user, pass, mode);

            return view.Show(result);
        }
Ejemplo n.º 19
0
        public string Update(int id, string weekday, DateTime at, int limit,
            int teacherId, int roomId)
        {
            Validator validator = new Validator();

            // Validate the user input here.
            if (!validator.Make(new string[] { id + "", weekday, at.ToString(), limit + "" },
                new string[] { "required", "required", "required", "required" },
                new string[] { "id", "weekday", "at", "limit" }))
            {
                return view.Error(validator.GetDetail());
            }
            // Enable the course by default
            bool bRet = dispatchMgrRepo.Update(id, weekday, at, limit, teacherId, roomId, true);

            return bRet ? view.Success() : view.Error();
        }
Ejemplo n.º 20
0
        public string Store(int dispatchId, int absence)
        {
            Validator validator = new Validator();
            // Validate the user input here.
            if (! validator.Make(new string[] { dispatchId + "", absence + "" },
                new string[] { "required", "required|min:0" },
                new string[] { "dispatchId", "absence" }))
            {
                return resultSetView.Error(validator.GetDetail());
            }

            bool ret = attendanceRepo.Create(dispatchId, absence, Auth.User().Id);

            return ret ? resultSetView.Success() : resultSetView.Error();
        }