public async Task <ReturnResult> AddKeySection([FromBody] CreateKeySection request) { return(await Task.Run(() => { if (string.IsNullOrWhiteSpace(request.Name)) { throw new AppException("栏目名称不能为空"); } if (int.Parse(request.Level) < 0) { throw new AppException("栏目等级不能为空"); } if (int.Parse(request.Level) > 0 && int.Parse(request.PID) < 0) { throw new AppException("父ID不能为空"); } int iUID = LoginManager.GetUserID(); var mapper = new MapperConfiguration(x => x.CreateMap <CreateKeySection, KeySection>()).CreateMapper(); KeySection keySection = mapper.Map <KeySection>(request); if (keySection.Level == 0) { keySection.PID = 0; } keySection.CreateUserID = iUID; return ReturnResult.ResultCalculation(() => KeySectionManager.Insert(keySection)); })); }
public void Deserialise(BinaryReader bin) { short keyCount = bin.ReadInt16(); if (keyCount > 256) throw new DeserialisationException(string.Format("Bad keypoint count: {0}", keyCount), bin.BaseStream.Position); KeySections = new KeySection[keyCount]; for (int i = 0; i < keyCount; i++) { KeySections[i] = new KeySection(bin.ReadByte(), bin.ReadByte()); } }
public void Deserialise(BinaryReader bin) { short keyCount = bin.ReadInt16(); if (keyCount > 256) { throw new DeserialisationException(string.Format("Bad keypoint count: {0}", keyCount), bin.BaseStream.Position); } KeySections = new KeySection[keyCount]; for (int i = 0; i < keyCount; i++) { KeySections[i] = new KeySection(bin.ReadByte(), bin.ReadByte()); } }
private static KeySection LookupKey(string section, string key) { CacheSection cSection = LookupSection(section); if (cSection == null) { return(null); } KeySection dummyKey = new KeySection(key, ""); int index = cSection.keys.BinarySearch(dummyKey, new KeyCompare()); return((index < 0) || (index >= cSection.keys.Count) ? null : (KeySection)cSection.keys[index]); }
public async Task <ReturnResult> EditKeySection([FromBody] EditKeySection request) { if (int.Parse(request.ID) <= 0) { throw new AppException("栏目ID不能为空"); } if (int.Parse(request.Level) < 0) { throw new AppException("栏目等级不能为空"); } if (int.Parse(request.Level) > 0 && int.Parse(request.PID) < 0) { throw new AppException("父ID不能为空"); } if (string.IsNullOrWhiteSpace(request.Name)) { throw new AppException("栏目名称不能为空"); } KeySection keySection = await KeySectionManager.GetByIdAsync(int.Parse(request.ID)); int iUID = LoginManager.GetUserID(); if (keySection.CreateUserID != iUID) { throw new AppException(ReturnResultStatus.Illegal, "非法操作"); } var mapper = new MapperConfiguration(x => x.CreateMap <EditKeySection, KeySection>()).CreateMapper(); keySection = mapper.Map <KeySection>(request); if (keySection.Level == 0) { keySection.PID = 0; } int iCount = await DbContext.Db.Queryable <KeySection>().Where(x => x.PID == keySection.ID).CountAsync(); if (keySection.Level == 1 && iCount > 0) { throw new AppException("还存在子栏目不能移动到其他栏目下"); } keySection.CreateUserID = iUID; return(ReturnResult.ResultCalculation(() => KeySectionManager.Update(keySection))); }
public static void RemoveFromCache(string section, string key) { KeySection kSection = LookupKey(section, key); if (kSection != null) { CacheSection cSection = LookupSection(section); if (File.Exists(kSection.filename)) { File.Delete(kSection.filename); } cSection.keys.Remove(kSection); if (cSection.keys.Count == 0) { sections.Remove(cSection); } SaveCacheData(); } }
public async Task <ReturnResult> EditKeySectionByName([FromBody] EditKeySectionByName request) { if (int.Parse(request.ID) <= 0) { throw new AppException("栏目ID不能为空"); } if (string.IsNullOrWhiteSpace(request.Name)) { throw new AppException("栏目名称不能为空"); } KeySection keySection = await KeySectionManager.GetByIdAsync(int.Parse(request.ID)); int iUID = LoginManager.GetUserID(); if (keySection.CreateUserID != iUID) { throw new AppException(ReturnResultStatus.Illegal, "非法操作"); } keySection.Name = request.Name; return(ReturnResult.ResultCalculation(() => KeySectionManager.Update(keySection))); }
public async Task <ReturnResult> GetKeyKeySectionDetailed(int ID) { if (ID <= 0) { throw new AppException("密匙栏目不能为空"); } int iUID = LoginManager.GetUserID(); KeySection keySection = await KeySectionManager.GetSingleAsync(x => x.CreateUserID == iUID && x.ID == ID); if (keySection == null) { throw new AppException(ReturnResultStatus.Illegal, "非法操作"); } return(new ReturnResult(ReturnResultStatus.Succeed, JsonConvert.SerializeObject(new { keySection.ID, keySection.Name, keySection.Remarks, keySection.Level, keySection.PID, }))); }
public static string CachedFile(string section, string key) { KeySection kSection = LookupKey(section, key); return(kSection == null ? "" : kSection.filename); }