Beispiel #1
0
        public JsonResult OnCreate(string pTieuDe, int?pGroupId, int?pUuTien, string pKichCo, string pImageUrl)
        {
            FileType mFileType;

            string[] mLevelArray;
            var      mLevel = 0;

            if (pGroupId == 0)
            {
                //Tinh gia tri Level moi cho Group nay
                //1- Lay tat ca cac Group me
                //2- Convert gia tri Level de lay gia tri lon nhat
                //3- Tao gia tri moi lon hon gia tri lon nhat
                mLevelArray = (from p in MpStartEntities.FileType
                               where p.ParentID == 0
                               select p.Level).ToArray();
                mLevel    = mLevelArray.Select(p => Convert.ToInt32(p)).ToArray().Max();
                mLevel    = (mLevel + 1);
                mFileType = new FileType()
                {
                    Date = DateTime.Now, Level = mLevel.ToString(), Number = pUuTien, Name = pTieuDe, ParentID = pGroupId
                };
                MpStartEntities.AddToFileType(mFileType);
                MpStartEntities.SaveChanges();
            }
            else
            {
                //lay level cua nhom me
                var mFileTypeParent = FileService.LayTheLoaiFileTheoId((int)pGroupId);
                if (mFileTypeParent != null)
                {
                    mLevelArray = (from p in MpStartEntities.NewsGroups
                                   where (p.Level.Substring(0, mFileTypeParent.Level.Length).Equals(mFileTypeParent.Level)) && (p.Level.Length == (mFileTypeParent.Level.Length + 5))
                                   select p.Level).ToArray();
                    if (mLevelArray.Any())
                    {
                        mLevel = mLevelArray.Select(p => Convert.ToInt32(p)).ToArray().Max();
                        mLevel = (mLevel + 1);
                    }
                    else
                    {
                        mLevel = Convert.ToInt32(mFileTypeParent.Level.ToString().Trim() + "10001");
                    }
                    mFileType = new FileType()
                    {
                        Date = DateTime.Now, Level = mLevel.ToString(), Number = pUuTien, Name = pTieuDe, ParentID = pGroupId
                    };
                    MpStartEntities.AddToFileType(mFileType);
                    MpStartEntities.SaveChanges();
                }
                else
                {
                    return(Json(new { code = 0, message = "Không tìm thấy nhóm file." }));
                }
            }
            return(Json(new { code = 1, message = "Lưu loại file thành công." }));
        }