Beispiel #1
0
 public PostProducer(Dispatcher disp)
 {
     this.ctx        = new PostContext();
     this.url        = "http://bash.im/index/";
     this.disp_store = disp;
     this.doc        = new HtmlDocument();
 }
Beispiel #2
0
 public AppointmentQueries(PostContext postContext, IHttpContextAccessor httpContextAccessor, IMapper mapper, ILogger <AppointmentQueries> logger)
 {
     _postContext         = postContext ?? throw new ArgumentNullException(nameof(postContext));
     _httpContextAccessor = httpContextAccessor ?? throw new ArgumentNullException(nameof(httpContextAccessor));
     _mapper = mapper ?? throw new ArgumentNullException(nameof(mapper));
     _logger = logger ?? throw new ArgumentNullException(nameof(logger));
 }
Beispiel #3
0
        public async Task <ListContentPostDTO> GetByIdAsync(long id)
        {
            using (PostContext ctx = new PostContext())
            {
                BaseService <PostEntity> bs = new BaseService <PostEntity>(ctx);
                var res = await bs.GetAll()
                          .AsNoTracking()
                          .Include(e => e.PostType)
                          .Include(e => e.PostStatus)
                          .SingleOrDefaultAsync(e => e.Id == id);

                BaseService <PostCommentEntity> commentBs = new BaseService <PostCommentEntity>(ctx);
                if (res == null)
                {
                    return(null);
                }

                return(new ListContentPostDTO
                {
                    Content = res.Content,
                    CreateTime = res.CreateTime,
                    IsEssence = res.IsEssence,
                    Id = res.Id,
                    IsKnot = res.IsKnot,
                    PostStatusId = res.PostStatusId,
                    PostStatusName = res.PostStatus.Name,
                    PostTypeId = res.PostTypeId,
                    PostTypeName = res.PostType.Name,
                    Title = res.Title,
                    UserId = res.UserId,
                    CommentCount = await commentBs.GetAll().LongCountAsync(e => e.PostId == id)
                });
            }
        }
Beispiel #4
0
        public ActionResult Edit(int id)
        {
            PostContext postContext = new PostContext();
            Post        post        = postContext.Posts.Single(pst => pst.postId == id);

            return(View(post));
        }
Beispiel #5
0
        public async static Task Seed(
            PostContext context,
            RoleManager <IdentityRole> roleManager,
            UserManager <ApplicationUser> userManager,
            IConfiguration configuration)
        {
            await context.Database.EnsureCreatedAsync();

            if (!await roleManager.RoleExistsAsync(SD.AdminRole))
            {
                await roleManager.CreateAsync(new IdentityRole(SD.AdminRole));
            }
            if (!await roleManager.RoleExistsAsync(SD.UserRole))
            {
                await roleManager.CreateAsync(new IdentityRole(SD.UserRole));
            }
            if (await userManager.FindByEmailAsync("*****@*****.**") == null)
            {
                var admin = new ApplicationUser()
                {
                    Email     = "*****@*****.**",
                    UserName  = "******",
                    Lastname  = "Mammadov",
                    Firstname = "Qasim"
                };
                var result = await userManager.CreateAsync(admin, configuration["AdminSetting:Password"]);

                if (result.Succeeded)
                {
                    await userManager.AddToRoleAsync(admin, SD.AdminRole);
                }
            }
        }
        public ActionResult Send(int id, Przesylka przesylka)
        {
            using (var ctx = new PostContext())
            {
                Nadawca        nad;
                List <Nadawca> nadList = ctx.Nadawcy.Where(p => p.Nazwisko == przesylka.Nadawca.Nazwisko).ToList();
                if (nadList.Count == 0)
                {
                    nad = new Nadawca {
                        Imie = przesylka.Nadawca.Imie, Nazwisko = przesylka.Nadawca.Nazwisko
                    };
                }
                else
                {
                    nad = nadList[0];
                }
                przesylka.Nadawca = nad;
                Paczkomat pacz = ctx.Paczkomaty.First(p => p.Id == id);
                przesylka.Paczkomat = pacz;
                ctx.Przesylki.Add(przesylka);
                ctx.SaveChanges();
            }

            return(RedirectToAction("Index", "Home"));
        }
Beispiel #7
0
        public async Task <List <ListPostDTO> > GetPageDataAsync(int pageIndex = 1, int pageDataCount = 10, bool?isKnot = null, bool?isEssence = null)
        {
            using (PostContext ctx = new PostContext())
            {
                BaseService <PostEntity>        bs        = new BaseService <PostEntity>(ctx);
                List <ListPostDTO>              list      = new List <ListPostDTO>();
                BaseService <PostCommentEntity> commentBs = new BaseService <PostCommentEntity>(ctx);

                var posts = bs.GetAll();

                if (isKnot != null)
                {
                    posts = posts.Where(e => e.IsKnot == isKnot);
                }
                if (isEssence != null)
                {
                    posts = posts.Where(e => e.IsEssence == isEssence);
                }
                await posts.Where(e => e.PostStatus.Name != "审核中")
                .AsNoTracking()
                .Include(e => e.PostStatus)
                .Include(e => e.PostType)
                .OrderBy(e => e.CreateTime)
                .Skip((pageIndex - 1) * pageDataCount)
                .Take(pageDataCount)
                .ForEachAsync(e =>
                {
                    list.Add(TODTO(e, commentBs.GetAll().LongCount(x => x.PostId == e.Id)));
                });

                return(list);
            }
        }
        public static async Task DispatchDomainEventsAsync(this IMediator mediator, PostContext ctx)
        {
            var domainEntities = ctx.ChangeTracker
                                 .Entries <Entity>()
                                 .Where(x => x.Entity.DomainEvents != null && x.Entity.DomainEvents.Any());

            var domainEvents = domainEntities
                               .SelectMany(x => x.Entity.DomainEvents)
                               .ToList();

            domainEntities.ToList()
            .ForEach(entity => entity.Entity.ClearDomainEvents());

            // NOTE: as DbContext instance is not thread safe, do not use the Select code:
            // events are published in parallel. Instead, use the foreach code, each publishing is awaited.

            //var tasks = domainEvents
            //    .Select(async (domainEvent) =>
            //    {
            //        await mediator.Publish(domainEvent);
            //    });
            //await Task.WhenAll(tasks);

            foreach (var domainEvent in domainEvents)
            {
                await mediator.Publish(domainEvent);
            }
        }
Beispiel #9
0
        public ActionResult Index()
        {
            PostContext postContext = new PostContext();
            List <Post> posts       = postContext.Posts.ToList();

            return(View(posts));
        }
Beispiel #10
0
        // The return type can be changed to IEnumerable, however to support
        // paging and sorting, the following parameters must be added:
        //     int maximumRows
        //     int startRowIndex
        //     out int totalRowCount
        //     string sortByExpression
        public IQueryable <Post> postList_GetData()
        {
            var _db = new PostContext();
            IQueryable <Post> query = _db.Posts;

            return(query);
        }
Beispiel #11
0
        public ActionResult ControlPost(PostViewModel PVM)
        {
            if (PVM.post.Id == 0)
            {
                DateTime fecha = new DateTime();
                fecha          = DateTime.Now.Date;
                PVM.post.Fecha = fecha.ToString("MM-dd-yyyy");

                using (var db = new PostContext())
                {
                    db.Posts.Add(PVM.post);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
            else
            {
                using (var db = new PostContext())
                {
                    Post UpdatePost = db.Posts.FirstOrDefault(s => s.Id == PVM.post.Id);
                    UpdatePost.Titulo      = PVM.post.Titulo;
                    UpdatePost.Descripcion = PVM.post.Descripcion;
                    UpdatePost.IdCategoría = PVM.post.IdCategoría;
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
        }
Beispiel #12
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env,
                              PostContext context,
                              UserManager <ApplicationUser> userManager,
                              RoleManager <IdentityRole> roleManager)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }
            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseCookiePolicy();
            app.UseAuthentication();


            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "MyAreas",
                    template: "{area=Admin}/{controller=Admin}/{action=Index}/{id?}");
            });

            DbInitializor.Seed(context, roleManager, userManager, Configuration).Wait();
        }
Beispiel #13
0
 public PostQueries(PostContext postContext,
                    IHttpContextAccessor httpContextAccessor,
                    ILogger <PostQueries> logger)
 {
     _postContext         = postContext ?? throw new ArgumentNullException(nameof(postContext));
     _httpContextAccessor = httpContextAccessor ?? throw new ArgumentNullException(nameof(httpContextAccessor));
     _logger = logger ?? throw new ArgumentNullException(nameof(logger));
 }
Beispiel #14
0
        public ActionResult Delete(int id)
        {
            PostContext postContext = new PostContext();
            Post        post        = postContext.Posts.Single(pst => pst.postId == id);

            post.DeletePost(post);
            return(RedirectToAction("Index"));
        }
Beispiel #15
0
 public async Task <long> GetTotalCountByPostIdAsync(long postId)
 {
     using (PostContext ctx = new PostContext())
     {
         BaseService <PostCommentEntity> bs = new BaseService <PostCommentEntity>(ctx);
         return(await bs.GetAll().LongCountAsync(e => e.PostId == postId));
     }
 }
 public PostController(PostContext context, IConfiguration config)
 {
     _context      = context;
     Configuration = config;
     AWS_KEY       = Configuration["AWS_KEY"];
     AWS_SECRET    = Configuration["AWS_SECRET"];
     uploader      = new AmazonUploader(AWS_KEY, AWS_SECRET);
 }
Beispiel #17
0
 // GET: Blog
 public ActionResult Index()
 {
     using (var db = new PostContext())
     {
         List <Post> ListPost = db.Posts.ToList();
         return(View(ListPost));
     }
 }
Beispiel #18
0
        public void Count_Starts_At_Zero()
        {
            var db        = new PostContext();
            var underTest = new PostRepository(db);
            var count     = underTest.Count();

            Assert.Equal(0, count);
        }
Beispiel #19
0
 public async Task <long> GetAdminWebTotalCountAsync()
 {
     using (PostContext ctx = new PostContext())
     {
         BaseService <PostEntity> bs = new BaseService <PostEntity>(ctx);
         return(await bs.TotalCountAsync());
     }
 }
Beispiel #20
0
 public async Task MarkDeleteAsync(long id)
 {
     using (PostContext ctx = new PostContext())
     {
         BaseService <PostEntity> bs = new BaseService <PostEntity>(ctx);
         await bs.MarkDeleteAsync(id);
     }
 }
Beispiel #21
0
 public async Task <long> TotalCountAsync()
 {
     using (PostContext ctx = new PostContext())
     {
         BaseService <PostEntity> bs = new BaseService <PostEntity>(ctx);
         return(await bs.GetAll().LongCountAsync(e => e.PostStatus.Name != "审核中"));
     }
 }
Beispiel #22
0
 /// <summary>
 /// 获取该用户收藏的帖子总数
 /// </summary>
 /// <param name="userId"></param>
 /// <returns></returns>
 public async Task <long> GetCollectionPostByUserIdTotalCountAsync(long userId)
 {
     using (PostContext ctx = new PostContext())
     {
         BaseService <PostEntity> postBs = new BaseService <PostEntity>(ctx);
         return(await postBs.GetAll().LongCountAsync(e => e.UserId == userId));
     }
 }
Beispiel #23
0
        public ActionResult ShowPost(Post pos)

        {
            using (var db = new PostContext())
            {
                db.Post.FirstOrDefault(s => s.IdP == pos.IdP);
            }
            return(View(pos));
        }
Beispiel #24
0
 public ActionResult Delete(Post post)
 {
     using (var db = new PostContext())
     {
         db.Entry(post).State = System.Data.Entity.EntityState.Deleted;
         db.SaveChanges();
     }
     return(RedirectToAction("Index"));
 }
 // GET: Wall
 public ActionResult Index()
 {
     using (var context = new PostContext())
     {
         var posts = context.Posts.ToList();
         ViewData["Posts"] = posts;
     }
     return View();
 }
Beispiel #26
0
        public ActionResult Edit(int id, FormCollection formCollection)
        {
            PostContext postContext = new PostContext();
            Post        post        = postContext.Posts.Single(pst => pst.postId == id);

            post.postContent = formCollection["postContent"];
            post.EditPost(post);
            return(RedirectToAction("Index"));
        }
Beispiel #27
0
 public ActionResult DeletePost(int Id)
 {
     using (var db = new PostContext())
     {
         PostViewModel PVM = new PostViewModel();
         PVM.post = db.Posts.First(s => s.Id == Id);
         return(View(PVM));
     }
 }
Beispiel #28
0
        // GET: Post
        public ActionResult Index()
        {
            List <Post> post;

            using (var db = new PostContext())
            {
                post = db.Database.SqlQuery <Post>("SELECT * FROM Posts").ToList();
            }
            return(View(post));
        }
        // GET: Home
        public ActionResult Index()
        {
            List <Nadawca> list;

            using (var ctx = new PostContext())
            {
                list = ctx.Nadawcy.Include(n => n.Adres).ToList();
            }
            return(View(list));
        }
Beispiel #30
0
 public ActionResult DeletePost(PostViewModel PVM)
 {
     using (var db = new PostContext())
     {
         Post deletePost = db.Posts.FirstOrDefault(s => s.Id == PVM.post.Id);
         db.Posts.Remove(deletePost);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
 }