public bool DeleteNewsType(int TypeId) { DataView types = GetChildrenNewsTypes(TypeId); foreach (DataRowView drv in types) { DeleteNewsType((Int32)drv["TypeId"]); } try { var type = GetType(TypeId); if (!StringUtils.IsNullOrWhiteSpace(type.Image)) { string path = WebContext.Server.MapPath(Path.Combine(WebContext.StartDir, Folders.NewsTypesFolder)); if (Directory.Exists(path)) { var Image = type.Image; if (File.Exists(Path.Combine(path, Image))) { File.Delete(Path.Combine(path, Image)); } } } NewsTypesData.NewsTypes.DeleteOnSubmit(type); NewsTypesData.SubmitChanges(); } catch (Exception ex) { ErrorContext.Add("delete-newstype", "Unable to delete news type.<br />" + ex.Message); return(false); } return(true); }
public int AddNewsType(string Name, Status Status, HttpPostedFile Image, string Description, int?ParentId, short?ThumbWidth, short?ThumbHeight, short?MediumWidth, short?MediumHeight, short?LargeWidth, short?LargeHeight, int?TemplateId, int?Permission) { if (GetType(Name) != null) { return(-1); } NewsType type = new NewsType { Name = Name, UniqueName = StringUtils.ToURL(Name), Status = (byte)Status, Description = Description, ParentId = ParentId, ThumbWidth = ThumbWidth, ThumbHeight = ThumbHeight, MediumWidth = MediumWidth, MediumHeight = MediumHeight, LargeWidth = LargeWidth, LargeHeight = LargeHeight, DateCreated = DateTime.Now, LastModified = DateTime.Now, TemplateId = TemplateId, Ranking = 0, UserRating = 0, Views = 0, Permission = Permission }; NewsTypesData.NewsTypes.InsertOnSubmit(type); NewsTypesData.SubmitChanges(); if (Image != null && Image.ContentLength > 0) { string ImageName = Path.GetFileNameWithoutExtension(Image.FileName); ImageName = string.Format("{0}_{1}{2}", ImageName, type.TypeId, Path.GetExtension(Image.FileName)); string path = WebContext.Server.MapPath(Path.Combine(WebContext.StartDir, Folders.NewsTypesFolder)); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } path = Path.Combine(path, ImageName); Image.SaveAs(path); if (ThumbWidth > 0 && ThumbHeight > 0) { ImageUtils.CropImage(path, path, (int)ThumbWidth, (int)ThumbHeight, ImageUtils.AnchorPosition.Default); } type.Image = ImageName; NewsTypesData.SubmitChanges(); } return(type.TypeId); }
public int UpdateNewsType(int TypeId, string Name, Status Status, HttpPostedFile Image, string Description, int?ParentId, short?ThumbWidth, short?ThumbHeight, short?MediumWidth, short?MediumHeight, short?LargeWidth, short?LargeHeight, int?TemplateId, int?Permission, bool DeleteOldImage, int?Ranking, int?UserRating, int?Views) { var type = GetType(TypeId); type.Name = Name; type.UniqueName = StringUtils.ToURL(Name); type.Status = (byte)Status; type.Description = Description; type.ParentId = ParentId; type.ThumbWidth = ThumbWidth; type.ThumbHeight = ThumbHeight; type.MediumWidth = MediumWidth; type.MediumHeight = MediumHeight; type.LargeWidth = LargeWidth; type.LargeHeight = LargeHeight; type.LastModified = DateTime.Now; type.TemplateId = TemplateId; if (Ranking != null) { type.Ranking = Ranking.Value; } if (UserRating != null) { type.UserRating = UserRating.Value; } if (Views != null) { type.Views = Views.Value; } type.Permission = Permission; NewsTypesData.SubmitChanges(); string path = WebContext.Server.MapPath(Path.Combine(WebContext.StartDir, Folders.NewsTypesFolder)); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } var oldImage = type.Image; DeleteOldImage = DeleteOldImage || (Image != null && Image.ContentLength > 0); if (DeleteOldImage && !StringUtils.IsNullOrWhiteSpace(type.Image)) { if (File.Exists(Path.Combine(path, oldImage))) { File.Delete(Path.Combine(path, oldImage)); } type.Image = ""; } if (Image != null && Image.ContentLength > 0) { string ImageName = Path.GetFileNameWithoutExtension(Image.FileName); ImageName = string.Format("{0}_{1}{2}", ImageName, type.TypeId, Path.GetExtension(Image.FileName)); string _path = Path.Combine(path, ImageName); Image.SaveAs(_path); Config cfg = new Config(); Dimension dim = new Dimension(cfg.GetKey(lw.CTE.Settings.NewsCategory_ImageSize)); if (dim.Valid) { ImageUtils.CropImage(_path, _path, dim.IntWidth, dim.IntHeight, ImageUtils.AnchorPosition.Default); } type.Image = ImageName; } NewsTypesData.SubmitChanges(); return(TypeId); }