Esempio n. 1
0
        public async Task <DBAction> Create(AppEditModel dataModel, string userId)
        {
            using (var db = new TDContext())
            {
                dataModel.Id = new DBHelper().GetAppId(db);


                var app = new App(dataModel);
                app.ModiyId    = userId;
                app.LastModify = DateTime.UtcNow;
                var gallery = new GalleryDB(db).Create(app);
                if (!string.IsNullOrEmpty(dataModel.ImageData))
                {
                    var save = await db.SaveImage(dataModel.ImageData, "apps", null);

                    if (!save.OK)
                    {
                        return(new DBAction(save.Message, false));
                    }
                    gallery.AppFiles.Add(save.Image);
                }
                db.Apps.Add(app);
                var str = await db.SaveMessageAsync();

                if (!string.IsNullOrEmpty(str))
                {
                    return(new DBAction(str, false));
                }
                return(new DBAction(app.Id));
            }
        }
Esempio n. 2
0
        public async Task <string> Delete(string id)
        {
            var blog = await db.Blogs.FindAsync(id);

            if (blog == null)
            {
                return(LanguageDB.NotFound);
            }
            var comments = await db.Comments.Where(x => x.BlogId == id).Select(x => x.Id).ToListAsync();

            var commentDB = new CommentDB(db);

            foreach (var item in comments)
            {
                await commentDB.Delete(item);
            }
            var galleryDB = new GalleryDB(db);
            var gallery   = await db.Galleries.Where(x => x.BlogId == id).Select(x => x.Id).ToListAsync();

            foreach (var item in gallery)
            {
                await galleryDB.Delete(item);
            }
            db.Blogs.Remove(blog);
            var str = await db.SaveMessageAsync();

            return(str);
        }
Esempio n. 3
0
        public async Task <DBAction> Edit(AppEditModel dataModel, string userId)
        {
            using (var db = new TDContext())
            {
                var app = await db.Apps.FindAsync(dataModel.Id);

                if (app == null)
                {
                    return(new DBAction(LanguageDB.NotFound, false));
                }
                app.Name       = dataModel.Name;
                app.Link       = dataModel.Link;
                app.Content    = dataModel.Content;
                app.Database   = dataModel.Database;
                app.ModiyId    = userId;
                app.LastModify = DateTime.UtcNow;
                if (!string.IsNullOrEmpty(dataModel.ImageData))
                {
                    var gallery = app.Galleries.FirstOrDefault();
                    if (gallery == null)
                    {
                        gallery = new GalleryDB(db).Create(app);
                    }
                    var          image = gallery.AppFiles.FirstOrDefault();
                    AppFileValue save;
                    if (image != null)
                    {
                        save = await db.SaveImage(dataModel.ImageData, "apps", image.Id);
                    }
                    else
                    {
                        save = await db.SaveImage(dataModel.ImageData, "apps", null);
                    }
                    if (!save.OK)
                    {
                        return(new DBAction(save.Message, false));
                    }
                    image = save.Image;
                }


                db.Entry(app).State = EntityState.Modified;
                var str = await db.SaveMessageAsync();

                if (!string.IsNullOrEmpty(str))
                {
                    return(new DBAction(str, false));
                }
                return(new DBAction(app.Id));
            }
        }
Esempio n. 4
0
        public async Task <string> Delete(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return((TD.Global.NoData));
            }
            using (var db = new TDContext())
            {
                App app = await db.Apps.FindAsync(id);

                if (app == null)
                {
                    return(LanguageDB.NotFound);
                }


                db.Apps.Remove(app);
                var galleries = db.Galleries.Where(x => x.AppId == app.Id).Select(x => x.Id).ToList();
                if (galleries != null && galleries.Count > 0)
                {
                    var galleryDB = new GalleryDB(db);
                    for (int i = 0, j = galleries.Count; i < j; i++)
                    {
                        await galleryDB.Delete(galleries[i]);
                    }
                }
                var str = await db.SaveMessageAsync();

                if (!string.IsNullOrEmpty(str))
                {
                    return(str);
                }


                return("");
                //return (Js.SuccessRedirect(AppRemove, TD.Properties.Resources.AdminAppsLink));
            }
        }