protected void SaveNewsCategory(bool isActive) { string error = string.Empty; string strLargeImagePath = string.Empty; string strMediumImagePath = string.Empty; string strSmallImagePath = string.Empty; string strImageExtension = string.Empty; if (fluNewsCategory.HasFile) { string path = HttpContext.Current.Server.MapPath("~/"); string largeImagePath = "Modules\\NewsModule\\NewsCategoryImage"; string savedPathLarge = Path.Combine(path, largeImagePath); string mediumImagePath = "Modules\\NewsModule\\NewsCategoryImage\\MediumBannerImage"; string savedPathMedium = Path.Combine(path, mediumImagePath); string smallImagePath = "Modules\\NewsModule\\NewsCategoryImage\\SmallBannerImage"; string savedPathSmall = Path.Combine(path, smallImagePath); char[] separator = new char[] { '.' }; string[] fileNames = fluNewsCategory.FileName.Split(separator); string fileName = fileNames[0]; string extension = string.Empty; if (fileNames.Length > 1) { extension = fileNames[fileNames.Length - 1]; } if (PictureManager.IsValidIconContentType(extension) && fluNewsCategory.PostedFile.ContentLength <= GetCatImageSizeSetting()) { fileName = PictureManager.GetFileName(fileName); strLargeImagePath = PictureManager.SaveImage(fluNewsCategory, fileName + "." + extension, savedPathLarge); strMediumImagePath = PictureManager.CreateMediumThumnail(strLargeImagePath, GetPortalID, fileName + "." + extension, savedPathMedium, 200); strSmallImagePath = PictureManager.CreateSmallThumnail(strLargeImagePath, GetPortalID, fileName + "." + extension, savedPathSmall, 150); if (hdfNewsCategoryID.Value == "") { db.sp_NewsCheckUniqueNewsCategoryName(0, txtCategoryName.Text.Trim(), false, ref _newCategoryCount); if (_newCategoryCount == 0) { // Add try { db.sp_NewsCategoryImageAdd(extension, "Modules\\NewsModule\\NewsCategoryImage\\" + fileName, "Modules\\NewsModule\\NewsCategoryImage\\MediumBannerImage\\" + fileName, "Modules\\NewsModule\\NewsCategoryImage\\SmallBannerImage\\" + fileName, isActive, GetPortalID, GetUsername, ref _ImageID); db.sp_NewsCategoryAdd(ref _newNewsCategoryID, txtCategoryName.Text.Trim(), txtCategoryDescription.Text.Trim(), _ImageID, isActive, DateTime.Now, GetPortalID, GetUsername); ShowMessage(SageMessageTitle.Information.ToString(), GetSageMessage("NewsModule", "NewsCategoryIsAddedSuccessfully"), "", SageMessageType.Success); ImgNewsCategory.Visible = true; ImgNewsCategory.ImageUrl = strSmallImagePath; } catch (Exception ex) { ProcessException(ex); error += ex.Message; } } else { ShowMessage(SageMessageTitle.Notification.ToString(), txtCategoryName.Text.Trim() + " " + GetSageMessage("NewsModule", "NameAlreadyExist"), "", SageMessageType.Error); error += "Name already Exist"; } } else if (hdfNewsCategoryID.Value != "") { db.sp_NewsCheckUniqueNewsCategoryName(Int32.Parse(hdfNewsCategoryID.Value), txtCategoryName.Text.Trim(), true, ref _newCategoryCount); if (_newCategoryCount == 0) { // Update try { var folderPaths = db.sp_NewsCategoryImageFoldersGet(Int32.Parse(hdfNewsCategoryID.Value), GetPortalID); foreach (sp_NewsCategoryImageFoldersGetResult imageFolders in folderPaths) { string largeImage = path + imageFolders.LargeImagePath + "." + imageFolders.ImageExtension; DeleteImageFiles(largeImage); string mediumImage = path + imageFolders.MediumImagePath + "." + imageFolders.ImageExtension; DeleteImageFiles(mediumImage); string smallImage = path + imageFolders.SmallImagePath + "." + imageFolders.ImageExtension; DeleteImageFiles(smallImage); } db.sp_NewsCategoryImageUpdate(Int32.Parse(hdfNewsCategoryID.Value), extension, "Modules\\NewsModule\\NewsCategoryImage\\" + fileName, "Modules\\NewsModule\\NewsCategoryImage\\MediumBannerImage\\" + fileName, "Modules\\NewsModule\\NewsCategoryImage\\SmallBannerImage\\" + fileName, isActive, GetPortalID, GetUsername, ref _ImageID); db.sp_NewsCategoryUpdate(Int32.Parse(hdfNewsCategoryID.Value), txtCategoryName.Text.Trim(), txtCategoryDescription.Text.Trim(), _ImageID, isActive, true, DateTime.Now, GetPortalID, GetUsername); ShowMessage(SageMessageTitle.Information.ToString(), GetSageMessage("NewsModule", "NewsCategoryIsUpdatedSuccessfully"), "", SageMessageType.Success); ImgNewsCategory.Visible = true; ImgNewsCategory.ImageUrl = strSmallImagePath; } catch (Exception ex) { ProcessException(ex); error += ex.Message; } } else { ShowMessage(SageMessageTitle.Notification.ToString(), txtCategoryName.Text.Trim() + " " + GetSageMessage("NewsModule", "NameAlreadyExists"), "", SageMessageType.Error); error += "Name already Exist"; } } } else { lblError.Text = ""; ShowMessage(SageMessageTitle.Notification.ToString(), GetSageMessage("NewsModule", "InvalidImageFileOrFileLength"), "", SageMessageType.Error); } } else//If No Image is uploaded { if (hdfNewsCategoryID.Value != "") { db.sp_NewsCheckUniqueNewsCategoryName(Int32.Parse(hdfNewsCategoryID.Value), txtCategoryName.Text.Trim(), true, ref _newCategoryCount); if (_newCategoryCount == 0) { try { db.sp_NewsCategoryUpdate(Int32.Parse(hdfNewsCategoryID.Value), txtCategoryName.Text.Trim(), txtCategoryDescription.Text.Trim(), null, isActive, true, DateTime.Now, GetPortalID, GetUsername); ShowMessage(SageMessageTitle.Information.ToString(), GetSageMessage("NewsModule", "NewsCategoryIsUpdatedSuccessfully"), "", SageMessageType.Success); } catch (Exception ex) { ProcessException(ex); error += ex.Message; } } else { ShowMessage(SageMessageTitle.Notification.ToString(), txtCategoryName.Text.Trim() + " " + GetSageMessage("NewsModule", "NameExistAlready"), "", SageMessageType.Error); error += "Name already Exist"; } } else if (hdfNewsCategoryID.Value == "") { db.sp_NewsCheckUniqueNewsCategoryName(0, txtCategoryName.Text.Trim(), false, ref _newCategoryCount); if (_newCategoryCount == 0) { // Add try { db.sp_NewsCategoryAdd(ref _newNewsCategoryID, txtCategoryName.Text.Trim(), txtCategoryDescription.Text.Trim(), _ImageID, isActive, DateTime.Now, GetPortalID, GetUsername); ShowMessage(SageMessageTitle.Information.ToString(), GetSageMessage("NewsModule", "NewsCategoryIsAgainAddedSuccessfully"), "", SageMessageType.Success); } catch (Exception ex) { ProcessException(ex); error += ex.Message; } } else { ShowMessage(SageMessageTitle.Notification.ToString(), GetSageMessage("NewsModule", "NameAlreadyExistAgain"), "", SageMessageType.Error); error += "Name already Exist"; } } } if (error == string.Empty) { ClearCategoryForm(); PanelVisibility2(true, false, false); BindNewsCategories(); } }