Example #1
0
 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));
     }));
 }
Example #2
0
 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());
       }
 }
Example #3
0
        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());
            }
        }
Example #4
0
        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]);
        }
Example #5
0
        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)));
        }
Example #6
0
        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();
            }
        }
Example #7
0
        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)));
        }
Example #8
0
        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,
            })));
        }
Example #9
0
        public static string CachedFile(string section, string key)
        {
            KeySection kSection = LookupKey(section, key);

            return(kSection == null ? "" : kSection.filename);
        }