public static void Delete(ApplicationDbContext context, short id) { var entity = new JGN_Categories { id = id }; context.JGN_Categories.Attach(entity); context.JGN_Categories.Remove(entity); context.SaveChanges(); }
/// <summary> /// Prepare and return category page link /// </summary> /// <param name="entity"></param> /// <param name="path"></param> /// <returns></returns> public static string PrepareUrl(JGN_Categories entity, string path) { string _value = entity.term; if (_value == "") { _value = entity.title; } string query = UtilityBLL.ReplaceSpaceWithHyphin_v2(_value.Trim().ToLower()); return(Config.GetUrl(path + "category/" + query)); }
/// <summary> /// Prepare and return category image / thumbnail link /// </summary> /// <param name="entity"></param> /// <returns></returns> public static string PrepareImageUrl(JGN_Categories entity) { if (entity.picturename == null || entity.picturename == "" || entity.picturename == "none") { return(getDefaultImageUrl()); } else if (entity.picturename.StartsWith("http")) { return(entity.picturename); } else { return(Config.GetUrl("contents/category/" + entity.picturename)); } }
public static async Task <short> Process(ApplicationDbContext context, JGN_Categories entity) { if (entity.picturename != null && entity.picturename != "") { if (entity.picturename.StartsWith("data:image")) { // base 64 image byte[] image = Convert.FromBase64String(entity.picturename.Replace("data:image/png;base64,", "")); // create image name string thumbFileName = UtilityBLL.ReplaceSpaceWithHyphin(entity.title) + Guid.NewGuid().ToString().Substring(0, 8) + ".png"; var path = SiteConfig.Environment.ContentRootPath + SystemDirectoryPaths.CategoryPhotosDirectoryPath; if (File.Exists(path + "" + thumbFileName)) { File.Delete(path + "" + thumbFileName); } // local storage File.WriteAllBytes(path + "" + thumbFileName, image); entity.picturename = await Helper.Aws.UploadPhoto(context, thumbFileName, path, Configs.AwsSettings.category_photos_directory); } } if (entity.id == 0) { var _entity = new JGN_Categories() { title = entity.title, parentid = entity.parentid, description = UtilityBLL.processNull(entity.description, 0), type = Convert.ToByte(entity.type), priority = entity.priority, isenabled = Convert.ToByte(entity.isenabled), mode = Convert.ToByte(entity.mode), term = UtilityBLL.processNull(entity.term, 0), level = "", picturename = UtilityBLL.processNull(entity.picturename, 0), icon = UtilityBLL.processNull(entity.icon, 0) }; context.Entry(_entity).State = EntityState.Added; await context.SaveChangesAsync(); entity.id = _entity.id; } else { var item = await context.JGN_Categories .Where(p => p.id == entity.id) .FirstOrDefaultAsync(); if (item != null) { item.description = entity.description; item.title = entity.title; item.term = entity.term; item.parentid = Convert.ToInt16(entity.parentid); item.priority = entity.priority; item.isenabled = Convert.ToByte(entity.isenabled); item.mode = Convert.ToByte(entity.mode); item.picturename = entity.picturename; item.icon = entity.icon; await context.SaveChangesAsync(); } } levelArr.Clear(); string level = prepareLevel(context, (short)entity.id); Update_Field(context, entity.id, level, "level"); return(entity.id); }