コード例 #1
0
        public JsonResult DoApprove(TRN_EXPENSE_DO_APPROVE appr_data)
        {
            bool   is_success = false;
            string msg        = @"failed to save";

            using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew)) {
                try {
                    this.GetLoggedInInfo();

                    appr_data.APPROVE_USER_NO  = this.sess_USER_NO;
                    appr_data.APPROVE_LOGON_NO = this.sess_LOGON_NO;

                    db.TRN_EXPENSE_DO_APPROVE(appr_data.EXP_NO, appr_data.APPROVE_TYPE_NO, appr_data.APPROVE_USER_NO, appr_data.APPROVE_LOGON_NO, appr_data.REASON_NO, appr_data.REAMRKS);
                    scope.Complete();

                    is_success = true;
                    msg        = @"saved successfully";
                } catch (DbException ex) {
                    scope.Dispose();
                    msg        = "An Error Occurred during Saving Expense, Error Code - 999, Please Try Again."; //ex.Message;
                    is_success = false;
                    msg        = ex.Message;
                    DbErrorTracker db_error = new DbErrorTracker();
                    db_error.WriteErrorLog(db_error.GetErrorMessage(ex, true), ex, sess_entry_user_name);
                } catch (EntitySqlException ex) {
                    scope.Dispose();
                    msg        = msg = "An Error Occurred during Saving Data, Error Code - 999, Please Try Again."; //ex.Message;
                    is_success = false;
                    msg        = ex.Message;
                    DbErrorTracker db_error = new DbErrorTracker();
                    db_error.WriteErrorLog(db_error.GetErrorMessage(ex, true), ex, sess_entry_user_name);
                } catch (DbUpdateException ex) {
                    scope.Dispose();
                    msg        = msg = ex.Message;
                    is_success = false;
                    msg        = ex.Message;
                    DbErrorTracker db_error = new DbErrorTracker();
                    db_error.WriteErrorLog(db_error.GetErrorMessage(ex, true), ex, sess_entry_user_name);
                } catch (Exception ex) {
                    scope.Dispose();
                    msg        = ex.Message;
                    is_success = false;
                    msg        = ex.Message;
                    DbErrorTracker db_error = new DbErrorTracker();
                    db_error.WriteErrorLog(db_error.GetErrorMessage(ex, true), ex, sess_entry_user_name);
                }
            }
            var result = new { @is_success = is_success, @msg = msg };

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
コード例 #2
0
        public JsonResult Login(SEC_USERS sec_users)
        {
            //MobileLogger.logDefault( "called", "test");
            //return Request.CreateResponse(HttpStatusCode.OK, sec_users);

            bool     is_success     = false;
            string   msg            = @"";
            decimal  login_msg_type = (decimal)LOGIN_MSG_TYPE.NOTHING;
            string   down_link      = string.Empty;
            string   version_number = string.Empty;
            decimal? USER_NO        = null;
            decimal? ENTRY_USER_NO  = null;
            decimal? ZM_USER_NO     = null;
            decimal? AGENT_USER_NO  = null;
            string   SESSION_ID     = string.Empty;
            DateTime?SERVER_TIME    = null;
            decimal? LAST_PK_VAL    = null;


            string APP_VERSION = string.Empty;

            try
            {
                var gen_app_version = db.GEN_APP_VERSION.Where(a => a.IS_CURR_VER == 1).FirstOrDefault();
                if (gen_app_version != null)
                {
                    APP_VERSION = gen_app_version.APP_VERSION;
                }

                if (string.IsNullOrEmpty(sec_users.APP_VERSION) || string.IsNullOrWhiteSpace(sec_users.APP_VERSION))
                {
                    msg            = "APP VERSION is required";
                    login_msg_type = (decimal)LOGIN_MSG_TYPE.INVALID_APP_VERSION;
                    //var result = new { @SESSION_ID = "", @SERVER_TIME = "", @msg = msg };
                    //return Json(result, JsonRequestBehavior.AllowGet);
                }
                else
                {
                    if (APP_VERSION.Trim().ToUpper() != sec_users.APP_VERSION.Trim().ToUpper())
                    {
                        msg            = @"Application Version Mismatch, Please download the updated version from https://dl.dropboxusercontent.com/u/67899212/Omicon.apk";
                        login_msg_type = (decimal)LOGIN_MSG_TYPE.INVALID_APP_VERSION;
                        down_link      = gen_app_version.DOWN_LINK;
                        version_number = gen_app_version.APP_VERSION;
                        //var result = new { @SESSION_ID = "", @SERVER_TIME = "", @msg = msg };
                        //return Json(result, JsonRequestBehavior.AllowGet);
                    }
                    else
                    {
                        var res_obj = db.SEC_USERS_LOGIN(sec_users.USER_NAME, sec_users.USER_PWD, null).FirstOrDefault();

                        if (res_obj != null)
                        {
                            if (res_obj.USER_NO > 0)
                            {
                                //
                                Session["sess_sec_users"] = res_obj;
                                Session["sess_USER_NO"]   = res_obj.USER_NO;

                                USER_NO     = res_obj.USER_NO;
                                SERVER_TIME = res_obj.SERVER_TIME;

                                if (res_obj.USER_TYPE_NO == (decimal)UserType.Agents)
                                {
                                    Session["sess_entry_user_no"] = res_obj.USER_NO;
                                    Session["sess_zm_user_no"]    = res_obj.USER_PARENT_NO;
                                    Session["sess_agent_user_no"] = res_obj.USER_NO;

                                    ENTRY_USER_NO = res_obj.USER_NO;
                                    ZM_USER_NO    = res_obj.USER_PARENT_NO;
                                    AGENT_USER_NO = res_obj.USER_NO;
                                }
                                else
                                {
                                    Session["sess_entry_user_no"] = res_obj.USER_NO;
                                    Session["sess_zm_user_no"]    = res_obj.USER_NO;
                                    Session["sess_agent_user_no"] = null;

                                    ENTRY_USER_NO = res_obj.USER_NO;
                                    ZM_USER_NO    = res_obj.USER_PARENT_NO;
                                    AGENT_USER_NO = res_obj.USER_NO;
                                }

                                string sess_id      = Session.SessionID;
                                string ip_addr      = CustomValidator.GetRequestIpAddress();
                                string device_id    = CustomValidator.GetDeviceId();
                                string login_mobile = sec_users.USER_MOBILE;
                                string ws_id        = CustomValidator.GetWebServerId();
                                string app_version  = sec_users.APP_VERSION;

                                SESSION_ID = sess_id;

                                decimal LOGON_NO = db.SEC_USER_LOGONS_INSERT(res_obj.USER_NO, ip_addr, device_id, null, null, null, (decimal)ApproveType.Approved, null, null, sess_id, login_mobile, ws_id, app_version, login_mobile).First().Value;

                                Session["sess_LOGON_NO"] = LOGON_NO;

                                LAST_PK_VAL = db.TRN_OFFLINE_LAST_PK_GET(res_obj.USER_NO).FirstOrDefault();

                                is_success = true;
                                if (sec_users.USER_NAME == "testuser")
                                {
                                    MobileLogger.logDefault("found him testuser " + USER_NO + " msg " + is_success.ToString(), "test");
                                }
                                //var result = new { @SESSION_ID = sess_id, @SERVER_TIME = res_obj.SERVER_TIME, @msg = "" };
                                //return Json(result, JsonRequestBehavior.AllowGet);
                            }
                            else
                            {
                                msg            = "Invalid Username or password";
                                login_msg_type = (decimal)LOGIN_MSG_TYPE.INVALID_LOGIN;
                                //var result = new { @SESSION_ID = "", @SERVER_TIME = "", @msg = msg };
                                //return Json(result, JsonRequestBehavior.AllowGet);
                            }
                            //MobileLogger.logDefault((res_obj.USER_NO == null) ? "NULL user no in Login LN:143 WS_SEC_USERS Controller" : res_obj.USER_NO.ToString(),"username");
                        }
                        else
                        {
                            msg            = "Invalid Username or password";
                            login_msg_type = (decimal)LOGIN_MSG_TYPE.INVALID_LOGIN;
                            //var result = new { @SESSION_ID = "", @SERVER_TIME = "", @msg = msg };
                            //return Json(result, JsonRequestBehavior.AllowGet);
                        }
                    }
                }
                if (sec_users.USER_NAME == "testuser" && !is_success)
                {
                    MobileLogger.logDefault(msg, "test");
                }
                var result_object = new
                {
                    @SESSION_ID     = SESSION_ID,
                    @SERVER_TIME    = SERVER_TIME,
                    @msg            = msg,
                    @is_success     = is_success,
                    @USER_NO        = USER_NO,
                    @ENTRY_USER_NO  = ENTRY_USER_NO,
                    @ZM_USER_NO     = ZM_USER_NO,
                    @AGENT_USER_NO  = AGENT_USER_NO,
                    @login_msg_type = login_msg_type,
                    @down_link      = down_link,
                    @version_number = version_number,
                    @LAST_PK_VAL    = LAST_PK_VAL,
                };

                return(Json(result_object, JsonRequestBehavior.AllowGet));

                //return null;
            }
            catch (Exception ex)
            {
                DbErrorTracker db_error = new DbErrorTracker();
                db_error.WriteErrorLog(db_error.GetErrorMessage(ex, true), ex, sess_entry_user_name);
                return(null);
            }
        }