public JsonResult OnCreate(string pTieuDe, int?pGroupId, int?pUuTien, string pKichCo, string pImageUrl) { ImageType mImageType; 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.ImageType where p.Parent == 0 select p.Level).ToArray(); mLevel = mLevelArray.Select(p => Convert.ToInt32(p)).ToArray().Max(); mLevel = (mLevel + 1); mImageType = new ImageType() { Date = DateTime.Now, Level = mLevel.ToString(), Number = pUuTien, Name = pTieuDe, Parent = pGroupId, Size = pKichCo, Image = pImageUrl }; MpStartEntities.AddToImageType(mImageType); MpStartEntities.SaveChanges(); } else { //lay level cua nhom me var mImageTypeParent = ImagesService.LayTheLoaiAnhTheoId((int)pGroupId); if (mImageTypeParent != null) { mLevelArray = (from p in MpStartEntities.NewsGroups where (p.Level.Substring(0, mImageTypeParent.Level.Length).Equals(mImageTypeParent.Level)) && (p.Level.Length == (mImageTypeParent.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(mImageTypeParent.Level.ToString().Trim() + "10001"); } mImageType = new ImageType() { Date = DateTime.Now, Level = mLevel.ToString(), Number = pUuTien, Name = pTieuDe, Parent = pGroupId, Size = pKichCo, Image = pImageUrl }; MpStartEntities.AddToImageType(mImageType); MpStartEntities.SaveChanges(); } else { return(Json(new { code = 0, message = "Không tìm thấy nhóm ảnh." })); } } return(Json(new { code = 1, message = "Lưu loại ảnh thành công." })); }