Пример #1
0
        public async Task <IActionResult> Post(PostViewModel post)
        {
            if (post.file == null || post.file.Length == 0)
            {
                return(Content("file not found"));
            }

            var    imgname   = DateTime.Now.ToString("MMddHHmmss") + post.file.FileName;
            string path_Root = _appEnvironment.WebRootPath;

            string path_to_Images = path_Root + "\\Postimages\\" + imgname;

            using (var stream = new FileStream(path_to_Images, FileMode.Create))
            {
                await post.file.CopyToAsync(stream);
            }
            await db.Posts.AddAsync(new Post { subject = post.subject, text = post.text, date = DateTime.Now, pathimg = imgname, hashtag = post.hashtag, pathvideo = post.pathvideo });

            await db.SaveChangesAsync();

            var posts = await db.Posts.OrderByDescending(x => x.Id).ToListAsync();

            //  cache.Set("posts", posts, new MemoryCacheEntryOptions().SetAbsoluteExpiration(TimeSpan.FromHours(24)));
            return(RedirectToAction(nameof(List)));
        }
Пример #2
0
        public async Task <IActionResult> Watched([FromBody] WatchViewModel watch)
        {
            var news = await db.Posts.FirstOrDefaultAsync(x => x.Id == watch.Id);

            news.watch++;
            await db.SaveChangesAsync();

            return(Json(Ok()));
        }
Пример #3
0
        public async Task <IActionResult> AddSatu(SatilimViewModel request)
        {
            if (ModelState.IsValid)
            {
                await db.Satilims.AddAsync(new Satilim { Name = request.Name, Price = request.Price, Type = request.Type });

                await db.SaveChangesAsync();

                return(RedirectToAction("Satilim"));
            }
            return(View());
        }
Пример #4
0
        public async Task <IActionResult> Qiwiorder(string pan)
        {
            string id = userManager.GetUserName(User);

            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            if (id == null)
            {
                return(Json(BadRequest()));
            }
            string date     = DateTime.Now.ToString("MMddHHmmss");
            string nnum     = id;
            var    aaa      = nnum.Substring(nnum.Length - 4);
            string acount   = aaa + date;
            string prv      = date + aaa;
            var    oldorder = await db.Qiwipays.Where(x => x.number == id& x.type == pan& x.pay == false).FirstOrDefaultAsync();

            if (oldorder == null)
            {
                await db.Qiwipays.AddAsync(new Qiwipay { account = acount, txn_date = DateTime.Now, sum = 1000, type = pan, number = id, prv_txn = prv, pan = true });
            }
            else
            {
                return(RedirectToAction(nameof(Qiwiorder), new { pan = pan, id = id }));
            }

            await db.SaveChangesAsync();


            return(RedirectToAction(nameof(Qiwiorder), new { pan = pan, id = id }));
        }
Пример #5
0
        public async Task <IActionResult> Tolem(string user_id, string type, int pg_result, string pg_amount, DateTime pg_payment_date, string pg_user_phone, string ptype)
        {
            AppUsern user = await userManager.FindByIdAsync(user_id);


            if (pg_result == 1)
            {
                if (user == null)
                {
                    return(new ObjectResult(new { result = "user not found" }));
                }
                if (ptype == "pan")
                {
                    await db.AddAsync(new Ofpay { IdentityId = user_id, type = type, Price = pg_amount.Split(".")[0] });

                    await db.Tolems.AddAsync(new Tolem { IdentityId = user_id, type = type, success = true, price = pg_amount, date = pg_payment_date });

                    await db.SaveChangesAsync();

                    return(new OkObjectResult(new { result = type, bl = "pann" }));
                }

                if (type == "search")
                {
                    await db.Tolems.AddAsync(new Tolem { IdentityId = user_id, type = type, success = true, price = pg_amount, date = pg_payment_date });

                    var searcher = db.Searches.FirstOrDefault(x => x.IdentityId == user_id);
                    searcher.date   = pg_payment_date;
                    searcher.pay    = true;
                    searcher.enable = false;
                    searcher.count  = 0;
                    await db.SaveChangesAsync();

                    return(new OkObjectResult(new { result = type, bl = "sr" }));
                }
                else
                {
                    await db.Tolems.AddAsync(new Tolem { IdentityId = user_id, type = type, success = true, price = pg_amount, date = pg_payment_date });

                    await db.AddAsync(new Blok { IdentityId = user_id, blok = type, enable = true, BuyDate = pg_payment_date });

                    await db.SaveChangesAsync();

                    return(new OkObjectResult(new { result = type, bl = "blok" }));
                }
            }
            return(BadRequest());
        }
Пример #6
0
        public async Task <IActionResult> List([FromBody] SearchViewModel body)
        {
            if (!ModelState.IsValid)
            {
                return(new ObjectResult(new { result = "not found" }));
            }


            var bbb = await db.Bloks.Where(x => x.IdentityId == body.Id).ToListAsync();

            var sellbloks = await db.SellBloks.ToListAsync();

            var BuyedBloks = await db.Bloks.FirstOrDefaultAsync(x => x.IdentityId == body.Id && x.blok == "all");

            if (BuyedBloks != null)
            {
                DateTime dated = new DateTime();
                DateTime today = new DateTime();
                dated = BuyedBloks.BuyDate;
                today = DateTime.Today;
                raz   = today - dated;

                var month = new TimeSpan(744, 0, 0);
                if (raz > month)
                {
                    BuyedBloks.enable = false;
                    await db.SaveChangesAsync();
                }
            }



            for (int i = 0; i < bbb.Count; i++)
            {
                for (int j = 0; j < sellbloks.Count; j++)
                {
                    if (sellbloks[j].Name == bbb[i].blok && bbb[i].enable == true)
                    {
                        sellbloks[j].Enable = true;
                    }
                }
            }

            if (bbb != null)
            {
                return(new ObjectResult(new { result = sellbloks }));
            }
            return(new ObjectResult(new { result = "not found" }));
        }
Пример #7
0
        public async Task <IActionResult> By([FromBody] SearchViewModel body)
        {
            bool exits, enable, pay;

            exits = true; enable = false; pay = false;
            int count    = 10;
            var searcher = await db.Searches.FirstOrDefaultAsync(x => x.IdentityId == body.Id);

            if (searcher != null)
            {
                exits  = true;
                enable = searcher.enable;
                pay    = searcher.pay;
                count  = searcher.count;
                DateTime dated = new DateTime();
                DateTime today = new DateTime();
                dated = searcher.date;
                today = DateTime.Today;
                raz   = today - dated;
            }
            else
            {
                exits = false;
            }
            if (exits)
            {
                if (!enable)
                {
                    if (pay)
                    {
                        var month = new TimeSpan(744, 0, 0);
                        if (raz > month)
                        {
                            searcher.pay = false;
                            await db.SaveChangesAsync();

                            return(new OkObjectResult(new { searcher.pay }));
                        }
                        return(new OkObjectResult(new { searcher.pay, searcher.date }));
                    }
                    else
                    {
                        return(new ObjectResult(new { searcher.pay }));
                    }
                }
                else
                if (count != 0 && count <= 200)
                {
                    //icount = count - 1;

                    searcher.count -= 1;
                    await db.SaveChangesAsync();

                    return(new OkObjectResult(new { searcher.enable }));
                }
                else
                {
                    searcher.count  = 0;
                    searcher.enable = false;
                    await db.SaveChangesAsync();

                    return(new OkObjectResult(new { searcher.enable }));
                }
            }
            else
            {
                return(new ObjectResult(new { result = "not found" }));
            }
        }
Пример #8
0
        public async Task <IActionResult> Index(LoginViewModel model)
        {
            if (ModelState.IsValid)
            {
                var result = await signInManager.PasswordSignInAsync(model.TelNum, model.Password, false, false);

                if (result.Succeeded)
                {
                    if (!string.IsNullOrEmpty(model.ReturnUrl) && Url.IsLocalUrl(model.ReturnUrl))
                    {
                        return(Redirect(model.ReturnUrl));
                    }
                    else
                    {
                        var mod = await db.Allowkurs.FirstOrDefaultAsync(x => x.UserPhone == model.TelNum);

                        if (mod == null)
                        {
                            await db.Allowkurs.AddAsync(new Allowkurs
                            {
                                Pan_Id    = 1,
                                DateTime  = DateTime.Now,
                                UserPhone = model.TelNum
                            });

                            await db.SaveChangesAsync();
                        }
                        return(RedirectToAction("Korsetilim", "Matsau"));
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Номер немесе пароліңіз қате!!");
                }
            }
            return(PartialView(model));
        }
Пример #9
0
        public async Task <IActionResult> Register([FromBody] RegisterViewModel body)
        {
            if (!ModelState.IsValid)
            {
                return(new ObjectResult(new { result = "all required" }));
            }
            var userIdentity = mapper.Map <AppUsern>(body);
            var ext          = await userManager.FindByNameAsync(body.TelNum);

            if (ext != null)
            {
                return(new ObjectResult(new { result = "number" }));
            }
            // var cd = "";
            //var code = cache.TryGetValue(body.Email, out cd);
            //if(body.Code != cd)
            //{
            //    return new ObjectResult(new { result = "Code" });
            //}

            var result = await userManager.CreateAsync(userIdentity, body.Password);

            if (!result.Succeeded)
            {
                return(BadRequest("jj"));
            }

            AppUsern newuser = await userManager.FindByNameAsync(body.TelNum);

            // newuser.regdate = DateTime.Today.Date;

            //if (body.Type == "on")
            //{
            //    newuser.offenable = true;
            //}
            //else
            //{
            //    newuser.enable = true;
            //}


            //await db.Searches.AddAsync(new Search { IdentityId = userIdentity.Id, count = 30, enable = true, date = DateTime.Now });
            await userManager.AddToRoleAsync(userIdentity, "user");

            await db.SaveChangesAsync();

            //var claims = new[]
            //              {
            //                    new Claim(ClaimTypes.Name,userIdentity.UserName)
            //              };
            //var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("dfghdfghdfghjsfjgwtyieyutlhknljsad"));
            //var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);
            //var token = new JwtSecurityToken(
            //    issuer: "Issuer",
            //    audience: "Audience",
            //    claims: claims,
            //    //expires: DateTime.Now.AddMinutes(30),
            //    signingCredentials: creds);

            var tokenstring = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1lIjoiODc0NzkwODE4OTgiLCJpc3MiOiJJc3N1ZXIiLCJhdWQiOiJBdWRpZW5jZSJ9.pjbZR4Ac6Axl4qrM1YucW1lokXjPshbcOZEXLm2nj3c";
            var id          = userIdentity.Id;


            return(new ObjectResult(new { result = "success", id, tokenstring }));
        }