public IActionResult SaveInbox(RequestFormat3 _requst)
        {
            List <string> SuccessId = new List <string>();
            List <string> ErrorId   = new List <string>();
            string        message   = "Unable to save!";
            dynamic       data      = new ExpandoObject();

            foreach (Inbox _inbox in _requst.content.NotEmpty())
            {
                message = "Successfully Saved!";
                _data   = new List <ModelParameter>();
                Inbox InboxModel = NewRepo.FindByColumn <Inbox>(new List <ConditionParameter> {
                    Condition("uuid", _inbox.uuid)
                });
                if (InboxModel == null)
                {
                    _data.Add(new ModelParameter()
                    {
                        ValidateModel = null, SaveModel = _inbox
                    });
                    string status = SingleRecordTransaction(_data);
                    if (status.ToLower().Trim() == "success")
                    {
                        SuccessId.Add(_inbox.uuid);
                    }
                    else
                    {
                        ErrorId.Add(_inbox.uuid);
                    }
                }
                else
                {
                    SuccessId.Add(_inbox.uuid);
                }
            }
            data.successId = string.Join(',', SuccessId);
            data.errorId   = string.Join(',', ErrorId);
            return(new CustomResult2(data, message));
        }
        //public dynamic MobileLogin(Users userModel)
        //{


        //    Users UpdateUser = NewRepo.FindByColumn<Users>(new List<ConditionParameter>
        //        {
        //            Condition("user_code",userModel.user_code),
        //            Condition("otp_code",userModel.otp_code),
        //        });
        //    if (UpdateUser != null)
        //    {
        //        Data = new List<ModelParameter>();
        //        UpdateUser.is_active = true;
        //        UpdateUser.token = DbHelper.UniqueKey();
        //        UpdateUser.device_token = userModel.device_token;
        //        Data.Add(new ModelParameter { ValidateModel = new UsersValidator(), SaveModel = UpdateUser });
        //        CustomResult customResult = UpdateData(Data);
        //        if (customResult._result.code == 200)
        //        {
        //            CacheRepository _cache = new CacheRepository();
        //            Query = new QueryParam()
        //            {
        //                Table = "user_organization_mapping",
        //                Fields = "org_type,company_code,plant_code,mcc_code,bmc_code,mpp_code",
        //                Where = new List<ConditionParameter> {
        //                Condition("user_code",UpdateUser.user_code)
        //            }
        //            };
        //            List<UserOrganizationMapping> _UserOrganizationMappingList = NewRepo.FindAll<UserOrganizationMapping>(Query).ToList();
        //            if (_UserOrganizationMappingList == null || _UserOrganizationMappingList.Count == 0)
        //            {
        //                return new CustomResult("error", "authentication_fail");
        //            }
        //            Query = new QueryParam()
        //            {
        //                Table = "user_role",
        //                Fields = "role_code",
        //                Where = new List<ConditionParameter> {
        //                Condition("user_code",UpdateUser.user_code)
        //            }
        //            };
        //            TmpUserToken _TmpUserToken = new TmpUserToken
        //            {
        //                username = UpdateUser.user_name,
        //                user_code = UpdateUser.user_code,
        //                id = UpdateUser.token,
        //                role = NewRepo.FindAll<string>(Query).ToList(),
        //                usertype = _UserOrganizationMappingList.FirstOrDefault().org_type,
        //                company_code = _UserOrganizationMappingList.Select(o => o.company_code).Distinct().ToList(),
        //                plant_code = _UserOrganizationMappingList.Select(o => o.plant_code).Distinct().ToList(),
        //                mcc_code = _UserOrganizationMappingList.Select(o => o.mcc_code).Distinct().ToList(),
        //                bmc_code = _UserOrganizationMappingList.Select(o => o.bmc_code).Distinct().ToList(),
        //                mpp_code = _UserOrganizationMappingList.Select(o => o.mpp_code).Distinct().ToList(),



        //                member_code = UpdateUser.reference_code,

        //                exp = DateTime.Now.AddHours(6)

        //            };
        //            //if (UpdateUser.user_type == "member")
        //            //{
        //            //    Query = new QueryParam()
        //            //    {
        //            //        Table = "member",
        //            //        Fields = "concat(mpp_name,'-',member_name)",
        //            //        Join = new List<JoinParameter>()
        //            //        {
        //            //            new JoinParameter{table="mpp",condition="mpp.mpp_code=member.mpp_code"},
        //            //        },
        //            //        Where = new List<ConditionParameter> {
        //            //            Condition("member_code",_TmpUserToken.member_code)
        //            //        }
        //            //    };
        //            //    _TmpUserToken.display_data = NewRepo.Find<string>(Query);
        //            //}
        //            Query = new QueryParam()
        //            {
        //                Table = "actions",
        //                Fields = "distinct service_url",
        //                Join = new List<JoinParameter>()
        //                {
        //                    new JoinParameter{table="permission_action",condition="permission_action.action_code=actions.action_code"},
        //                    new JoinParameter{table="role_permission",condition="role_permission.permission_code=permission_action.permission_code"}
        //                },
        //                Where = new List<ConditionParameter> {
        //                    Condition("role_code",_TmpUserToken.role.ToArray(),"in")
        //                }
        //            };
        //            _TmpUserToken.actions = NewRepo.FindAll<string>(Query).ToList();
        //            FreeAction _freeAction = _cache.GetData<FreeAction>("FreeActions");

        //            if (_freeAction == null || (DateTime.Now.Subtract(_freeAction.created_at).Hours >= 24))
        //            {
        //                _freeAction = new FreeAction();
        //                Query = new QueryParam()
        //                {
        //                    Table = typeof(Actions).GetTableName(),
        //                    Fields = "distinct service_url",
        //                    Where = new List<ConditionParameter> {
        //                Condition("is_free",true),
        //                new ConditionParameter{direct_condition="service_url is not null",PropertyValue="#$#",PropertyName="service_url" } }
        //                };
        //                _freeAction.actions = NewRepo.FindAll<string>(Query).ToList();
        //                _freeAction.created_at = DateTime.Now;
        //                _cache.SaveData(_freeAction, "FreeActions");
        //            }
        //            _cache.SaveData(_TmpUserToken, UpdateUser.token);

        //            UserToken ut = new UserToken
        //            {
        //                user_code = UpdateUser.user_code,
        //                login_time = DateTime.Now,
        //                token = UpdateUser.token,
        //                is_active = true
        //            };

        //            Data = new List<ModelParameter>()
        //            {
        //                new ModelParameter{ValidateModel=new UserTokenValidator(),SaveModel=ut}
        //            };
        //            this.SaveData(Data);
        //            return UpdateUser.token;
        //        }
        //        return customResult;
        //    }
        //    return new CustomResult("error", "authfail");
        //}

        public dynamic MobileLogin(Users userModel)
        {
            Users UpdateUser = NewRepo.FindByColumn <Users>(new List <ConditionParameter>
            {
                Condition("user_code", userModel.user_code),
                Condition("otp_code", userModel.otp_code),
            });

            if (UpdateUser != null)
            {
                Data = new List <ModelParameter>();
                UpdateUser.is_active    = true;
                UpdateUser.token        = DbHelper.UniqueKey();
                UpdateUser.device_token = userModel.device_token;
                Data.Add(new ModelParameter {
                    ValidateModel = new UsersValidator(), SaveModel = UpdateUser
                });
                CustomResult customResult = UpdateData(Data);
                if (customResult._result.code == 200)
                {
                    _cache = new CacheRepository();
                    TmpUserToken _TmpUserToken = SetUserCache(UpdateUser);
                    if (_TmpUserToken == null)
                    {
                        return(new CustomResult("error", "no_org_set"));
                    }
                    SetFreeActions();
                    SetRLSHierarchy(ref _TmpUserToken);
                    _cache.SaveData(_TmpUserToken, UpdateUser.token, null);
                    SetLoginToken(UpdateUser.user_code, UpdateUser.token);
                    return(UpdateUser.token);
                }
                return(customResult);
            }
            return(new CustomResult("error", "authfail"));
        }
示例#3
0
        public IActionResult Registration()
        {
            Bmc     BmcModel = NewRepo.FindByKey <Bmc>(_request.organizationCode);
            dynamic data     = new ExpandoObject();

            if (BmcModel != null)
            {
                if (_request.content.mobileNo != null && _request.content.mobileNo.Trim() == BmcModel.contact_no.Trim())
                {
                    _data = new List <ModelParameter>();
                    AndroidInstallationDetails DetailModel;
                    AndroidInstallation        InstalationModel = NewRepo.FindByColumn <AndroidInstallation>(new List <ConditionParameter>
                    {
                        Condition("organization_code", BmcModel.bmc_code),
                        Condition("organization_type", "BMC"),
                    });

                    if (InstalationModel == null)
                    {
                        InstalationModel = new AndroidInstallation
                        {
                            android_installation_id = DbHelper.UniqueKey(),
                            organization_code       = BmcModel.bmc_code,
                            organization_type       = "BMC",
                        };
                        DetailModel = SetDetail(InstalationModel.android_installation_id);
                        _data.Add(new ModelParameter {
                            ValidateModel = null, SaveModel = InstalationModel
                        });
                    }
                    else
                    {
                        DetailModel = NewRepo.FindByColumn <AndroidInstallationDetails>(new List <ConditionParameter>
                        {
                            Condition("android_installation_id", InstalationModel.android_installation_id),
                            Condition("device_id", _request.deviceId),
                            Condition("mobile_no", BmcModel.contact_no.Trim()),
                            Condition("is_active", 1)
                        });
                        if (DetailModel == null)
                        {
                            DetailModel = SetDetail(InstalationModel.android_installation_id);
                        }
                        else
                        {
                            DetailModel.model_operation = "update";
                        }
                    }
                    DetailModel.hash_key   = DbHelper.UniqueKey(20);
                    DetailModel.otp_code   = 1234;
                    DetailModel.is_active  = false;
                    DetailModel.is_expired = false;
                    _data.Add(new ModelParameter {
                        ValidateModel = null, SaveModel = DetailModel
                    });
                    CustomResult result = AUDOperation(_data);
                    if (result._result.message.ToLower() == "success")
                    {
                        data.token = DetailModel.hash_key;
                        return(new CustomResult2(data));
                    }
                    return(new CustomResult2(data, "Data Not Available"));
                }
                else
                {
                    return(new CustomResult2(data, "Data Not Available"));
                }
            }
            else
            {
                return(new CustomResult2(data, "Data Not Available"));
            }
        }
示例#4
0
        public IActionResult Generate(string host)
        {
            AndroidInstallationDetails DetailModel = NewRepo.FindByColumn <AndroidInstallationDetails>(new List <ConditionParameter> {
                Condition("hash_key", _request.token)
            });

            if (DetailModel != null)
            {
                string NewFileName = FileHelper.NewFileName(FileHelper.FileServerPath("Identity/Data/"), $"{_request.organizationType}_{_request.organizationCode}_", "db");
                FileHelper.Copy(FileHelper.FileServerPath("Identity/Struct/everest_amcs.db"), NewFileName);
                DetailModel.db_path         = host + "/" + NewFileName.Replace(FileHelper.ProjectPath(), "");
                DetailModel.model_operation = "update";
                _data = new List <ModelParameter> {
                    new ModelParameter {
                        ValidateModel = null, SaveModel = DetailModel
                    }
                };
                AUDOperation(_data);

                DBRepository Sqlite = new DBRepository(NewFileName);
                _query = new QueryParam
                {
                    DirectQuery = $"SELECT tbl_name FROM sqlite_master WHERE type='table'"
                };
                List <string>    SqliteTable  = Sqlite.FindAll <string>(_query).ToList();
                List <TableList> AllTableList = NewRepo.FindAll <TableList>(new QueryParam {
                    Where = new List <ConditionParameter> {
                        Condition("is_offline", 0)
                    }
                }).ToList();
                OrgDetail();
                foreach (TableList tables in AllTableList)
                {
                    if (SqliteTable.Contains(tables.table_name.Trim()))
                    {
                        _query = new QueryParam
                        {
                            DirectQuery = $"PRAGMA table_info({tables.table_name.Trim()})"
                        };
                        List <TableInfo> TableInfoDetail = Sqlite.FindAll <TableInfo>(_query).ToList();
                        string           fields          = string.Join(",", TableInfoDetail.Select(x => x.name).ToArray());
                        _query = new QueryParam
                        {
                            Fields   = fields,
                            Distinct = "distinct",
                            Table    = tables.table_name.Trim(),
                        };
                        if (tables.key_field != null && tables.key_field.Trim() != "")
                        {
                            string comapre_field = tables.key_field == "to_dest"?"bmc_code": tables.key_field;
                            _query.Where = new List <ConditionParameter>
                            {
                                Condition(tables.key_field, Hierarchy[comapre_field], "in")
                            };
                        }

                        IEnumerable <object> ObjectResult = NewRepo.FindAll(_query);
                        int    i           = 0;
                        string DirectQuery = "";
                        foreach (var ObjTmp in ObjectResult)
                        {
                            IDictionary <string, object> Tmp = ObjTmp as IDictionary <string, object>;
                            if (i == 0)
                            {
                                DirectQuery = $"insert into {tables.table_name} ({fields}) values (";
                            }
                            if (i == 200)
                            {
                                DirectQuery = DirectQuery.TrimEnd('(');
                                DirectQuery = DirectQuery.TrimEnd(',');
                                Sqlite.Add(new QueryParam {
                                    DirectQuery = DirectQuery
                                });
                                i = 0;
                            }
                            else
                            {
                                DirectQuery += string.Join(",", Tmp.Select(x => x.Value == null ? "NULL" : $"'{x.Value.ToString()}'")) + "),(";
                                i++;
                            }
                        }
                        if (DirectQuery != "")
                        {
                            DirectQuery = DirectQuery.TrimEnd('(');
                            DirectQuery = DirectQuery.TrimEnd(',');
                            Sqlite.Add(new QueryParam {
                                DirectQuery = DirectQuery
                            });
                        }
                    }
                }
                dynamic data = new ExpandoObject();
                data.dbPath = DetailModel.db_path;
                return(new CustomResult2(data));
            }
            return(new CustomResult2(null, "Authentication Failed."));
        }
示例#5
0
        public IActionResult Verification()
        {
            dynamic data = new ExpandoObject();
            AndroidInstallationDetails DetailModel = NewRepo.FindByColumn <AndroidInstallationDetails>(new List <ConditionParameter> {
                Condition("hash_key", _request.token),
                Condition("otp_code", _request.content.otpCode),
                Condition("imei_no", _request.imei),
            });

            if (DetailModel == null)
            {
                return(new CustomResult2(data, "OTP Not Verified."));
            }
            else
            {
                _data  = new List <ModelParameter>();
                _query = new QueryParam
                {
                    Where = new List <ConditionParameter>
                    {
                        Condition("android_installation_id", DetailModel.android_installation_id),
                        Condition("android_installation_details_id", DetailModel.android_installation_details_id, "!=")
                    }
                };
                List <AndroidInstallationDetails> DetailList = NewRepo.FindAll <AndroidInstallationDetails>(_query).ToList();
                foreach (AndroidInstallationDetails UdateDetailModel in DetailList.NotEmpty())
                {
                    UdateDetailModel.sync_active     = false;
                    UdateDetailModel.model_operation = "update";
                    _data.Add(new ModelParameter {
                        ValidateModel = null, SaveModel = UdateDetailModel
                    });
                }
                DetailModel.is_active       = true;
                DetailModel.sync_key        = NumericHelper.RandomNumber().ToString();
                DetailModel.sync_active     = true;
                DetailModel.model_operation = "update";
                _data.Add(new ModelParameter {
                    ValidateModel = null, SaveModel = DetailModel
                });
                CustomResult result = AUDOperation(_data);
                if (result._result.message.ToLower() == "success")
                {
                    _query = new QueryParam
                    {
                        Fields = "tbl_mcc_plant.mcc_plant_code,tbl_mcc_plant.name",
                        Join   = new List <JoinParameter>
                        {
                            new JoinParameter {
                                table = "tbl_bmc", condition = "tbl_bmc.mcc_plant_code=tbl_mcc_plant.mcc_plant_code"
                            }
                        },
                        Where = new List <ConditionParameter>
                        {
                            Condition("bmc_code", _request.organizationCode)
                        }
                    };
                    MccPlant MccModel = NewRepo.Find <MccPlant>(_query);
                    if (MccModel == null)
                    {
                        return(new CustomResult2(data, "OTP Not Verified."));
                    }
                    data.message    = "OTP Verified";
                    data.syncKey    = DetailModel.sync_key;
                    data.parentType = "MCC";
                    data.parentCode = MccModel.mcc_plant_code;
                    data.parentName = MccModel.name;
                    return(new CustomResult2(data));
                }
                return(new CustomResult2(data, "OTP Not Verified."));
            }
        }