public HelpVm Init(long userId, long id) { var parents = LoadAll(userId).Where(h => h.Ctrl == "").ToList(); foreach (var parent in parents) { parent.Title = parent.Title == "" ? Path.GetFileNameWithoutExtension(parent.Page) : parent.Title; } var toRet = new HelpVm { Parents = parents.OrderBy(p => p.Title).ToList(), Orders = BlCode.LoadTable(userId, "DisplayOrder"), ActionMode = Enumerations.ActionMode.Add, Help = new Help { } }; if (id != 0) { var help = LoadSingle(userId, id); toRet.Help = help; toRet.DisplayPage = Path.GetFileNameWithoutExtension(toRet.Help.Page); toRet.DisplayControl = toRet.Help.Ctrl == "" ? "N/A" : toRet.Help.Ctrl; toRet.ActionMode = Enumerations.ActionMode.Edit; } //toRet.Help.User.Roles = null; return(toRet); }
public static string GetDocumentPath(long userId, string reference, string type) { var repository = new DocumentRepository(); var predicate = PredicateBuilder.True <Document>(); predicate = predicate.And(p => p.Reference == reference); predicate = predicate.And(p => p.Type == type); var toRet = repository.LoadSearch(predicate).First(); return(BlCode.LoadSingle(userId, "_System", "DocumentsRootUrl").Value1 + "documents/" + toRet.Path); }
public static List <DdlVm.DdlOption> GetLov(long userId, string operation, bool required, string relCode = "") { if (operation.ToUpper() == "CODETABLES") { return(GetLovTables(userId, required).ToList()); } if (operation.ToUpper() == "BRANCHES") { return(BlBranch.GetLov(userId, required).ToList()); } var user = BlUser.LoadSingle(userId); var fieldName = user.LanguageId == 1 ? "Value1" : "Value2"; var blCode = new BlCode(); var predicate = PredicateBuilder.True <Code>(); predicate = predicate.And(p => p.TableName == operation); if (relCode != "") { predicate = predicate.And(p => p.RelCode == relCode); } var result = blCode.LoadSearch(userId, predicate).ToList(); if (!result.Any()) { return(null); } var results = (from a in result.Where(m => m.Status) orderby a.DisplayOrder ascending select new DdlVm.DdlOption { value = a.CodeName, label = a.GetType().GetProperty(fieldName).GetValue(a, null).ToString() }).ToList(); if (!required) { results.Insert(0, new DdlVm.DdlOption("...", "")); } return(results.ToList()); }
public bool Delete(long userId, Document toDelete) { using (var tran = new TransactionScope()) { var toRet = _repository.Delete(toDelete); //Delete physical file var rootDirectory = BlCode.LoadSingle(userId, "_System", "DocumentsRootDirectory").Value1 + "documents\\"; if (File.Exists(rootDirectory + toDelete.Path)) { File.Delete(rootDirectory + toDelete.Path); } BlLog.Log(userId, Module, "Delete document", "DocumentDeleted", new object[] { toDelete.Name, toDelete.Reference }); tran.Complete(); return(toRet); } }
private static string SavePhysicalFile(long userId, ref HttpPostedFile file, string name, string reference) { var rootDirectory = BlCode.LoadSingle(userId, "_System", "DocumentsRootDirectory").Value1 + "Documents\\"; //Create root directory if needed if (!Directory.Exists(rootDirectory)) { Directory.CreateDirectory(rootDirectory); } //Construct custom directory string customDirectory; if (reference.IndexOf('_') != -1) { customDirectory = reference.Split('_')[0] + "\\" + reference.Replace(reference.Split('_')[0] + "_", "") + "\\"; } else { customDirectory = reference + "\\"; } //Create custom directory if needed if (!Directory.Exists(rootDirectory + customDirectory)) { Directory.CreateDirectory(rootDirectory + customDirectory); } var fileName = name + Path.GetExtension(file.FileName); var destination = rootDirectory + customDirectory + fileName; var i = 1; while (File.Exists(destination)) { fileName = name + "_" + i + Path.GetExtension(file.FileName); destination = rootDirectory + customDirectory + fileName; i += 1; } file.SaveAs(destination); return(customDirectory + fileName); }
public static List <DdlVm.DdlOption> LoadQs(long userId, string parameters, string searchTerm, int pageSize, int pageNum, out long count) { var blObject = new BlCode(); var serializer = new JavaScriptSerializer(); var dict = serializer.Deserialize <Dictionary <string, object> >(parameters); var tableName = CheckEmpty.String(ref dict, "tableName"); var relationKey = CheckEmpty.String(ref dict, "relationKey"); var predicate = PredicateBuilder.True <Code>(); predicate = predicate.And(c => c.TableName == tableName); predicate = predicate.And(c => c.Status); if (CheckEmpty.String(relationKey) != "") { predicate = predicate.And(c => c.RelCode == relationKey); } if (CheckEmpty.String(searchTerm) != "") { var tokens = searchTerm.Tokens(); foreach (var token in tokens) { var predicate2 = PredicateBuilder.False <Code>(); predicate2 = predicate2.Or(c => c.Value1.Contains(token)); predicate2 = predicate2.Or(c => c.Value2.Contains(token)); predicate2 = predicate2.Or(c => c.Value3.Contains(token)); predicate2 = predicate2.Or(c => c.Value4.Contains(token)); predicate2 = predicate2.Or(c => c.Value5.Contains(token)); predicate2 = predicate2.Or(c => c.Value6.Contains(token)); predicate = predicate.And(predicate2); } } var items = blObject.LoadPaging(userId, predicate, pageSize, (pageNum - 1), out count); return(items.Select(i => FormatForQs(userId, i)).ToList()); }
public GridResults LoadPaging(long userId, string search, int pageIndex, out long totalRecords, string sortColumnName = "", string sortOrderBy = "") { //Get current user var user = BlUser.LoadSingle(userId); //Query paged data var results = LoadPaging(userId, CreateFilter(search), user.PageSize, pageIndex - 1, out totalRecords); //Convert results into display model var res = (from r in results select new { r.Id, Url = "<a class='text-primary' href=" + BlCode.LoadSingle(userId, "_System", "DocumentsRootUrl").Value1 + "documents/" + r.Path + " target='_blank' >" + r.Name + "</a>", Type = BlCode.GetCodeByLanguage(user, BlCode.LoadSingle(userId, "DocumentType", r.Type)), EntryDate = r.EntryDate.ToString(true), User = r.UserId == 0 ? "" : BlUser.LoadSingle(r.UserId).UserName, }).ToList(); //Convert display model into json data return(GridVm.FormatResult(res, user.PageSize, pageIndex, totalRecords)); }
public static List <DdlVm.DdlOption> GetLovTables(long userId, bool required) { var blCode = new BlCode(); var result = blCode.LoadTables(userId).ToList(); if (!result.Any()) { return(null); } var results = (from a in result select new DdlVm.DdlOption { value = a, label = a }).ToList(); if (!required) { results.Insert(0, new DdlVm.DdlOption("...", "")); } return(results.ToList()); }