public async Task <ActionResult> CreateImage(string AppId, string BlogId) { if (AppId == null && BlogId == null) { return(PartialView()); } Gallery gallery = null; if (AppId != null) { var product = await db.Apps.FindAsync(AppId); if (product == null) { return(View()); } if (product.Galleries.Count == 0) { gallery = new GalleryDB(db).Create(product); await db.SaveAsync(); } else { gallery = product.Galleries.FirstOrDefault(); } } else { var blog = await db.Blogs.FindAsync(BlogId); if (blog == null) { return(PartialView()); } if (blog.Galleries.Count == 0) { gallery = new GalleryDB(db).CreateBlog(blog); await db.SaveAsync(); } else { gallery = blog.Galleries.FirstOrDefault(); } } if (gallery == null) { return(PartialView()); } ViewBag.GalleryId = gallery.Id; return(PartialView()); }
public async Task<ActionResult> Create(string Name, string Link, string ButtonText, string Subtitle, string VideoLink, string ImageData) { if (string.IsNullOrEmpty(ImageData)) return Json("Không có dữ liệu ảnh".GetError()); var saveFile = await db.SaveImage(ImageData, "galleries", null);// ImageData.WriteImageString(Server.MapPath("~/data/img/slides")); if (!saveFile.OK) return Json(saveFile.Message); var gal = new GalleryDB(db).Create(); gal.InHome = true; gal.Name = Name; gal.Link = Link; gal.ButtonText = ButtonText; gal.Subtitle = Subtitle; gal.VideoLink = VideoLink; gal.AppFiles.Add(saveFile.Image); var str = await db.SaveMessageAsync(); if (str != null) return Json(str.GetError()); return Json(Js.SuccessRedirect("Đã thêm Gallery" + saveFile.Image.FileName, "/admin/home/config")); }
public async Task <ActionResult> Index(string AppId, string BlogId) { if (BlogId != null) { var blog = await db.Blogs.FindAsync(BlogId); if (blog == null) { return(PartialView()); } if (blog.Galleries.Count == 0) { var gal = new GalleryDB(db).CreateBlog(blog); await db.SaveAsync(); } ViewBag.CreateLink = "BlogId=" + BlogId; return(PartialView("_Index", db.AppFiles.Where(x => x.Gallery.BlogId == BlogId))); } else if (AppId != null) { ViewBag.CreateLink = "AppId=" + AppId; var product = await db.Apps.FindAsync(AppId); if (product == null) { return(PartialView()); } if (product.Galleries.Count == 0) { var gal = new GalleryDB(db).Create(product); await db.SaveAsync(); } return(PartialView("_Index", db.AppFiles.Where(x => x.Gallery.AppId == AppId))); } return(View(db.AppFiles)); }
/// <summary> /// Initializes a new instance of the <see cref="GallerySql"/> class. /// </summary> public GallerySql() { galleryDb = new GalleryDB(); galleryDb.DbClient = new SqlServerClient(); }
/// <summary> /// Initializes a new instance of the <see cref="GallerySqlCe"/> class. /// </summary> public GallerySqlCe() { galleryDb = new GalleryDB(); galleryDb.DbClient = new SqlCeClient(); }
/// <summary> /// Initializes a new instance of the <see cref="GallerySql"/> class. /// </summary> public GallerySql() { galleryDb = new GalleryDB(); galleryDb.DbClient = new SqlServerClient(); }
public async Task <ActionResult> Create(BlogEditModel model) { if (!ModelState.IsValid) { return(Json(this.GetModelStateError().GetError())); } var db = new TDContext(); var UserId = User.Identity.GetUserId(); if (db.Blogs.Any(x => x.FullName == model.FullName)) { return(Json(Js.Error(Global.BlogNameUsed))); } var lstSelect = await new TagBlogDB(db).FindOrCreate(model.TagBlogId); model.Content = await model.Content.GetValidHtml(); model.Summary = await model.Content.GetSummary(); model.LongSummary = await model.Content.GetSummary(500); model.Name = model.FullName.GetSafeName(); model.Id = new DBHelper().GetBlogId(db); model.UserId = UserId; var blog = new Blog(model); if (model.ParentId != null) { var parent = await db.Blogs.FindAsync(model.ParentId); if (parent != null) { blog.ParentId = parent.Id; foreach (var item in parent.BlogTags.Select(x => x.TagBlogId)) { if (!lstSelect.Contains(item)) { lstSelect.Add(item); } } } } foreach (var item in lstSelect) { blog.BlogTags.Add(new BlogTag(item, blog.Id)); } var gal = new GalleryDB(db).CreateBlog(blog); if (!string.IsNullOrEmpty(model.ImageData)) { var saveFile = await this.db.SaveImage(model.ImageData, "blogs"); if (!saveFile.OK) { return(Json(Js.Error(saveFile.Message))); } saveFile.Image.IsMain = true; gal.AppFiles.Add(saveFile.Image); } db.Blogs.Add(blog); var str = await db.SaveMessageAsync(); if (str.NotNull()) { return(Json(str.GetError())); } if (string.IsNullOrEmpty(model.ParentId)) { var parent = await db.Blogs.FindAsync(model.ParentId); if (parent != null) { blog.ParentId = parent.Id; var lstAdd = new List <string>(); foreach (var item in parent.BlogTags.Select(x => x.TagBlogId)) { if (!lstAdd.Contains(item) && !await db.BlogTags.AnyAsync(x => x.TagBlogId == item && x.BlogId == model.Id)) { db.BlogTags.Add(new BlogTag { BlogId = model.Id, TagBlogId = item, }); lstAdd.Add(item); } } } } return(Json(Js.SuccessRedirect(Global.BlogInserted, "/admin/blogs"))); }
/// <summary> /// Initializes a new instance of the <see cref="GallerySqlCe"/> class. /// </summary> public GallerySqlCe() { galleryDb = new GalleryDB(); galleryDb.DbClient = new SqlCeClient(); }