public long Set([FromBody] CommonDictionary dictionary) { var currentDictionary = _sqlMapper.QuerySingle <CommonDictionary>(new RequestContext { SqlId = "Get", Scope = "CommonDictionary", Request = new { dictionary.Key } }); if (currentDictionary == null) { dictionary.CreateTime = DateTime.Now; return(_commonDictionaryRepository.Add(dictionary)); } return(_sqlMapper.Execute(new RequestContext { SqlId = "Set", Scope = "CommonDictionary", Request = new { dictionary.Key, dictionary.Value } })); }
public ActionResult DeleteConfirmed(long id) { CommonDictionary commonDictionary = db.CommonDictionaries.Find(id); db.CommonDictionaries.Remove(commonDictionary); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create([Bind(Include = "Id,CDKey,CDValue,LanguageId,SortOrder")] CommonDictionary commonDictionary) { if (ModelState.IsValid) { db.CommonDictionaries.Add(commonDictionary); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.LanguageId = new SelectList(db.Languages, "Id", "Title", commonDictionary.LanguageId); return(View(commonDictionary)); }
public ActionResult Edit([Bind(Include = "Id,CDKey,CDValue,LanguageId,SortOrder")] CommonDictionary commonDictionary) { if (ModelState.IsValid) { db.Entry(commonDictionary).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.LanguageId = new SelectList(db.Languages, "Id", "Title", commonDictionary.LanguageId); return(View(commonDictionary)); }
public int CreateOrUpdate(CommonDictionary model) { var get = _repo.Get(model.ID); if (get == null) { _repo.Insert(model); } else { _repo.Update(model); } return(model.ID); }
// GET: CommonDictionaries/Details/5 public ActionResult Details(long?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CommonDictionary commonDictionary = db.CommonDictionaries.Find(id); if (commonDictionary == null) { return(HttpNotFound()); } return(View(commonDictionary)); }
public static List <CommonDictionary> GetValuesByKey(string key) { List <CommonDictionary> lstCommonDictionary = new List <CommonDictionary>(); try { using (SPSite oSPsite = new SPSite(SPContext.Current.Web.Url)) { using (SPWeb oSPWeb = oSPsite.OpenWeb()) { string listName = "CommonDictionary"; // Fetch the List SPList spList = oSPWeb.GetList(string.Format("{0}/Lists/{1}/AllItems.aspx", oSPWeb.Url, listName)); SPQuery query = new SPQuery(); SPListItemCollection spListItems; // Include only the fields you will use. query.ViewFields = "<FieldRef Name='Title'/><FieldRef Name='Value'/><FieldRef Name='SortOrder'/>"; query.ViewFieldsOnly = true; StringBuilder sb = new StringBuilder(); sb.Append("<Where>") .Append("<Eq>") .Append("<FieldRef Name='Title' />") .Append("<Value Type='Text'>" + key + "</Value>") .Append("</Eq>") .Append("</Where>"); query.Query = sb.ToString(); spListItems = spList.GetItems(query); for (int i = 0; i < spListItems.Count; i++) { SPListItem listItem = spListItems[i]; CommonDictionary commonDictionary = new CommonDictionary(); commonDictionary.Key = Convert.ToString(listItem["Title"]); commonDictionary.Value = Convert.ToString(listItem["Value"]); commonDictionary.SortOrder = Convert.ToInt32(listItem["SortOrder"]); lstCommonDictionary.Add(commonDictionary); } } } } catch (Exception ex) { SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory("SL.FG.FFL(Utility->GetValuesByKey)", TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected, ex.Message, ex.StackTrace); } return(lstCommonDictionary); }
public object Execute(ISession session) { CommonDictionary dic = ActiveRecordHelp.GetFilterSql(_query, _start, _limit, _sort, _dir, _tableName, _primaryKey, _filters, _otherWhere, _otherParameter); ISQLQuery query = session.CreateSQLQuery(dic.ContentSql).AddEntity(typeof(T)); if (dic.Parameters != null) { foreach (DictionaryEntry par in dic.Parameters) { query.SetParameter(par.Key.ToString(), par.Value); } } return(query.List()); }
public object Execute(ISession session) { CommonDictionary dic = ActiveRecordHelp.GetFilgerCount(_tableName, _filters, _otherWhere, _otherParameter); ISQLQuery query = session.CreateSQLQuery(dic.ContentSql); if (dic.Parameters != null) { foreach (DictionaryEntry par in dic.Parameters) { query.SetParameter(par.Key.ToString(), par.Value); } } return(query.List()[0]); }
// GET: CommonDictionaries/Edit/5 public ActionResult Edit(long?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CommonDictionary commonDictionary = db.CommonDictionaries.Find(id); if (commonDictionary == null) { return(HttpNotFound()); } ViewBag.LanguageId = new SelectList(db.Languages, "Id", "Title", commonDictionary.LanguageId); return(View(commonDictionary)); }
/// <summary> /// 返回记录总数SQL /// </summary> public static CommonDictionary GetFilgerCount(string tableName, string[][] filters, string otherWhere, params object[] otherParemeters) { CommonDictionary dic = GetFilgerWhere(null, null, null, filters, otherWhere, otherParemeters); string where = dic.ContentSql; if (where.Contains(" order")) { where = where.Substring(0, where.LastIndexOf(" order")); } if (string.IsNullOrEmpty(where)) { where = string.Format("select count(*) from {0}", tableName); } else { where = string.Format("select count(*) from {0} where {1}", tableName, where); } dic.ContentSql = where; return(dic); }
public static CommonDictionary GetFilterSql(string query, int start, int limit, string sort, string dir, string tableName, string primaryKey, string[][] filters, string otherWhere, params object[] otherParemeters) { CommonDictionary dic = GetFilgerWhere(start, limit, sort, dir, tableName, primaryKey, filters, otherWhere, otherParemeters); string where = dic.Sql; if (string.IsNullOrEmpty(where)) { where = string.Format("select top {0} {4} from {1} where {2} not in (select top {3} {2} from {1} )", limit, tableName, primaryKey, start, query); } else { if (where.StartsWith(" order")) { where = string.Format("select top {0} {5} from {1} where {2} not in (select top {3} {2} from {1} {4}) {4}", limit, tableName, primaryKey, start, where, query); } else { where = string.Format("select top {0} {5} from {1} where {2} not in (select top {3} {2} from {1} where {4}) and {4}", limit, tableName, primaryKey, start, where, query); } } dic.Sql = where; return(dic); }
private static CommonDictionary GetFilgerWhere(string sort, string dir, string primaryKey, string[][] filters, string otherWhere, params object[] otherParemeters) { CommonDictionary dic = new CommonDictionary(); StringBuilder builder = new StringBuilder(); int i = 1; foreach (string[] filter in filters) { if (!string.IsNullOrEmpty(filter[1])) { switch (filter[1]) { case "eq": builder.Append(string.Format(" and {0}=:{1}", filter[2], i)); dic.AddParameter(i.ToString(), filter[3]); i++; break; case "lt": builder.Append(string.Format(" and {0}<=:{1}", filter[2], i)); dic.AddParameter(i.ToString(), filter[3]); i++; break; case "gt": builder.Append(string.Format(" and {0}>=:{1}", filter[2], i)); dic.AddParameter(i.ToString(), filter[3]); i++; break; } } else { builder.Append(string.Format(" and {0} like :{1}", filter[2], i)); dic.AddParameter(i.ToString(), string.Format("%{0}%", filter[3])); i++; } } if (!string.IsNullOrEmpty(otherWhere)) { string[] ws = otherWhere.Trim().Split(new string[] { "?" }, StringSplitOptions.RemoveEmptyEntries); for (int j = 0; j < ws.Length; j++) { if (j != ws.Length - 1) { builder.Append(string.Format(" {0}:{1}", ws[j], i)); dic.AddParameter(i.ToString(), otherParemeters[j]); i++; } else if (j == 0 && otherWhere.Contains("?")) { builder.Append(string.Format(" {0}:{1}", ws[j], i)); dic.AddParameter(i.ToString(), otherParemeters[j]); i++; } else builder.Append(string.Format(" {0}", ws[j])); } } if (!string.IsNullOrEmpty(sort)) builder.Append(string.Format(" order by {0} {2},{1} {2}", sort, primaryKey, dir)); string where = builder.ToString(); if (where.StartsWith(" and")) where = where.Substring(4); if (where.StartsWith("and")) where = where.Substring(3); dic.ContentSql = where; return dic; }
public long Add([FromBody] CommonDictionary dictionary) { dictionary.CreateTime = DateTime.Now; return(_commonDictionaryRepository.Add(dictionary)); }
private static CommonDictionary GetFilgerWhere(int start, int limit, string sort, string dir, string tableName, string primaryKey, string[][] filters, string otherWhere, params object[] otherParemeters) { CommonDictionary dic = new CommonDictionary(); StringBuilder builder = new StringBuilder(); int i = 1; foreach (string[] filter in filters) { if (!string.IsNullOrEmpty(filter[1])) { switch (filter[1]) { case "eq": builder.Append(string.Format(" and {0}=:{1}", filter[2], i)); dic.AddParameter(i.ToString(), filter[3]); i++; break; case "lt": builder.Append(string.Format(" and {0}<=:{1}", filter[2], i)); dic.AddParameter(i.ToString(), filter[3]); i++; break; case "gt": builder.Append(string.Format(" and {0}>=:{1}", filter[2], i)); dic.AddParameter(i.ToString(), filter[3]); i++; break; } } else { builder.Append(string.Format(" and {0} like @{1}", filter[2], i)); dic.AddParameter(i.ToString(), string.Format("%{0}%", filter[3])); i++; } } if (!string.IsNullOrEmpty(otherWhere)) { string[] ws = otherWhere.Trim().Split(new string[] { "?" }, StringSplitOptions.RemoveEmptyEntries); for (int j = 0; j < ws.Length; j++) { if (j != ws.Length - 1) { builder.Append(string.Format(" {0}:{1}", ws[j], i)); dic.AddParameter(i.ToString(), otherParemeters[j]); i++; } else if (j == 0 && otherWhere.Contains("?")) { builder.Append(string.Format(" {0}:{1}", ws[j], i)); dic.AddParameter(i.ToString(), otherParemeters[j]); i++; } else { builder.Append(string.Format(" {0}", ws[j])); } } } if (!string.IsNullOrEmpty(sort)) { builder.Append(string.Format(" order by {0} {2},{1} {2}", sort, primaryKey, dir)); } string where = builder.ToString(); if (where.StartsWith(" and")) { where = where.Substring(4); } if (where.StartsWith("and")) { where = where.Substring(3); } dic.Sql = where; return(dic); }
public void Update(CommonDictionary model) { _repo.Update(model); }
public int Create(CommonDictionary model) { _repo.Insert(model); return(model.ID); }
public async Task <ResultContract <string> > UploadFile(BaseUploadContract data) { var result = new ResultContract <string>() { Code = 0, Msg = "上传成功" }; try { //验证参数 var orgInfo = new OrganizationContract(); this.CheckParameter(data, ref result, ref orgInfo); if (result.Code == -1) { return(result); } List <UploadContract> fileList = new List <UploadContract>(); var files = Request.Form.Files; var groupId = Guid.NewGuid().ToString(); int order = 1; foreach (var file in files) { var fileModel = new UploadContract() { UserId = data.UserId, OrgId = data.OrgId, AppId = data.AppId, Tags = data.Tags, UploadTime = DateTime.Now, DisplayName = data.DisplayName, Remark = data.Remark, OrgName = orgInfo.OrganizationName, Order = order, ThemeType = data.ThemeType }; //分组id fileModel.GroupId = groupId; var fileData = new MultipartFormDataContent(); //判断文件夹是否存在 if (!Directory.Exists(uploadFilePath)) { Directory.CreateDirectory(uploadFilePath); } var imgPath = AppDomain.CurrentDomain.BaseDirectory + ConfigHelper.ReadConfigByName("ImgsPath"); if (!Directory.Exists(imgPath)) { Directory.CreateDirectory(imgPath); } fileModel.FileName = file.FileName; var lastName = file.FileName.Substring(file.FileName.LastIndexOf(".") + 1, (file.FileName.Length - file.FileName.LastIndexOf(".") - 1)); //扩展名 fileModel.FileId = Guid.NewGuid(); fileModel.NewFileName = fileModel.FileId + "." + lastName; var fileLocalFullName = uploadFilePath + Path.DirectorySeparatorChar + fileModel.NewFileName; var stream = file.OpenReadStream(); //文件保存到本地 double fileSize = 0; //保存文件 FileHelper.SavaFile(fileLocalFullName, stream, ref fileSize); //文件上传成功 修改model fileModel.IsUpload = false; fileModel.Url = fileLocalFullName; fileModel.FileType = lastName; //组织名称。后期加上 //判断文件大小 double uploadLimitSize = 0; double.TryParse(ConfigHelper.ReadConfigByName("UploadLimitSizeM"), out uploadLimitSize); //如果是视频截取封面 if (CommonDictionary.GetInstance().VideoType.Count(d => d.ToLower() == lastName.ToLower()) > 0) { var thumbnailPath = AliyunOSSHepler.GetInstance().GetPicFromVideo(fileLocalFullName, imgPath + Path.DirectorySeparatorChar + fileModel.FileId + ".jpg", "1"); var thumbnailUrl = ""; var isUpload = AliyunOSSHepler.GetInstance().UploadFiles(imgPath, fileModel.FileId + ".jpg", ref thumbnailUrl, true); fileModel.ThumbnailUrl = thumbnailPath; if (isUpload && !string.IsNullOrWhiteSpace(thumbnailUrl)) { fileModel.ThumbnailUrl = thumbnailUrl; } else { fileModel.IsFailure = true; this._uploadHandService.SavaTagsFile(fileModel); //把文件 移动到错误文件 文件夹 System.IO.File.Move(uploadFilePath + Path.DirectorySeparatorChar + fileModel.NewFileName, FailurePath + Path.DirectorySeparatorChar + fileModel.NewFileName); result.Code = -1; result.Msg = "截图失败"; return(result); } } //如果断网把标签和文件都存到本地 if (!CommonDictionary.GetInstance().KafkaIsOnline) { this._uploadHandService.SavaTagsFile(fileModel); } else { //如果文件大小比预设大小 小 直接上云 if (fileSize < uploadLimitSize) { var url = ""; fileModel.IsUpload = AliyunOSSHepler.GetInstance().UploadFiles(uploadFilePath, fileModel.NewFileName, ref url, false); //如果上传失败 标签存本地 if (!fileModel.IsUpload) { fileModel.IsFailure = true; this._uploadHandService.SavaTagsFile(fileModel); //把文件 移动到错误文件 文件夹 System.IO.File.Move(uploadFilePath + Path.DirectorySeparatorChar + fileModel.NewFileName, FailurePath + Path.DirectorySeparatorChar + fileModel.NewFileName); } else { fileModel.Url = url; } } fileList.Add(fileModel); order++; } } ////把标签 推送到总署 KafKaContract kafkaModel = new KafKaContract(); if (fileList.Count > 1) //批量添加 { kafkaModel.MsgCode = KafkaMsgCodeEnum.AddList; kafkaModel.Msg = SerializeHelper.serializeToString(fileList); KafKaLogic.GetInstance().Push(kafkaModel, KafkaTopic); } else if (fileList.Count() == 1) //单个文件添加 { kafkaModel.MsgCode = KafkaMsgCodeEnum.Add; fileList[0].GroupId = Guid.NewGuid().ToString(); kafkaModel.Msg = SerializeHelper.serializeToString(fileList[0]); KafKaLogic.GetInstance().Push(kafkaModel, KafkaTopic); } } catch (Exception e) { LogHelper.logError("上传文件失败:" + e.StackTrace); result.Code = -1; result.Msg = e.Message; } return(result); }