Esempio n. 1
0
        public GenericListModel <SettingModel> GetSearchSettingsList(DataTableSearchParameters <Nullable <bool> > dataTableSearchParameters)
        {
            GenericListModel <SettingModel> baseListModel = new GenericListModel <SettingModel>();

            try
            {
                //if (!base.UserHasPermision(baseListModel))
                //    return baseListModel;

                IQueryable <Setting> settings = dbContext.Settings.OrderBy(x => x.CreatedAt);

                if (!string.IsNullOrEmpty(dataTableSearchParameters.search.value))
                {
                    settings = settings.Where(x => x.Key.ToLower().Contains(dataTableSearchParameters.search.value.ToLower()));
                }

                foreach (JQDTColumnOrder order in dataTableSearchParameters.order)
                {
                    switch (order.column)
                    {
                    case 0:
                        if (order.dir == JQDTColumnOrderDirection.asc)
                        {
                            settings = CommonLayer.Helpers.Utilites.GetLocalizedOrderBy(settings.OrderBy(c => c.EnglishName), settings.OrderBy(c => c.ArabicName));
                        }
                        else
                        {
                            settings = CommonLayer.Helpers.Utilites.GetLocalizedOrderBy(settings.OrderByDescending(c => c.EnglishName), settings.OrderByDescending(c => c.ArabicName));
                        }
                        break;
                    }
                }

                baseListModel.Total = settings.Count();
                settings            = settings.Skip(dataTableSearchParameters.start);

                if (dataTableSearchParameters.length != -1)
                {
                    settings = settings.Take(dataTableSearchParameters.length);
                }


                SettingMapper.Map(settings.ToList(), baseListModel.List);
            }
            catch (Exception ex)
            {
                base.HandleError(baseListModel, CommonLayer.LookUps.ErrorType.Critical, ex);
            }

            return(baseListModel);
        }
Esempio n. 2
0
        public void GetSettingModel(SettingModel settingModel)
        {
            try
            {
                Setting setting = dbContext.Settings.Where(x => x.Id == settingModel.Id).FirstOrDefault();

                if (setting == null)
                {
                    base.HandleError(settingModel, CommonLayer.LookUps.ErrorType.Critical, null, Resources.NotFound);
                }
                else
                {
                    SettingMapper.Map(setting, settingModel);
                }
            }
            catch (Exception ex)
            {
                base.HandleError(settingModel, CommonLayer.LookUps.ErrorType.Critical, ex);
            }
        }
Esempio n. 3
0
        public void Edit(SettingModel settingModel)
        {
            List <SettingFileModel> lstOldSettingFileModel = new List <SettingFileModel>();
            string oldImageShortPath = null;

            try
            {
                Setting setting = dbContext.Settings.Where(x => x.Id == settingModel.Id).FirstOrDefault();

                if (settingModel.Type == LookUps.SettingsTypes.Int)
                {
                    settingModel.Value = settingModel.IntValue.ToString();
                }
                else if (settingModel.Type == LookUps.SettingsTypes.Bool)
                {
                    settingModel.Value = settingModel.BoolValue.ToString();
                }
                else if (settingModel.Type == LookUps.SettingsTypes.file)
                {
                    SettingMapper.Map(dbContext.Settings.Find(setting.Id).SettingsFiles.ToList(), lstOldSettingFileModel);
                }
                else if (settingModel.Type == LookUps.SettingsTypes.image)
                {
                    oldImageShortPath  = setting.Value;
                    settingModel.Value = FileHelper.CreateShortFilePath(LookUps.FolderName.Common, settingModel.imageValue.FileName);
                }

                if (setting == null)
                {
                    base.HandleError(settingModel, CommonLayer.LookUps.ErrorType.Critical, null, Resources.NotFound);
                    return;
                }

                dbContext.SettingsFiles.RemoveRange(setting.SettingsFiles);

                SettingMapper.Map(settingModel, setting);

                base.SaveChanges();
                ClearCache(setting.Id);


                if (settingModel.Type == LookUps.SettingsTypes.file)
                {
                    //save new

                    //delete old
                    foreach (var oldSettingFileModel in lstOldSettingFileModel)
                    {
                        FileHelper.DeleteFile(oldSettingFileModel.FileShortPath);
                    }
                }
                else if (settingModel.Type == LookUps.SettingsTypes.image)
                {
                    //save new image and delete old image
                    FileHelper.SaveFileByShortPath(settingModel.Value, settingModel.imageValue);
                    FileHelper.DeleteFileByShortPath(oldImageShortPath);
                }

                settingModel.AddSuccess(Resources.SettingUpdatedSuccessfully, LookUps.SuccessType.Full);
            }
            catch (Exception ex)
            {
                base.HandleError(settingModel, CommonLayer.LookUps.ErrorType.Exception, ex);
                base.UndoUpdates();
            }
        }