Ejemplo n.º 1
0
        public ActionResult ShowFormEditMasterData(long id)
        {
            MasterDataViewModel    masterData     = new MasterDataViewModel();
            List <MasterDataModel> ListMasterData = new List <MasterDataModel>();
            List <LanguageModel>   languages      = new List <LanguageModel>();
            //list language
            var localizationService = EngineContext.Current.Resolve <ILocalizationService>();
            var responseLanguage    = localizationService.GetLanguage();

            if (responseLanguage != null)
            {
                var resultLanguage = JsonConvert.DeserializeObject <HrmResultModel <LanguageModel> >(responseLanguage);
                if (!CheckPermission(resultLanguage))
                {
                    //return to Access Denied
                }
                else
                {
                    languages            = resultLanguage.Results;
                    masterData.Languages = JsonConvert.DeserializeObject <List <dynamic> >(JsonConvert.SerializeObject(resultLanguage.Results));
                }
            }
            var responseMasterData = _masterDataService.GetMasterDataById(id);

            if (responseMasterData != null)
            {
                var result = JsonConvert.DeserializeObject <HrmResultModel <MasterDataModel> >(responseMasterData);
                if (!CheckPermission(result))
                {
                    //return to Access Denied
                }
                else
                {
                    masterData.MasterData = result.Results[0];
                    masterData.GroupId    = result.Results[0].GroupId;
                }
            }
            var responseMasterDatas = localizationService.GetLocalizedDataByDataId(id, DataType.MasterData);
            List <LocalizedDataModel> LocalizedDatas = new List <LocalizedDataModel>();

            if (responseMasterDatas != null)
            {
                var resultMasterDatas = JsonConvert.DeserializeObject <HrmResultModel <LocalizedDataModel> >(responseMasterDatas);
                if (!CheckPermission(resultMasterDatas))
                {
                    //return to Access Denied
                }
                else
                {
                    LocalizedDatas = resultMasterDatas.Results;
                    var listProp = localizationService.GetMultipleLanguageConfiguration(DataType.MasterData);
                    var listData = new List <MasterDataModel>();
                    foreach (var language in languages)
                    {
                        var data = LocalizedDatas.Where(s => s.LanguageId == language.Id).ToList();
                        if (data != null && data.Count() > 0)
                        {
                            MasterDataModel MasterData = new MasterDataModel();
                            var             response   = FunctionHelpers.ConvertLanguageToModel(data, MasterData, listProp.Results);
                            response.LanguageId = language.Id;
                            ListMasterData.Add(response);
                        }
                    }
                }
            }
            masterData.ListMasterDataByLanguage = JsonConvert.DeserializeObject <List <dynamic> >(JsonConvert.SerializeObject(ListMasterData));
            return(PartialView("~/Administration/Views/MasterData/_AddMasterData.cshtml", masterData));
        }
Ejemplo n.º 2
0
        public ActionResult ShowFormAddSalaryElement(long id = 0)
        {
            AddSalaryElementViewModel addSalaryElement_vm = new AddSalaryElementViewModel();
            var listGroup = new List <LongTypeModel>();

            listGroup.Add(new LongTypeModel()
            {
                Value = MasterDataId.Type
            });
            listGroup.Add(new LongTypeModel()
            {
                Value = MasterDataId.DataType
            });
            var listGropuId              = MapperHelper.MapList <LongTypeModel, LongType>(listGroup);
            var resultMasterData         = this._masterDataService.GetAllMasterDataByListGroupId(listGropuId);
            var responseMasterDataDetail = JsonConvert.DeserializeObject <HrmResultModel <dynamic> >(resultMasterData);

            if (!CheckPermission(responseMasterDataDetail))
            {
                //return to Access Denied
            }
            else
            {
                addSalaryElement_vm.Types     = responseMasterDataDetail.Results.Where(m => m.GroupId == MasterDataId.Type).ToList();
                addSalaryElement_vm.DataTypes = responseMasterDataDetail.Results.Where(m => m.GroupId == MasterDataId.DataType).ToList();
            }
            //list language
            var localizationService = EngineContext.Current.Resolve <ILocalizationService>();
            var responseLanguage    = localizationService.GetLanguage();

            if (responseLanguage != null)
            {
                var resultLanguage = JsonConvert.DeserializeObject <HrmResultModel <LanguageModel> >(responseLanguage);
                if (!CheckPermission(resultLanguage))
                {
                    //return to Access Denied
                }
                else
                {
                    addSalaryElement_vm.Languages = resultLanguage.Results;
                }
            }
            if (id != 0)
            {
                var responseSalaryElement = _salaryElementService.GetSalaryElementById(id);
                if (responseSalaryElement != null)
                {
                    var resultSalaryElement = JsonConvert.DeserializeObject <HrmResultModel <SalaryElementModel> >(responseSalaryElement);
                    if (!CheckPermission(resultSalaryElement))
                    {
                        //return to Access Denied
                    }
                    else
                    {
                        addSalaryElement_vm.SalaryElement = resultSalaryElement.Results.FirstOrDefault();
                    }
                }
                var responseLocalizedDatas = localizationService.GetLocalizedDataByDataId(id, DataType.SalaryElement);
                List <LocalizedDataModel> LocalizedDatas = new List <LocalizedDataModel>();
                if (responseLocalizedDatas != null)
                {
                    var resultLocalizedDatas = JsonConvert.DeserializeObject <HrmResultModel <LocalizedDataModel> >(responseLocalizedDatas);
                    if (!CheckPermission(resultLocalizedDatas))
                    {
                        //return to Access Denied
                    }
                    else
                    {
                        LocalizedDatas = resultLocalizedDatas.Results;
                        var listProp = localizationService.GetMultipleLanguageConfiguration(DataType.SalaryElement);
                        var listData = new List <SalaryElementModel>();
                        if (addSalaryElement_vm.Languages != null && addSalaryElement_vm.Languages.Count() > 0)
                        {
                            foreach (var language in addSalaryElement_vm.Languages)
                            {
                                var data = LocalizedDatas.Where(s => s.LanguageId == language.Id).ToList();
                                if (data != null && data.Count() > 0)
                                {
                                    SalaryElementModel salaryElement = new SalaryElementModel();
                                    var response = FunctionHelpers.ConvertLanguageToModel(data, salaryElement, listProp.Results);
                                    response.LanguageId = language.Id;
                                    addSalaryElement_vm.SalaryElements.Add(response);
                                }
                            }
                        }
                    }
                }
                else
                {
                    addSalaryElement_vm.SalaryElements.Add(new SalaryElementModel());
                }
            }
            return(PartialView(UrlHelpers.TemplateAdmin("SalaryElement", "_FormAddSalaryElement.cshtml"), addSalaryElement_vm));
        }