public IActionResult PurchaseRateApplicability(List <PurchaseRateApplicability> PurchaseRateApplicabilityList)
        {
            Unions     UnionsModel = GetLastRecord <Unions>("tbl_unions");
            QueryParam Query       = new QueryParam
            {
                Fields = "*"
            };
            IEnumerable <Shift> shiftList = NewRepo.FindAll <Shift>(Query);
            int code = NewRepo.Find <int>(new QueryParam {
                DirectQuery = "select IFNULL(max(rate_app_code),0) from tbl_purchase_rate_applicability"
            });

            foreach (PurchaseRateApplicability PurchaseRateApplicabilityModel in PurchaseRateApplicabilityList)
            {
                Data = new List <ModelParameter>();
                if (PurchaseRateApplicabilityModel.module_name.ToLower() == "dcs")
                {
                    if (PurchaseRateApplicabilityModel.rate_for == "farmer_collection")
                    {
                        PurchaseRateApplicabilityModel.rate_app_code        = (code + 1).ToString();
                        PurchaseRateApplicabilityModel.ref_code             = PurchaseRateApplicabilityModel.applicability_unique_code;
                        PurchaseRateApplicabilityModel.originating_org_code = PurchaseRateApplicabilityModel.union_code = UnionsModel.union_code;
                        PurchaseRateApplicabilityModel.dcs_code             = PurchaseRateApplicabilityModel.module_code;
                        PurchaseRateApplicabilityModel.shift_code           = shiftList.Where(x => x.short_name.ToLower() == PurchaseRateApplicabilityModel.shift.ToLower()).Select(x => x.id).FirstOrDefault();
                        string time = PurchaseRateApplicabilityModel.wef_date.ToString("yyyy-MM-dd") + " " + shiftList.Where(x => x.short_name.ToLower() == PurchaseRateApplicabilityModel.shift.ToLower()).Select(x => x.shift_time.ToString(@"hh\:mm\:ss")).FirstOrDefault();
                        PurchaseRateApplicabilityModel.wef_date = DateHelper.ParseDate(time);
                        Data.Add(new ModelParameter {
                            SaveModel = PurchaseRateApplicabilityModel, ValidateModel = new PurchaseRateApplicabilityValidator()
                        });
                        SaveData(PurchaseRateApplicabilityModel.applicability_unique_code);
                    }
                }
            }
            return(new CustomResult("success", _response));
        }
 public void TestMethod()
 {
     BaseRepo <BaseModel>   t1 = new BaseRepo <BaseModel>();
     BaseRepo <NewModel>    t2 = new NewRepo();
     ICovariant <BaseModel> t3 = new BaseRepo <NewModel>();
     ICovariant <BaseModel> t4 = new NewRepo();
 }
        public IActionResult SaveMpp(List <Dcs> DcsList)
        {
            Unions   UnionsModel   = GetLastRecord <Unions>("tbl_unions");
            MccPlant MccPlantModel = GetLastRecord <MccPlant>("tbl_mcc_plant");

            foreach (Dcs DcsModel in DcsList)
            {
                Data = new List <ModelParameter>();
                if (DcsModel.dcs_code != "")
                {
                    Dcs NewModel = NewRepo.FindByKey <Dcs>(DcsModel.dcs_code);
                    if (NewModel == null)
                    {
                        if (UnionsModel.has_mcc == true)
                        {
                            DcsModel.mcc_plant_code = MccPlantModel.mcc_plant_code;
                        }
                        else
                        {
                            DcsModel.mcc_plant_code = DcsModel.bmc_code;
                        }

                        DcsModel.ref_code             = DcsModel.dcs_code.PadLeft(15, '0');
                        DcsModel.originating_org_code = DcsModel.union_code = MccPlantModel.union_code;
                        DcsModel.plant_code           = MccPlantModel.plant_code;
                        DcsModel.x_col1 = SetDcsXcol(DcsModel.allow_multiple_milktype);
                        Data.Add(new ModelParameter {
                            SaveModel = DcsModel, ValidateModel = new DcsValidator()
                        });
                    }
                    else
                    {
                        NewModel.dcs_name                = DcsModel.dcs_name;
                        NewModel.bmc_code                = DcsModel.bmc_code;
                        NewModel.route_code              = DcsModel.route_code;
                        NewModel.is_active               = DcsModel.is_active;
                        NewModel.contact_person          = DcsModel.contact_person;
                        NewModel.mobile_no               = DcsModel.mobile_no;
                        NewModel.allow_multiple_milktype = DcsModel.allow_multiple_milktype;
                        NewModel.x_col1          = SetDcsXcol(DcsModel.allow_multiple_milktype);
                        NewModel.model_operation = "update";
                        Data.Add(new ModelParameter {
                            SaveModel = NewModel, ValidateModel = new DcsValidator()
                        });
                    }
                    SaveData(DcsModel.dcs_code);
                }
                else
                {
                    _response.Add(new CustomResponse {
                        status = "300", msg = "error:dcs_code"
                    });
                }
            }
            return(new CustomResult("success", _response));
        }
Exemple #4
0
        public NewRepo CreateRepository(NewRepo newRepo)
        {
            string        url           = $"{CardAPIBaseUrl}/repo";
            NetworkClient networkClient = new NetworkClient(url);

            networkClient.PostData = JsonConvert.SerializeObject(newRepo);
            string resultJson = networkClient.HttpPost();

            return(JsonConvert.DeserializeObject <NewRepo>(resultJson));
        }
        private T GetLastRecord <T>(string table) where T : BaseModel
        {
            QueryParam Query = new QueryParam
            {
                Fields  = "*",
                Table   = table,
                OrderBy = "created_at desc"
            };

            return(NewRepo.Find <T>(Query));
        }
        public IActionResult SaveAck(Acknowledgemen _requst)
        {
            string  message = "Sentbox Not Updated.";
            dynamic data    = new ExpandoObject();
            string  status  = NewRepo.Find <string>(new QueryParam
            {
                Fields = "tbl_android_installation.android_installation_id",
                Table  = "tbl_android_installation_details",
                Join   = new List <JoinParameter>
                {
                    new JoinParameter {
                        table = "tbl_android_installation", condition = "tbl_android_installation.android_installation_id=tbl_android_installation_details.android_installation_id"
                    },
                },
                Where = new List <ConditionParameter> {
                    Condition("hash_key", _requst.token),
                    Condition("tbl_android_installation_details.is_active", 1),
                    Condition("is_expired", 0),
                    Condition("device_id", _requst.deviceId),
                    Condition("tbl_android_installation.organization_code", _requst.organizationCode),
                    Condition("organization_type", _requst.organizationType)
                }
            });

            if (status.Trim() != "")
            {
                bool flag = NewRepo.Delete(new List <QueryParam> {
                    new QueryParam
                    {
                        Table = "tbl_sentbox",
                        Where = new List <ConditionParameter>
                        {
                            Condition("uuid", _requst.content.uuid.ToArray())
                        }
                    },
                    new QueryParam
                    {
                        Table = "tbl_sentbox_clone",
                        Where = new List <ConditionParameter>
                        {
                            Condition("uuid", _requst.content.uuid.ToArray())
                        }
                    }
                });
                if (flag)
                {
                    message = "Sentbox Updated Successfully.";
                }
            }
            data.message = message;
            return(new CustomResult2(data));
        }
        public IActionResult SaveRoute(List <Route> RouteList)
        {
            Unions UnionsModel = GetLastRecord <Unions>("tbl_unions");

            foreach (Route RouteModel in RouteList)
            {
                Data = new List <ModelParameter>();
                if (RouteModel.route_code != "")
                {
                    Route NewModel = NewRepo.FindByKey <Route>(RouteModel.route_code);
                    if (RouteModel.route_type == null || RouteModel.route_type == "")
                    {
                        RouteModel.route_type = "Can";
                    }
                    if (NewModel == null)
                    {
                        RouteModel.vehicle_type_code = (RouteModel.route_type == "Can") ? 1 : 2;
                        RouteModel.to_dest           = RouteModel.bmc_code;
                        RouteModel.to_type           = "bmc";
                        RouteModel.ref_code          = RouteModel.route_code;
                        RouteModel.union_code        = RouteModel.originating_org_code = UnionsModel.union_code;
                        Data.Add(new ModelParameter {
                            SaveModel = RouteModel, ValidateModel = new RouteValidator()
                        });
                    }
                    else
                    {
                        NewModel.vehicle_type_code     = (RouteModel.route_type == "Can") ? 1 : 2;
                        NewModel.to_dest               = RouteModel.bmc_code;
                        NewModel.bmc_code              = RouteModel.bmc_code;
                        NewModel.route_name            = RouteModel.route_name;
                        NewModel.is_active             = RouteModel.is_active;
                        NewModel.route_supervisor_name = RouteModel.route_supervisor_name;
                        NewModel.contact_no            = RouteModel.contact_no;
                        NewModel.model_operation       = "update";
                        Data.Add(new ModelParameter {
                            SaveModel = NewModel, ValidateModel = new RouteValidator()
                        });
                    }
                    SaveData(RouteModel.route_code);
                }
                else
                {
                    _response.Add(new CustomResponse {
                        status = "300", msg = "error:route_code"
                    });
                }
            }
            return(new CustomResult("success", _response));
        }
Exemple #8
0
        private void OrgDetail()
        {
            Hierarchy = new Dictionary <string, List <string> >();
            List <Dcs> OrgData = NewRepo.FindAll <Dcs>(new QueryParam {
                Fields = "union_code,plant_code,mcc_plant_code,bmc_code,dcs_code",
                Where  = new List <ConditionParameter>
                {
                    Condition("bmc_code", _request.organizationCode)
                }
            }).ToList();

            if (OrgData == null)
            {
                Bmc BmcData = NewRepo.FindByKey <Bmc>(_request.organizationCode);
                Hierarchy.Add("union_code", new List <string> {
                    BmcData.union_code
                });
                Hierarchy.Add("plant_code", new List <string> {
                    BmcData.plant_code
                });
                Hierarchy.Add("mcc_plant_code", new List <string> {
                    BmcData.mcc_plant_code
                });
                Hierarchy.Add("bmc_code", new List <string> {
                    _request.organizationCode
                });
                Hierarchy.Add("dcs_code", new List <string> {
                    ""
                });
            }
            else
            {
                Hierarchy.Add("union_code", new List <string> {
                    OrgData.Select(x => x.union_code).FirstOrDefault()
                });
                Hierarchy.Add("plant_code", new List <string> {
                    OrgData.Select(x => x.plant_code).FirstOrDefault()
                });
                Hierarchy.Add("mcc_plant_code", new List <string> {
                    OrgData.Select(x => x.mcc_plant_code).FirstOrDefault()
                });
                Hierarchy.Add("bmc_code", new List <string> {
                    _request.organizationCode
                });
                Hierarchy.Add("dcs_code", OrgData.Select(x => x.dcs_code).ToList());
            }
        }
 public IActionResult SaveBmcAck(List <CustomResponse> CollectionCodeList)
 {
     foreach (CustomResponse code in CollectionCodeList)
     {
         BmcCollection collection = NewRepo.FindByKey <BmcCollection>(code.key_code);
         if (collection != null)
         {
             collection.data_post_status = 1;
             collection.model_operation  = "update";
             List <ModelParameter> Data = new List <ModelParameter>()
             {
                 new ModelParameter {
                     SaveModel = collection, ValidateModel = null
                 }
             };
             SingleRecordTransaction(Data, 3);
         }
     }
     return(new CustomResult("success", new CustomResponse {
         status = "200", msg = "success"
     }));
 }
        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));
        }
        private List <string> SingleHierarchy(string hierarchy_code, string parent_code, string[] parent_value, bool IsHierarchy)
        {
            string table;

            if (IsHierarchy)
            {
                table = "business_hierarchy";
            }
            else
            {
                table = hierarchy_code.Split('-')[0];
            }
            Query = new QueryParam
            {
                Fields = hierarchy_code,
                Table  = table,
                Where  = new List <ConditionParameter>
                {
                    Condition(parent_code, parent_value, "IN")
                }
            };
            return(NewRepo.FindAll <string>(Query).ToList());
        }
        public IActionResult UpdateDeviceToken(Users userModel)
        {
            Data = new List <ModelParameter>();
            QueryParam Query = new QueryParam
            {
                Where = new List <ConditionParameter>
                {
                    Condition("user_code", userModel.user_code),
                    Condition("device_id", userModel.device_id),
                },
            };
            Users UserModel = NewRepo.Find <Users>(Query);

            if (UserModel == null)
            {
                return(new CustomResult("error", "no_device_found"));
            }
            UserModel.device_token = userModel.device_token;
            Data.Add(new ModelParameter {
                ValidateModel = new UsersValidator(), SaveModel = UserModel
            });
            return(UpdateData(Data));
        }
        private void SetFreeActions()
        {
            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", null);
            }
        }
        //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"));
        }
        public IActionResult SaveCustomer(List <CustomerMaster> CustomerMasterList)
        {
            Unions     UnionsModel = GetLastRecord <Unions>("tbl_unions");
            QueryParam Query       = new QueryParam
            {
                Fields = "*",
                Table  = "tbl_customer_type"
            };
            List <CustomerType> CustomerTypeList = NewRepo.FindAll <CustomerType>(Query).ToList();

            foreach (CustomerMaster CustomerMasterModel in CustomerMasterList)
            {
                Data = new List <ModelParameter>();

                if (CustomerMasterModel.customer_unique_code.Trim() != "")
                {
                    string prefix = CustomerTypeList.Where(x => x.customer_type == CustomerMasterModel.customer_type).Select(x => x.code_prefix).FirstOrDefault();
                    if (CheckPrefix(prefix, CustomerMasterModel.customer_code))
                    {
                        CustomerMaster NewModel = NewRepo.Find <CustomerMaster>(new QueryParam {
                            Where = new List <ConditionParameter> {
                                Condition("ref_code", CustomerMasterModel.customer_unique_code)
                            }
                        });
                        if (NewModel == null)
                        {
                            CustomerMasterModel.ref_code             = CustomerMasterModel.customer_unique_code;
                            CustomerMasterModel.x_col1               = SetDcsXcol(CustomerMasterModel.allow_multiple_milktype);
                            CustomerMasterModel.originating_org_code = CustomerMasterModel.union_code = UnionsModel.union_code;
                            Data.Add(new ModelParameter {
                                SaveModel = CustomerMasterModel, ValidateModel = new CustomerMasterValidator()
                            });
                        }
                        else
                        {
                            NewModel.customer_unique_code = CustomerMasterModel.customer_unique_code;
                            NewModel.bmc_code             = CustomerMasterModel.bmc_code;
                            NewModel.x_col1          = SetDcsXcol(CustomerMasterModel.allow_multiple_milktype);
                            NewModel.route_code      = CustomerMasterModel.route_code;
                            NewModel.customer_name   = CustomerMasterModel.customer_name;
                            NewModel.is_active       = CustomerMasterModel.is_active;
                            NewModel.mobile_no       = CustomerMasterModel.mobile_no;
                            NewModel.customer_type   = CustomerMasterModel.customer_type;
                            NewModel.model_operation = "update";
                            Data.Add(new ModelParameter {
                                SaveModel = NewModel, ValidateModel = new CustomerMasterValidator()
                            });
                        }
                        SaveData(CustomerMasterModel.customer_unique_code);
                    }
                    else
                    {
                        _response.Add(new CustomResponse {
                            status = "300", msg = "error:customer_code:Invalid Code"
                        });
                    }
                }
                else
                {
                    _response.Add(new CustomResponse {
                        status = "300", msg = "error:customer_unique_code:Require"
                    });
                }
            }
            return(new CustomResult("success", _response));
        }
Exemple #16
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"));
            }
        }
Exemple #17
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."));
        }
Exemple #18
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."));
            }
        }
        //private string CheckCustomerCode(string customer_type)
        //{
        //    QueryParam Query = new QueryParam
        //    {
        //        Fields = "*",
        //        Table = "tbl_customer_type",
        //        Where = new List<ConditionParameter>
        //            {
        //                Condition("customer_type",customer_type)
        //            }
        //    };
        //    CustomerType CustomerTypeModel = NewRepo.Find<CustomerType>(Query);


        //    if (CustomerTypeModel.customer_type== "VENDOR") { }



        //}
        public IActionResult Upload(IFormFile File, int rate_type)
        {
            Data = new List <ModelParameter>();
            if (Path.GetExtension(File.FileName).ToLower() != ".csv")
            {
                return(new CustomResult("success", new CustomResponse {
                    key_code = "0", status = "300", msg = "error:Only Csv File Allowed"
                }));
            }
            string[] param = File.FileName.Split('_');
            if (param.Count() != 2)
            {
                return(new CustomResult("success", new CustomResponse {
                    key_code = "0", status = "300", msg = "error:Wrong FileName Format"
                }));
            }
            string DirectoryPath = FileHelper.FileServerPath();

            FileHelper.CreateDirectory(FileHelper.FileServerPath());
            ImportFile ImportFileModel = new ImportFile
            {
                file_name     = File.FileName,
                process_name  = "purchase_rate",
                new_file_path = FileHelper.NewFileName(DirectoryPath, "purchase_rate", "csv")
            };

            Data.Add(new ModelParameter {
                ValidateModel = new ImportFileValidator(), SaveModel = ImportFileModel
            });
            using (var fileStream = new FileStream(ImportFileModel.new_file_path, FileMode.Create))
            {
                File.CopyTo(fileStream);
                SaveData(Data);
            }
            string rate = NewRepo.Find <string>(new QueryParam {
                Fields = "purchase_rate_code",
                Table  = "tbl_purchase_rate",
                Where  = new List <ConditionParameter> {
                    Condition("purchase_rate_code", param[0].Trim())
                }
            });

            if (rate == param[0].Trim())
            {
                return(new CustomResult("success", new CustomResponse {
                    key_code = param[0], status = "300", msg = "error:Rate already Exist"
                }));
            }
            string tablename   = NumericHelper.RandomNumber().ToString() + "tmp";
            string DirectQuery = $"create table {tablename}(id int not null AUTO_INCREMENT PRIMARY KEY,fat decimal(18,2),snf decimal(18,2),milk_type varchar(5),rtpl decimal(18,2),class varchar(5) null default '0',milk_type_code int null); LOAD DATA LOCAL INFILE  '{ImportFileModel.new_file_path.Replace('\\', '/')}' INTO TABLE {tablename}  FIELDS TERMINATED BY ';'  IGNORE 1 ROWS (fat,snf,milk_type,rtpl); ";

            if (rate_type != 0)
            {
                DirectQuery = $"create table {tablename}(id int not null AUTO_INCREMENT PRIMARY KEY,fat decimal(18,2),snf decimal(18,2),milk_type varchar(5),rtpl decimal(18,2),class varchar(5) null default '0',milk_type_code int null); LOAD DATA LOCAL INFILE  '{ImportFileModel.new_file_path.Replace('\\', '/')}' INTO TABLE {tablename} FIELDS TERMINATED BY ';'  IGNORE 1 ROWS (fat,snf,milk_type,rtpl,class); ";
            }
            NewRepo.Add(new QueryParam
            {
                DirectQuery = DirectQuery
            });
            string value = NewRepo.Find <string>(new QueryParam {
                Sp    = "import_rate",
                Where = new List <ConditionParameter>
                {
                    Condition("p_rate_code", param[0].Trim()),
                    Condition("p_rate_date", $"{param[1].Substring(4,4)}-{param[1].Substring(2,2)}-{param[1].Substring(0,2)}"),
                    Condition("p_table_name", tablename),
                    Condition("p_usercode", UserData.user_code),
                }
            });

            if (value == "1")
            {
                return(new CustomResult("success", new CustomResponse {
                    key_code = param[0], status = "200", msg = "success"
                }));
            }
            else
            {
                return(new CustomResult("success", new CustomResponse {
                    key_code = param[0], status = "300", msg = "error"
                }));
            }
        }
        private TmpUserToken SetUserCache(Users UserData)
        {
            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", UserData.user_code)
                }
            };
            List <UserOrganizationMapping> _UserOrganizationMappingList = NewRepo.FindAll <UserOrganizationMapping>(Query).ToList();

            if (_UserOrganizationMappingList == null || _UserOrganizationMappingList.Count == 0)
            {
                return(null);
            }
            Query = new QueryParam()
            {
                Table  = "user_role",
                Fields = "role_code",
                Where  = new List <ConditionParameter> {
                    Condition("user_code", UserData.user_code)
                }
            };
            TmpUserToken _TmpUserToken = new TmpUserToken
            {
                token        = UserData.token,
                username     = UserData.user_name,
                user_code    = UserData.user_code,
                id           = UserData.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  = UserData.reference_code,
                exp          = DateTime.Now.AddHours(6)
            };

            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, "in")
                }
            };
            _TmpUserToken.actions = NewRepo.FindAll <string>(Query).ToList();
            return(_TmpUserToken);
        }
        public IActionResult SaveBmc(List <Bmc> BmcList)
        {
            Unions   UnionsModel = GetLastRecord <Unions>("tbl_unions");
            Plant    PlantModel  = GetLastRecord <Plant>("tbl_plant");
            MccPlant MccModel    = GetLastRecord <MccPlant>("tbl_mcc_plant");

            foreach (Bmc BmcModel in BmcList)
            {
                Data = new List <ModelParameter>();
                if (BmcModel.bmc_code != "")
                {
                    Bmc NewModel = NewRepo.FindByKey <Bmc>(BmcModel.bmc_code);
                    if (NewModel == null)
                    {
                        BmcModel.ref_code   = BmcModel.bmc_code;
                        BmcModel.union_code = BmcModel.originating_org_code = UnionsModel.union_code;
                        BmcModel.plant_code = PlantModel.plant_code;
                        if (UnionsModel.has_bmc == true && UnionsModel.has_mcc == false)
                        {
                            BmcModel.mcc_plant_code = BmcModel.bmc_code;
                            MccPlant MccPlantModel = new MccPlant
                            {
                                mcc_plant_code = BmcModel.bmc_code,
                                plant_code     = PlantModel.plant_code,
                                name           = BmcModel.bmc_name,
                                ref_code       = BmcModel.ref_code,
                                contact_person = BmcModel.bmc_incharge_name,
                                mobile_no      = BmcModel.contact_no
                            };
                            MccPlantModel.union_code = MccPlantModel.originating_org_code = BmcModel.union_code;
                            Data.Add(new ModelParameter {
                                SaveModel = MccPlantModel, ValidateModel = new MccPlantValidator()
                            });
                        }
                        else
                        {
                            BmcModel.mcc_plant_code = MccModel.mcc_plant_code;
                        }
                        Data.Add(new ModelParameter {
                            SaveModel = BmcModel, ValidateModel = new BmcValidator()
                        });
                    }
                    else
                    {
                        if (UnionsModel.has_bmc == true && UnionsModel.has_mcc == false)
                        {
                            MccPlant MccPlantModel = NewRepo.FindByKey <MccPlant>(BmcModel.bmc_code);
                            MccPlantModel.name            = BmcModel.bmc_name;
                            MccPlantModel.contact_person  = BmcModel.bmc_incharge_name;
                            MccPlantModel.mobile_no       = BmcModel.contact_no;
                            MccPlantModel.model_operation = "update";
                            Data.Add(new ModelParameter {
                                SaveModel = MccPlantModel, ValidateModel = new MccPlantValidator()
                            });
                        }
                        NewModel.bmc_name          = BmcModel.bmc_name;
                        NewModel.is_active         = BmcModel.is_active;
                        NewModel.bmc_incharge_name = BmcModel.bmc_incharge_name;
                        NewModel.contact_no        = BmcModel.contact_no;
                        NewModel.model_operation   = "update";
                        Data.Add(new ModelParameter {
                            SaveModel = NewModel, ValidateModel = new BmcValidator()
                        });
                    }
                    SaveData(BmcModel.bmc_code);
                }
                else
                {
                    _response.Add(new CustomResponse {
                        status = "300", msg = "error:bmc_code"
                    });
                }
            }
            return(new CustomResult("success", _response));
        }
        public IActionResult SaveMember(List <Member> MemberList)
        {
            Unions UnionsModel = GetLastRecord <Unions>("tbl_unions");

            foreach (Member MemberModel in MemberList)
            {
                Data = new List <ModelParameter>();
                if (MemberModel.member_unique_code.Trim() != "")
                {
                    if (MemberModel.member_code.Length > 4)
                    {
                        return(new CustomResult("success", new CustomResponse {
                            status = "300", msg = "error:member_code:Max Length Should be 4"
                        }));
                    }
                    WelcomeParamStationResult _welcome = NewRepo.Find <WelcomeParamStationResult>(new QueryParam
                    {
                        Fields = "welcome_param_station_result.id,welcome_param_id,station_code,param_value",
                        Join   = new List <JoinParameter>
                        {
                            new JoinParameter {
                                table = "welcome_params", condition = "welcome_params.id=welcome_param_id and param_name=\"NameFlag\""
                            },
                            new JoinParameter {
                                table = "tbl_dcs", condition = "tbl_dcs.ref_code=welcome_param_station_result.station_code"
                            }
                        },
                        Where = new List <ConditionParameter>
                        {
                            Condition("tbl_dcs.dcs_code", MemberModel.dcs_code)
                        }
                    });
                    if (_welcome != null)
                    {
                        _welcome.model_operation = "update";
                        _welcome.param_value     = "Y";
                        Data.Add(new ModelParameter {
                            SaveModel = _welcome, ValidateModel = null
                        });
                    }
                    Member NewModel = NewRepo.Find <Member>(new QueryParam {
                        Where = new List <ConditionParameter> {
                            Condition("ref_code", MemberModel.member_unique_code)
                        }
                    });
                    if (NewModel == null)
                    {
                        MemberModel.ex_member_code       = MemberModel.member_code;
                        MemberModel.member_code          = MemberModel.dcs_code + MemberModel.member_code.PadLeft(4, '0');
                        MemberModel.originating_org_code = UnionsModel.union_code;
                        MemberModel.ref_code             = MemberModel.member_unique_code;
                        Data.Add(new ModelParameter {
                            SaveModel = MemberModel, ValidateModel = new MemberValidator()
                        });
                    }
                    else
                    {
                        NewModel.member_unique_code = MemberModel.member_unique_code;
                        NewModel.dcs_code           = MemberModel.dcs_code;
                        NewModel.member_name        = MemberModel.member_name;
                        NewModel.is_active          = MemberModel.is_active;
                        NewModel.mobile_no          = MemberModel.mobile_no;
                        NewModel.model_operation    = "update";
                        Data.Add(new ModelParameter {
                            SaveModel = NewModel, ValidateModel = new MemberValidator()
                        });
                    }
                    SaveData(MemberModel.member_unique_code);
                }
                else
                {
                    _response.Add(new CustomResponse {
                        status = "300", msg = "error:member_unique_code:require"
                    });
                }
            }
            return(new CustomResult("success", _response));
        }