Example #1
0
        public HttpResponseMessage NewOngoingTask([FromBody] dynamic data)
        {
            SLW_DatabaseInfo db     = new SLW_DatabaseInfo();
            KeyDetail        detail = db.GetKeyDetail((string)data.access_key);

            if (detail.data_present)
            {
                UnassignedTask unassigned = db.GetSingleUnassignedTask((string)data.application_id);
                db.DeleteUnassignedTask((string)data.application_id);

                UserDetails userDetailsAdmin = db.GetUserDetails(detail.username);
                db.NewOngoingTask((string)data.application_id, (string)data.assigned_to, unassigned.username, (string)data.status, unassigned.created_date_raw, userDetailsAdmin.fullname, userDetailsAdmin.username);
                db.UpdateApplicationStatus((string)data.application_id, Commons.Constants.PENDING_TYPE, DateTime.Now);
                OngoingTask ongoing     = db.GetSingleOngoingTask((string)data.application_id);
                UserDetails userDetails = db.GetUserDetails(ongoing.assigned_to);
                ongoing.assigned_to = userDetails.fullname;
                db.SaveActivity(new UserActivity(detail.username, Commons.Constants.ACTIVITY_NEW_ONGOING, (string)data.application_id, (string)data.assigned_to, 1));
                Form form = db.GetApplication((string)data.application_id);

                Email.Send(userDetails.email, "New Type Approval Application", "Type approval application " + form.application_id + " for Device with Model number " + form.product_identification + " from " + ongoing.submitted_by + " is assigned to you for processing.");
                return(Request.CreateResponse(HttpStatusCode.OK, ongoing));
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.Forbidden, "invalid key"));
            }
        }
        public HttpResponseMessage Delete([FromBody] Delete delete)
        {
            SLW_DatabaseInfo db         = new SLW_DatabaseInfo();
            KeyDetail        key_detail = db.GetKeyDetail(delete.key);

            if (IsKeyValid(key_detail))
            {
                int user_type_requirement     = 9;
                Utilities.PasswordManager mgr = new Utilities.PasswordManager();

                if (db.GetUserType(delete.key) == user_type_requirement)
                {
                    if (db.CheckUserExist(delete.user))
                    {
                        db.DeleteUser(delete.user);
                        db.SaveActivity(new UserActivity(delete.user, Commons.Constants.ACTIVITY_DELETE_ACCOUNT, delete.user, "", 0));
                        return(Request.CreateResponse(HttpStatusCode.OK, "user_deleted"));
                    }
                    else
                    {
                        return(Request.CreateResponse(HttpStatusCode.Unauthorized, "invalid_user"));
                    }
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.Unauthorized, "unauthorized"));
                }
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.Unauthorized, "access_key_invalid"));
            }
        }
Example #3
0
        public HttpResponseMessage ReassignTask([FromBody] dynamic data)
        {
            SLW_DatabaseInfo db     = new SLW_DatabaseInfo();
            KeyDetail        detail = db.GetKeyDetail((string)data.access_key);

            if (detail.data_present)
            {
                OngoingTask prev_ongoing = db.GetSingleOngoingTask((string)data.application_id);
                db.ReassignTask((string)data.application_id, (string)data.assign_to);
                OngoingTask ongoing         = db.GetSingleOngoingTask((string)data.application_id);
                UserDetails prevUserDetails = db.GetUserDetails(prev_ongoing.assigned_to);
                UserDetails userDetails     = db.GetUserDetails(ongoing.assigned_to);

                Form form = db.GetApplication((string)data.application_id);
                ongoing.assigned_to = userDetails.fullname;
                db.SaveActivity(new UserActivity(detail.username, Commons.Constants.ACTIVITY_REASSIGN_TASK, (string)data.application_id, (string)data.assign_to, 1));

                Email.Send(userDetails.email, "New Type Approval Application", "Type approval application " + form.application_id + " for Device with Model number " + form.product_identification + " from " + ongoing.submitted_by + " is assigned to you for processing.");
                Email.Send(prevUserDetails.email, "Assigned Type Approval Application", "Application " + form.application_id + " that had been assigned to you has been reassigned.");

                return(Request.CreateResponse(HttpStatusCode.OK, ongoing));
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.Unauthorized, "invalid key"));
            }
        }
        public HttpResponseMessage Update([FromBody] Form form)
        {
            SLW_DatabaseInfo db        = new SLW_DatabaseInfo();
            KeyDetail        keyDetail = db.GetKeyDetail(form.access_key);

            //db.SaveApplication(form);
            return(Request.CreateResponse(HttpStatusCode.OK, "updated"));;
        }
        public HttpResponseMessage New([FromBody] Form form)
        {
            SLW_DatabaseInfo db        = new SLW_DatabaseInfo();
            KeyDetail        keyDetail = db.GetKeyDetail(form.access_key);

            string applicationId = string.Format("{0}_{1:N}", "ta", Guid.NewGuid());

            form.application_id = applicationId;

            //db.SaveApplication(form);
            return(Request.CreateResponse(HttpStatusCode.OK, "saved: " + applicationId));;
        }
        private bool IsKeyValid(KeyDetail key_detail)
        {
            var key_expiry = key_detail.last_detected_activity.AddMinutes(key_detail.max_inactivity_length);

            if (key_expiry >= DateTime.Now)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #7
0
        public HttpResponseMessage GetApplicationIDsForClient([FromBody] dynamic data)
        {
            SLW_DatabaseInfo db     = new SLW_DatabaseInfo();
            KeyDetail        detail = db.GetKeyDetail((string)data.access_key);

            if (detail.data_present)
            {
                return(Request.CreateResponse(HttpStatusCode.OK, db.GetApplicationIDsForUser((string)data.username)));
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.Unauthorized, "invalid key"));
            }
        }
        public HttpResponseMessage GetUsersList([FromBody] string access_key)
        {
            SLW_DatabaseInfo db         = new SLW_DatabaseInfo();
            KeyDetail        key_detail = db.GetKeyDetail(access_key);

            if (IsKeyValid(key_detail))
            {
                List <UserDetails> userDetails = db.GetAllUsersDetails();
                return(Request.CreateResponse(HttpStatusCode.OK, userDetails));
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.Unauthorized, "invalid_key"));
            }
        }
Example #9
0
        public HttpResponseMessage GetRecentDocuments([FromBody] string access_key)
        {
            SLW_DatabaseInfo       db = new SLW_DatabaseInfo();
            List <RecentDocuments> recentDocuments = new List <RecentDocuments>();
            KeyDetail detail = db.GetKeyDetail(access_key);

            if (detail.data_present)
            {
                recentDocuments = db.GetRecentDocuments(detail.username);
                return(Request.CreateResponse(HttpStatusCode.OK, recentDocuments));
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.Forbidden, "invalid key"));
            }
        }
Example #10
0
        public HttpResponseMessage GetUnassignedTask([FromBody] string access_key)
        {
            SLW_DatabaseInfo db     = new SLW_DatabaseInfo();
            KeyDetail        detail = db.GetKeyDetail(access_key);

            if (detail.data_present)
            {
                db.CheckForApplicationUpdatesAllUsers();
                List <UnassignedTask> unassignedTasks = db.GetUnassignedTasks();
                return(Request.CreateResponse(HttpStatusCode.OK, unassignedTasks));
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.Forbidden, "invalid key"));
            }
        }
Example #11
0
        public HttpResponseMessage GetSavedApplications([FromBody] dynamic data)
        {
            string           access_key = (string)data;
            SLW_DatabaseInfo db         = new SLW_DatabaseInfo();
            KeyDetail        detail     = db.GetKeyDetail(access_key);

            if (detail.data_present)
            {
                List <SavedApplications> savedApplications = db.GetSavedApplications(detail.username);
                return(Request.CreateResponse(HttpStatusCode.OK, savedApplications));
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.Forbidden, "invalid key"));
            }
        }
Example #12
0
        public HttpResponseMessage GetCertificate([FromBody] dynamic data)
        {
            SLW_DatabaseInfo db        = new SLW_DatabaseInfo();
            Dashboard        dashboard = new Dashboard();
            KeyDetail        detail    = db.GetKeyDetail((string)data.access_key);

            if (detail.data_present)
            {
                Certificate certificate = db.GetPersonalSMACertificate((string)data.application_id);
                return(Request.CreateResponse(HttpStatusCode.OK, certificate));
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.Forbidden, "invalid key"));
            }
        }
Example #13
0
        public HttpResponseMessage GetDashboardFeed([FromBody] string access_key)
        {
            SLW_DatabaseInfo db        = new SLW_DatabaseInfo();
            Dashboard        dashboard = new Dashboard();
            KeyDetail        detail    = db.GetKeyDetail(access_key);

            if (detail.data_present)
            {
                db.CheckForApplicationUpdates(detail.username);
                dashboard = db.GetDashboardData(detail.username);
                return(Request.CreateResponse(HttpStatusCode.OK, dashboard));
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.Forbidden, "invalid key"));
            }
        }
Example #14
0
        public HttpResponseMessage GetUserActivities([FromBody] string access_key)
        {
            SLW_DatabaseInfo    db             = new SLW_DatabaseInfo();
            List <UserActivity> userActivities = new List <UserActivity>();

            KeyDetail detail = db.GetKeyDetail(access_key);

            if (detail.data_present)
            {
                userActivities = db.GetUserActivities("*preview");
                return(Request.CreateResponse(HttpStatusCode.OK, userActivities));
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.Forbidden, "invalid key"));
            }
        }
Example #15
0
        public HttpResponseMessage GetApplicationStatus([FromBody] dynamic data)
        {
            string access_key     = (string)data.access_key;
            string application_id = (string)data.application_id;

            SLW_DatabaseInfo db     = new SLW_DatabaseInfo();
            KeyDetail        detail = db.GetKeyDetail(access_key);

            if (detail.data_present)
            {
                return(Request.CreateResponse(HttpStatusCode.OK, db.GetApplicationStatus(application_id)));
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.Unauthorized, "invalid key"));
            }
        }
        public HttpResponseMessage ClientResubmission([FromBody] dynamic data)
        {
            SLW_DatabaseInfo db        = new SLW_DatabaseInfo();
            KeyDetail        keyDetail = db.GetKeyDetail((string)data.access_key);

            if (keyDetail.data_present)
            {
                db.UpdateApplicationStatus((string)data.application_id, Commons.Constants.PENDING_RESUBMISSION, DateTime.Now);
                Utilities.FileManager.DeleteFiles((string)data.application_id);
                db.DeleteOngoingTask((string)data.application_id);
                db.DeleteUnassignedTask((string)data.application_id);
                return(Request.CreateResponse(HttpStatusCode.OK, "status updated"));
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.Unauthorized, "invalid key"));
            }
        }
Example #17
0
        public HttpResponseMessage DeleteOngoingTask([FromBody] dynamic data)
        {
            SLW_DatabaseInfo db     = new SLW_DatabaseInfo();
            KeyDetail        detail = db.GetKeyDetail((string)data.access_key);

            if (detail.data_present)
            {
                db.DeleteOngoingTask((string)data.application_id);
                db.UpdateApplicationStatus((string)data.application_id, Commons.Constants.REJECTED, DateTime.Now);
                FileManager.DeleteFiles((string)data.application_id);
                db.SaveActivity(new UserActivity(detail.username, Commons.Constants.ACTIVITY_REJECT_UNASSIGNED, (string)data.application_id, "", 1));
                return(Request.CreateResponse(HttpStatusCode.OK, "deleted"));
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.Unauthorized, "invalid key"));
            }
        }
Example #18
0
        public HttpResponseMessage NewEmailSetting([FromBody] dynamic data)
        {
            SLW_DatabaseInfo db     = new SLW_DatabaseInfo();
            KeyDetail        detail = db.GetKeyDetail((string)data.access_key);

            if (detail.data_present)
            {
                //do additional checks here to confirm if this is a sys admin
                db.NewEmailSetting((string)data.email, (string)data.company_name);
                db.SaveActivity(new UserActivity(detail.username, Commons.Constants.ACTIVITY_SET_EMAIL, (string)data.email, "", 1));

                Email.Send((string)data.email, "Email Verification", "Email is now configured...");
                return(Request.CreateResponse(HttpStatusCode.OK, "email_saved"));
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.Unauthorized, "invalid key"));
            }
        }
Example #19
0
        public HttpResponseMessage MoveToUnassigned([FromBody] dynamic data)
        {
            SLW_DatabaseInfo db     = new SLW_DatabaseInfo();
            KeyDetail        detail = db.GetKeyDetail((string)data.access_key);

            if (detail.data_present)
            {
                OngoingTask ongoing = db.GetSingleOngoingTask((string)data.application_id);
                db.DeleteOngoingTask((string)data.application_id);
                db.NewUnassignedTask(ongoing.application_id, ongoing.submitted_by_username, ongoing.created_date_raw);
                db.UpdateApplicationStatus((string)data.application_id, Commons.Constants.SUBMITTED_TYPE, DateTime.Now);
                db.SaveActivity(new UserActivity(detail.username, Commons.Constants.ACTIVITY_MOVE_UNASSAIGNED, (string)data.application_id, "", 1));
                return(Request.CreateResponse(HttpStatusCode.OK, new UnassignedTask(ongoing.application_id, ongoing.created_date, ongoing.created_date_raw, ongoing.submitted_by, ongoing.submitted_by_username)));
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.Unauthorized, "invalid key"));
            }
        }
Example #20
0
        public HttpResponseMessage GetStaffAssignedTasks([FromBody] dynamic data)
        {
            SLW_DatabaseInfo db     = new SLW_DatabaseInfo();
            KeyDetail        detail = db.GetKeyDetail((string)data.access_key);

            if (detail.data_present)
            {
                db.CheckForApplicationUpdatesAllUsers();
                List <AssignedTask> assignedTasks = db.GetStaffAssignedTasks((string)data.username);
                for (int i = 0; i < assignedTasks.Count; i++)
                {
                    assignedTasks[i].applicationFiles = db.GetApplicationFiles(assignedTasks[i].application_id);
                }
                return(Request.CreateResponse(HttpStatusCode.OK, assignedTasks));
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.Unauthorized, "invalid key"));
            }
        }
Example #21
0
        public HttpResponseMessage GetApplication([FromBody] dynamic data)
        {
            string access_key     = (string)data.access_key;
            string application_id = (string)data.application_id;
            string mode           = (string)data.mode;

            SLW_DatabaseInfo db = new SLW_DatabaseInfo();

            db.CheckForApplicationUpdatesAllUsers();
            KeyDetail detail = db.GetKeyDetail(access_key);

            if (detail.data_present)
            {
                Form form = db.GetApplication(application_id);
                if (mode == "preview")
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, form));
                }
                else if (mode == "edit")
                {
                    string status = (string)data.status;
                    if (status == form.status)
                    {
                        return(Request.CreateResponse(HttpStatusCode.OK, form));
                    }
                    else
                    {
                        return(Request.CreateResponse(HttpStatusCode.Unauthorized, "unauthorized"));
                    }
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.Unauthorized, "unauthroized"));
                }
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.Forbidden, "invalid key"));
            }
        }
Example #22
0
        public HttpResponseMessage ApplicantInfo([FromBody] dynamic data)
        {
            SLW_DatabaseInfo db            = new SLW_DatabaseInfo();
            ClientCompany    clientCompany = null;
            KeyDetail        keyDetail     = db.GetKeyDetail((string)data.access_key);

            if (keyDetail.data_present)
            {
                if (keyDetail.user_type == "company")
                {
                    AssignedCompany company = db.GetAssignedCompany(keyDetail.username);
                    if (company == null)
                    {
                        return(Request.CreateResponse(HttpStatusCode.OK, "empty"));
                    }
                    else
                    {
                        if (company.source == Commons.Constants.LOCAL_SOURCE)
                        {
                            clientCompany = db.GetLocalClientCompany(company.clientId);
                        }
                        else
                        {
                            clientCompany = db.GetClientDetail(company.clientId);
                        }

                        return(Request.CreateResponse(HttpStatusCode.OK, clientCompany));
                    }
                }
                else
                {
                    clientCompany = db.GetIndividualDetail(keyDetail.username);
                    return(Request.CreateResponse(HttpStatusCode.OK, clientCompany));
                }
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.Unauthorized, "unauthorized"));
            }
        }
        public HttpResponseMessage ChangePassword([FromBody] dynamic data)
        {
            SLW_DatabaseInfo db         = new SLW_DatabaseInfo();
            KeyDetail        key_detail = db.GetKeyDetail((string)data.access_key);

            if (IsKeyValid(key_detail))
            {
                Utilities.PasswordManager psw_manager = new Utilities.PasswordManager();
                if (psw_manager.ChangePassword((string)data.username, (string)data.old_psw, (string)data.new_psw))
                {
                    db.SaveActivity(new UserActivity((string)data.username, Commons.Constants.ACTIVITY_CHANGE_PASSWORD, "", "", 0));
                    return(Request.CreateResponse(HttpStatusCode.OK, "password_updated"));
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.Unauthorized, "password_incorrect"));
                }
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.Unauthorized, "invalid key"));
            }
        }
        public HttpResponseMessage RegisterCompanyUserV2([FromBody] Models.CompanyUser user)
        {
            if (user != null)
            {
                SLW_DatabaseInfo db     = new SLW_DatabaseInfo();
                KeyDetail        detail = db.GetKeyDetail(user.access_key);

                if (detail.data_present)
                {
                    //can be used to call client functions
                    var connection = GlobalHost.ConnectionManager.GetHubContext <CrossDomainHub>();

                    Utilities.PasswordManager mgr = new Utilities.PasswordManager();
                    bool valid_user_type          = false;

                    List <UserType> user_types = db.GetUserTypes();
                    for (int i = 0; i < user_types.Count; i++)
                    {
                        if (user_types[i].user_type == user.user_role)
                        {
                            valid_user_type = true;
                            break;
                        }
                    }

                    if (valid_user_type)
                    {
                        if (!db.CheckUserExist(user.username))
                        {
                            string hash   = mgr.GetHash(user.password);
                            string source = "";
                            if (db.CheckLocalClientExist(user.clientId))
                            {
                                source = Commons.Constants.LOCAL_SOURCE;
                            }
                            else
                            {
                                source = Commons.Constants.ASMS_SOURCE;
                            }

                            user.user_type = "company";
                            db.NewCompanyUser(user.username, user.first_name, user.last_name, DateTime.Now, user.user_role, user.user_type, DateTime.Now, (DateTime)System.Data.SqlTypes.SqlDateTime.MinValue, hash, false, user.email, user.company, user.clientId, source);
                            db.SaveActivity(new UserActivity(user.username, Commons.Constants.ACTIVITY_CREATE_ACCOUNT, "", "", 0));
                            return(Request.CreateResponse(HttpStatusCode.OK, db.GetUserDetails(user.username)));
                        }
                        else
                        {
                            return(Request.CreateResponse(HttpStatusCode.Unauthorized, "user exists"));
                        }
                    }
                    else
                    {
                        return(Request.CreateResponse(HttpStatusCode.Unauthorized, "invalid user type"));
                    }
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.Unauthorized, "invalid key"));
                }
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, "bad request"));
            }
        }