コード例 #1
0
        public ActionResult Delete(long id)
        {
            var canedit = false;
            var usr     = repository.GetUser(id);

            if (usr != null)
            {
                canedit = usr.GetCanEdit(sessionid.Value, auth);
            }
            if (!canedit)
            {
                return(SendJsonNoPermission());
            }

            try
            {
                repository.DeleteUser(id, sessionid.Value);

                LuceneUtil.DeleteLuceneIndex(id);
            }
            catch (Exception ex)
            {
                return(SendJsonErrorResponse(ex));
            }
            return(Json("User deleted successfully".ToJsonOKMessage()));
        }
コード例 #2
0
ファイル: searchController.cs プロジェクト: seanlinmt/tradelr
        public ActionResult Index(string q, int?page)
        {
            var template = CreateLiquidTemplate("search", "Search");

            template.InitContentTemplate("templates/search.liquid");
            var searchresult = new Search();

            template.AddParameters("search", searchresult);
            if (!string.IsNullOrEmpty(q))
            {
                searchresult.performed = true;
                var ids = new List <string>();
                try
                {
                    var analyzer = new StandardAnalyzer(Version.LUCENE_29);
                    using (var searcher = new IndexSearcher(LuceneUtil.GetDirectoryInfo(LuceneIndexType.PRODUCTS, accountSubdomainName), true))
                    {
                        var queryparser = new MultiFieldQueryParser(Version.LUCENE_29, new[] { "sku", "title", "category", "details" }, analyzer);
                        var query       = queryparser.Parse(q);
                        var hits        = searcher.Search(query);

                        for (int i = 0; i < hits.Length(); i++)
                        {
                            Document doc = hits.Doc(i);
                            ids.Add(doc.Get("id"));
                        }
                    }
                }
                catch (Exception ex)
                {
                    Syslog.Write(ex);
                }

                var products = repository.GetProducts(subdomainid.Value).Where(x => ids.Contains(x.id.ToString())).IsActive();

                searchresult.terms   = q;
                searchresult.results = products.ToLiquidModel(sessionid, "").ToList();
            }

            // return first page if we don't have page value but just return products
            if (page.HasValue)
            {
                template.AddRegisters("current_page", page.Value);
            }

            return(Content(template.Render()));
        }
コード例 #3
0
        public ActionResult Save(Gender?child_sex, int enrol_year, int school, int year, string child_name,
                                 string child_race, string child_dialect, string child_address,
                                 int child_dob_day, int child_dob_month, int child_dob_year, string child_pob,
                                 string child_citizenship, string child_birthcertno, string child_passportnric, bool child_bumi,
                                 string child_religion, HttpPostedFileBase child_photo, string child_previous_school,
                                 HttpPostedFileBase child_report, string child_previous_class, string child_leaving_reason, bool?child_handicap,
                                 bool?child_learning_problems, string child_disability_details,
                                 // parents fields
                                 string parent1_designation, string parent1_name, string parent1_passportnric, string parent1_occupation,
                                 string parent1_employer, string parent1_race,
                                 string parent1_dialect, bool?parent1_bumi, string parent1_marital, string parent1_citizenship,
                                 string parent1_religion, string parent1_officephone, string parent1_homephone, string parent1_handphone,
                                 string parent1_email, string parent1_address,
                                 string parent2_designation, string parent2_name, string parent2_passportnric, string parent2_occupation,
                                 string parent2_employer, string parent2_race,
                                 string parent2_dialect, bool?parent2_bumi, string parent2_marital, string parent2_citizenship,
                                 string parent2_religion, string parent2_officephone, string parent2_homephone, string parent2_handphone,
                                 string parent2_email, string parent2_address,
                                 // guardian fields
                                 string guardian_designation, string guardian_name, Gender?guardian_sex,
                                 string guardian_passportnric, string guardian_occupation, string guardian_employer, string guardian_race,
                                 string guardian_dialect, bool?guardian_bumi, string guardian_marital, string guardian_citizenship,
                                 string guardian_religion, string guardian_officephone, string guardian_homephone, string guardian_handphone,
                                 string guardian_email, string guardian_address,
                                 // other siblings
                                 string[] sibling_name, string[] sibling_nric,
                                 // other
                                 GuardianType?applicant_relationship)
        {
            var admissionHandler = new Admission(repository);
            var result           = admissionHandler.Process(child_sex.HasValue?child_sex.Value:Gender.MALE, enrol_year, school, year, child_name,
                                                            child_race, child_dialect, child_address,
                                                            child_dob_day, child_dob_month, child_dob_year, child_pob,
                                                            child_citizenship, child_birthcertno, child_passportnric, child_bumi,
                                                            child_religion, child_photo, child_previous_school,
                                                            child_report, child_previous_class, child_leaving_reason,
                                                            child_handicap,
                                                            child_learning_problems, child_disability_details,
                                                            parent1_designation, parent1_name, parent1_passportnric,
                                                            parent1_occupation, parent1_employer, parent1_race,
                                                            parent1_dialect, parent1_bumi, parent1_marital, parent1_citizenship,
                                                            parent1_religion, parent1_officephone, parent1_homephone,
                                                            parent1_handphone,
                                                            parent1_email, parent1_address,
                                                            parent2_designation, parent2_name, parent2_passportnric,
                                                            parent2_occupation, parent2_employer, parent2_race,
                                                            parent2_dialect, parent2_bumi, parent2_marital, parent2_citizenship,
                                                            parent2_religion, parent2_officephone, parent2_homephone,
                                                            parent2_handphone,
                                                            parent2_email, parent2_address,
                                                            guardian_designation, guardian_name, guardian_sex,
                                                            guardian_passportnric, guardian_occupation, guardian_employer,
                                                            guardian_race,
                                                            guardian_dialect, guardian_bumi, guardian_marital,
                                                            guardian_citizenship,
                                                            guardian_religion, guardian_officephone, guardian_homephone,
                                                            guardian_handphone,
                                                            guardian_email, guardian_address, sibling_name, sibling_nric,
                                                            applicant_relationship, false);

            Syslog.Write(ErrorLevel.INFORMATION, "Online admission submitted: " + result);

            if (result != AdmissionStatus.SUCCESS)
            {
                switch (result)
                {
                case AdmissionStatus.DUPLICATEEMAIL:
                    return(Redirect("/admission#emailexist"));

                case AdmissionStatus.NOEMAIL:
                    return(Redirect("/admission#noemail"));

                case AdmissionStatus.NOID:
                    return(Redirect("/admission#noid"));

                case AdmissionStatus.INCORRECT_NRIC_PASSPORT:
                    return(Redirect("/admission#incorrectnricpassport"));

                case AdmissionStatus.UNKNOWN:
                    return(Redirect("/admission#fail"));

                default:
                    return(Redirect("/admission#fail"));
                }
            }

            // send email with further instructions
            if (admissionHandler.father != null && !string.IsNullOrEmpty(admissionHandler.father.email))
            {
                var email = new EmailRegistrationViewModel();
                email.applicantName = admissionHandler.father.ToName();
                email.email         = admissionHandler.father.email;
                email.password      = admissionHandler.password_father;
                this.SendEmail(EmailViewType.REGISTRATION,
                               email,
                               " School Online Enrolment", email.email, admissionHandler.father.ToName());
                LuceneUtil.UpdateLuceneIndex(admissionHandler.father);
            }
            if (admissionHandler.mother != null && !string.IsNullOrEmpty(admissionHandler.mother.email))
            {
                var email = new EmailRegistrationViewModel();
                email.applicantName = admissionHandler.mother.ToName();
                email.email         = admissionHandler.mother.email;
                email.password      = admissionHandler.password_mother;
                this.SendEmail(EmailViewType.REGISTRATION,
                               email,
                               " School Online Enrolment", email.email, admissionHandler.mother.ToName());
                LuceneUtil.UpdateLuceneIndex(admissionHandler.mother);
            }
            if (admissionHandler.guardian != null && !string.IsNullOrEmpty(admissionHandler.guardian.email))
            {
                var email = new EmailRegistrationViewModel();
                email.applicantName = admissionHandler.guardian.ToName();
                email.email         = admissionHandler.guardian.email;
                email.password      = admissionHandler.password_guardian;
                this.SendEmail(EmailViewType.REGISTRATION,
                               email,
                               " School Online Enrolment", email.email, admissionHandler.guardian.ToName());
                LuceneUtil.UpdateLuceneIndex(admissionHandler.guardian);
            }

            new Thread(() =>
            {
                using (var repo = new Repository())
                {
                    var pplToNotify = repo.GetRegistrationNotifications();
                    foreach (var registrationNotification in pplToNotify)
                    {
                        var usr = registrationNotification.user;
                        if (!string.IsNullOrEmpty(usr.email))
                        {
                            EmailHelper.SendEmail(EmailViewType.REGISTRATION_NOTIFICATION,
                                                  null,
                                                  "New  School Online Enrolment",
                                                  usr.email,
                                                  usr.ToName());
                        }
                    }
                }
            }).Start();

            LuceneUtil.UpdateLuceneIndex(admissionHandler.student);

            return(Redirect("/admission#success"));
        }
コード例 #4
0
        public ActionResult Save(Gender child_sex, int enrol_year, int school, int year, string child_name,
                                 string child_race, string child_dialect, string child_address,
                                 int child_dob_day, int child_dob_month, int child_dob_year, string child_pob,
                                 string child_citizenship, string child_birthcertno, string child_passportnric, bool child_bumi,
                                 string child_religion, HttpPostedFileBase child_photo, string child_previous_school,
                                 HttpPostedFileBase child_report, string child_previous_class, string child_leaving_reason, bool?child_handicap,
                                 bool?child_learning_problems, string child_disability_details,
                                 // parents fields
                                 string parent1_designation, string parent1_name, string parent1_passportnric,
                                 string parent1_occupation, string parent1_employer, string parent1_race,
                                 string parent1_dialect, bool?parent1_bumi, string parent1_marital, string parent1_citizenship,
                                 string parent1_religion, string parent1_officephone, string parent1_homephone, string parent1_handphone,
                                 string parent1_email, string parent1_address,
                                 string parent2_designation, string parent2_name, string parent2_passportnric,
                                 string parent2_occupation, string parent2_employer, string parent2_race,
                                 string parent2_dialect, bool?parent2_bumi, string parent2_marital, string parent2_citizenship,
                                 string parent2_religion, string parent2_officephone, string parent2_homephone, string parent2_handphone,
                                 string parent2_email, string parent2_address,
                                 // guardian fields
                                 string guardian_designation, string guardian_name, Gender?guardian_sex,
                                 string guardian_passportnric, string guardian_occupation, string guardian_employer, string guardian_race,
                                 string guardian_dialect, bool?guardian_bumi, string guardian_marital, string guardian_citizenship,
                                 string guardian_religion, string guardian_officephone, string guardian_homephone, string guardian_handphone,
                                 string guardian_email, string guardian_address,
                                 // other siblings
                                 string[] sibling_name, string[] sibling_nric)
        {
            var admissionHandler = new Admission(repository);

            var result = admissionHandler.Process(child_sex, enrol_year, school, year, child_name,
                                                  child_race, child_dialect, child_address,
                                                  child_dob_day, child_dob_month, child_dob_year, child_pob,
                                                  child_citizenship, child_birthcertno, child_passportnric, child_bumi,
                                                  child_religion, child_photo, child_previous_school,
                                                  child_report, child_previous_class, child_leaving_reason,
                                                  child_handicap,
                                                  child_learning_problems, child_disability_details,
                                                  parent1_designation, parent1_name, parent1_passportnric,
                                                  parent1_occupation, parent1_employer, parent1_race,
                                                  parent1_dialect, parent1_bumi, parent1_marital, parent1_citizenship,
                                                  parent1_religion, parent1_officephone, parent1_homephone,
                                                  parent1_handphone,
                                                  parent1_email, parent1_address,
                                                  parent2_designation, parent2_name, parent2_passportnric,
                                                  parent2_occupation, parent2_employer, parent2_race,
                                                  parent2_dialect, parent2_bumi, parent2_marital, parent2_citizenship,
                                                  parent2_religion, parent2_officephone, parent2_homephone,
                                                  parent2_handphone,
                                                  parent2_email, parent2_address,
                                                  guardian_designation, guardian_name, guardian_sex,
                                                  guardian_passportnric, guardian_occupation, guardian_employer,
                                                  guardian_race,
                                                  guardian_dialect, guardian_bumi, guardian_marital,
                                                  guardian_citizenship,
                                                  guardian_religion, guardian_officephone, guardian_homephone,
                                                  guardian_handphone,
                                                  guardian_email, guardian_address, sibling_name, sibling_nric,
                                                  null, true);

            if (result != AdmissionStatus.SUCCESS)
            {
                switch (result)
                {
                case AdmissionStatus.DUPLICATEEMAIL:
                    ViewData["message"] =
                        "The email address you have specified is currently in use. Please specify a different email address.";
                    break;

                case AdmissionStatus.NOEMAIL:
                    ViewData["message"] =
                        "No email was specified. The email of either the parents or guardian is required to complete your online registration.";
                    break;

                case AdmissionStatus.NOID:
                    ViewData["message"] = "You must specify a NRIC or Passport Number.";
                    break;

                case AdmissionStatus.INCORRECT_NRIC_PASSPORT:
                    ViewData["message"] = "Invalid NRIC or Passport Number.";
                    break;

                default:
                    ViewData["message"] =
                        "An error has occurred while processing your registration. We are currently looking into the issue.";
                    break;
                }
                return(View("Error"));
            }

            LuceneUtil.UpdateLuceneIndex(admissionHandler.student);

            return(Redirect("/enrolment"));
        }
コード例 #5
0
        public ActionResult Save(long?id, string designation, string name, string email, Schools?uschool,
                                 int[] day, int[] year, int?[] school, int?[] schoolclass, string[] subject,
                                 long[] parent, int[] parentrel, long[] child, int[] childrel,
                                 UserGroup?ugroup, long?thumbnailid, int[] start_hour, int[] start_minutes, int[] end_hour, int[] end_minutes,
                                 string race, string dialect, int dob_day, int dob_month, int?dob_year,
                                 string pob, string citizenship, string birthcertno, string passport, bool bumi, string nric_new,
                                 string homephone, string cellphone, string address, string religion, Gender gender, MaritalStatus marital_status,
                                 string occupation, string officephone, string employer, string notes,
                                 // staff stuff
                                 string staff_socso, string staff_salary_grade, string staff_epf, string staff_income_tax,
                                 string staff_spouse_phone_cell, string staff_spouse_phone_office, string staff_spouse_employer_address,
                                 string staff_spouse_employer, string staff_spouse_name
                                 )
        {
            if (email == null)
            {
                email = "";
            }
            email = email.Trim().ToLower();

            // TODO check that staff / student id is unique
            var emailchanged = true;
            var u            = new user();

            if (id.HasValue)
            {
                u = repository.GetUser(id.Value);
                if (u == null)
                {
                    return(Json("Unable to find user".ToJsonFail()));
                }
                if (u.email == email)
                {
                    emailchanged = false;
                }
            }
            else
            {
                // can we create new user?
                if (!auth.perms.HasFlag(Permission.USERS_CREATE))
                {
                    return(SendJsonNoPermission());
                }

                // dont allow change of usergroups for the moment because there are specific actions
                // that need to be performed when a certain type of user is added
                // only set when user is created
                if (ugroup.HasValue)
                {
                    u.usergroup   = (int)ugroup.Value;
                    u.permissions = (long)UserHelper.GetDefaultPermission(ugroup.Value);
                }
                u.settings = (int)UserSettings.NONE;
            }

            // check that email is unique
            if (!string.IsNullOrEmpty(email))
            {
                var duplicate = repository.GetUsers().SingleOrDefault(x => string.Compare(x.email, email) == 0);
                if (duplicate != null && duplicate.id != u.id)
                {
                    return(Json("Email address is already in use".ToJsonFail()));
                }
            }

            // check that nric is unique
            if (!string.IsNullOrEmpty(nric_new))
            {
                var duplicate = repository.GetUsers().FirstOrDefault(x => string.Compare(x.nric_new, nric_new) == 0);
                if (duplicate != null && duplicate.id != u.id)
                {
                    return(Json("NRIC is already in use".ToJsonFail()));
                }
            }

            if (uschool.HasValue)
            {
                u.schoolid = uschool.Value.ToInt();
            }

            u.gender      = gender.ToString();
            u.designation = designation;
            u.name        = name;
            u.email       = email;
            u.photo       = thumbnailid;
            u.race        = race;
            u.dialect     = dialect;
            if (dob_year.HasValue)
            {
                try
                {
                    u.dob = new DateTime(dob_year.Value, dob_month, dob_day);
                }
                catch
                {
                    return(Json("Invalid Date of Birth".ToJsonFail()));
                }
            }
            u.pob            = pob;
            u.citizenship    = citizenship;
            u.birthcertno    = birthcertno;
            u.passportno     = passport;
            u.isbumi         = bumi;
            u.nric_new       = nric_new;
            u.phone_home     = homephone;
            u.phone_cell     = cellphone;
            u.address        = address;
            u.religion       = religion;
            u.notes          = notes;
            u.marital_status = marital_status.ToString();

            if (!ugroup.HasValue)
            {
                ugroup = (UserGroup)u.usergroup;
            }

            switch (ugroup)
            {
            case UserGroup.GUARDIAN:
                if (u.user_parents == null)
                {
                    u.user_parents = new user_parent();
                }
                if (!string.IsNullOrEmpty(employer))
                {
                    employer = employer.Trim();
                }
                u.user_parents.employer     = employer;
                u.user_parents.phone_office = officephone;
                u.user_parents.occupation   = occupation;

                if (child != null)
                {
                    for (int i = 0; i < child.Length; i++)
                    {
                        var student = new students_guardian();
                        student.studentid = child[i];
                        student.type      = Convert.ToByte(childrel[i]);
                        u.students_guardians1.Add(student);
                    }
                }
                break;

            case UserGroup.HEAD:
            case UserGroup.TEACHER:
                if (schoolclass != null)
                {
                    for (int i = 0; i < schoolclass.Length; i++)
                    {
                        var assigned = new classes_teachers_allocated();
                        assigned.day  = day[i];
                        assigned.year = year[i];
                        if (school[i] == null)
                        {
                            return(Json("School not specified".ToJsonFail()));
                        }
                        assigned.schoolid = school[i].Value;
                        if (schoolclass[i] == null)
                        {
                            return(Json("Class is not specified".ToJsonFail()));
                        }
                        assigned.classid = schoolclass[i].Value;

                        // allow NULL subject for kindy classes as they don't have subjects
                        if (subject != null && !string.IsNullOrEmpty(subject[i]))
                        {
                            assigned.subjectid = long.Parse(subject[i]);
                        }

                        assigned.time_start = new TimeSpan(start_hour[i], start_minutes[i], 0);
                        assigned.time_end   = new TimeSpan(end_hour[i], end_minutes[i], 0);

                        // check that period is not already assigned
                        var period = repository.GetClassPeriod(assigned.year, assigned.day, assigned.schoolid, assigned.classid,
                                                               assigned.time_start, assigned.time_end);
                        if (period != null)
                        {
                            // only give warning if class allocated is owner's own as we want to allow
                            // assistants to share the same period
                            if (id.HasValue && period.teacherid == id.Value)
                            {
                                return
                                    (Json(
                                         string.Format(
                                             "A class from {0} to {1} has already been assigned to {2} for {3}",
                                             period.time_start,
                                             period.time_end,
                                             period.user.ToName(),
                                             period.subject == null ? "" : period.subject.name).
                                         ToJsonFail()));
                            }
                        }
                        u.classes_teachers_allocateds.Add(assigned);
                    }
                }
                break;

            case UserGroup.STUDENT:
                if (schoolclass != null)
                {
                    for (int i = 0; i < schoolclass.Length; i++)
                    {
                        var assigned = new classes_students_allocated();
                        assigned.year = year[i];
                        if (schoolclass[i] == null)
                        {
                            return(Json("Class is not specified".ToJsonFail()));
                        }
                        assigned.classid = schoolclass[i].Value;

                        // check that class is not already assigned
                        var exist =
                            u.classes_students_allocateds.SingleOrDefault(x => x.year == assigned.year);
                        if (exist == null)
                        {
                            u.classes_students_allocateds.Add(assigned);
                        }
                        else
                        {
                            return(Json(string.Format("A class for the year {0} has already been allocated.", exist.year).ToJsonFail()));
                        }
                    }
                }
                if (parent != null)
                {
                    for (int i = 0; i < parent.Length; i++)
                    {
                        var guardian = new students_guardian();
                        guardian.parentid = parent[i];
                        guardian.type     = Convert.ToByte(parentrel[i]);
                        u.students_guardians.Add(guardian);
                    }

                    // validate not more than 1 mother or father
                    if (u.students_guardians.Count(x => x.type.HasValue && x.type == GuardianType.FATHER.ToInt()) > 1)
                    {
                        return(Json("Cannot add more than 1 father".ToJsonFail()));
                    }

                    if (u.students_guardians.Count(x => x.type.HasValue && x.type == GuardianType.MOTHER.ToInt()) > 1)
                    {
                        return(Json("Cannot add more than 1 mother".ToJsonFail()));
                    }

                    if (u.students_guardians.Count(x => x.type.HasValue && x.type == GuardianType.GUARDIAN.ToInt()) > 1)
                    {
                        return(Json("Cannot add more than 1 guardian".ToJsonFail()));
                    }
                }
                break;
            } // end switch

            // do STAFF only actions
            if (UserSuperGroups.STAFF.HasFlag(ugroup.Value) &&
                UserSuperGroups.SUPERSTAFF.HasFlag(auth.group))
            {
                if (u.user_staffs == null)
                {
                    u.user_staffs = new user_staff();
                }
                u.user_staffs.socso                   = staff_socso;
                u.user_staffs.salary_grade            = staff_salary_grade;
                u.user_staffs.epf                     = staff_epf;
                u.user_staffs.income_tax              = staff_income_tax;
                u.user_staffs.spouse_phone_cell       = staff_spouse_phone_cell;
                u.user_staffs.spouse_phone_work       = staff_spouse_phone_office;
                u.user_staffs.spouse_employer_address = staff_spouse_employer_address;
                u.user_staffs.spouse_employer         = staff_spouse_employer;
                u.user_staffs.spouse_name             = staff_spouse_name;
            }

            // check if we can actually edit
            var canedit = u.GetCanEdit(sessionid.Value, auth);

            if (!canedit)
            {
                return(SendJsonNoPermission());
            }

            if (!id.HasValue)
            {
                repository.AddUser(u);
            }

            // log changes
            EntityLogging.LogChanges(db, u, u.name, sessionid.Value);

            try
            {
                repository.Save();
            }
            catch (Exception ex)
            {
                return(SendJsonErrorResponse(ex));
            }

            // try to update school
            if (!u.schoolid.HasValue)
            {
                u.schoolid = u.GetNewSchoolID();
            }
            repository.Save();

            // resend password email if email has been changed OR a user has been created
            if (emailchanged && !string.IsNullOrEmpty(email))
            {
                var password = tradelr.Crypto.Utility.GetRandomString(uppercase: true);
                var hash     = Utility.GeneratePasswordHash(email, password);
                u.passwordhash = hash;
                u.settings     = u.SetFlag(UserSettings.PASSWORD_RESET);
                repository.Save();
                var credentials = new UserCredentials {
                    password = password, email = email
                };
                this.SendEmailNow(EmailViewType.PASSWORD_RESET, credentials, "New Account Password", email, u.ToName());
            }

            LuceneUtil.UpdateLuceneIndex(u);

            var jsonmodel = "User successfully saved".ToJsonOKMessage();

            jsonmodel.data = u.id;

            return(Json(jsonmodel));
        }
コード例 #6
0
 public static QueryContext NumericRange(string key, Number from, Number to, bool includeFrom, bool includeTo)
 {
     return(new QueryContext(LuceneUtil.rangeQuery(key, from, to, includeFrom, includeTo)));
 }