示例#1
0
        public async Task <bool> CreateAsync(CustomerEntity customer)
        {
            _context.Add(customer);
            await _context.SaveChangesAsync();

            return(true);
        }
        public async Task <IActionResult> Edit(int id, [Bind("video_id,baslik,aciklama,olusturulma,videoUrl,kategori_id,video_silme")] Video video)
        {
            if (id != video.video_id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(video);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!VideoExists(video.video_id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(video));
        }
        public async Task <IActionResult> PutContent([FromRoute] int id, [FromBody] Content content)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != content.ContentId)
            {
                return(BadRequest());
            }

            _context.Entry(content).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ContentExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> Edit(int id, [Bind("kategori_id,kategori_ad,Silme")] Kategoriler kategoriler)
        {
            if (id != kategoriler.kategori_id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(kategoriler);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!KategorilerExists(kategoriler.kategori_id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(kategoriler));
        }
示例#5
0
        public async Task <IActionResult> Edit(int id, [Bind("haber_id,baslik,aciklama,olusturulma,imageUrl,kategori_id,haber_silme")] Haber haber)
        {
            if (id != haber.haber_id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(haber);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!HaberExists(haber.haber_id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(haber));
        }
        public async Task <IActionResult> Create([Bind("Id,Name")] SecurityGroup securityGroup)
        {
            if (ModelState.IsValid)
            {
                _context.Add(securityGroup);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(securityGroup));
        }
        public async Task <bool> CreateAsync(SiteEntity siteEntity)
        {
            if (!IsIDExistsAsync(siteEntity.SiteID).Result)
            {
                _context.Add(siteEntity);
                await _context.SaveChangesAsync();

                return(true);
            }
            return(false);
        }
        public virtual async Task <ICorsPolicy> AddCorsPolicyAsync(ICorsPolicy corsPolicy, CancellationToken cancellationToken = default)
        {
            var initialCorsPolicy = new SiteCorsPolicy(Guid.NewGuid(), corsPolicy);

            _dbContext
            .CorsPolicies
            .Add(initialCorsPolicy);

            await _dbContext
            .SaveChangesAsync(cancellationToken);

            return(initialCorsPolicy);
        }
        public async Task <IActionResult> Register(RegisterViewModel model, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            if (ModelState.IsValid)
            {
                if (model.AcceptTerms)
                {
                    var user = new ApplicationUser {
                        UserName = model.UserName, Email = model.Email, Register = DateTime.Now, SlotForCompanion = 0
                    };
                    var result = await _userManager.CreateAsync(user, model.Password);

                    if (result.Succeeded)
                    {
                        // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=532713
                        // Send an email with this link
                        var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                        var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: HttpContext.Request.Scheme);
                        await _emailSender.SendEmailAsync(model.Email, "Confirm your account",
                                                          $"Please confirm your account by clicking this link: <a href='{callbackUrl}'>link</a>");

                        // await _signInManager.SignInAsync(user, isPersistent: false);
                        _logger.LogInformation(3, "User created a new account with password.");

                        // Setup Gold
                        Gold gold = new Gold()
                        {
                            UserId = user.Id,
                            Number = 0
                        };

                        // Setup Artifacts
                        Artifacts artifact = new Artifacts()
                        {
                            UserId = user.Id,
                            Number = 10
                        };

                        using (var context = new SiteDbContext())
                        {
                            context.Add(artifact);
                            context.Add(gold);
                            await context.SaveChangesAsync();
                        }

                        // Redirect
                        return(RedirectToLocal(returnUrl));
                    }
                    AddErrors(result);
                }
                else
                {
                    ModelState.AddModelError("AcceptTerms", "You must accept the Terms of Use");
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
示例#10
0
        public async Task <IActionResult> Buy(int ProductId, int Quantity)
        {
            var orderitem = new OrderItem();
            var product   = await db.Products.SingleOrDefaultAsync(i => i.Id == ProductId);//may be null

            orderitem.Product  = product;
            orderitem.Quantity = Quantity;

            var cartId = HttpContext.Request.Cookies["order-id"];

            if (String.IsNullOrEmpty(cartId))
            {
                var order = new Order();
                orderitem.Order = order;
                await db.OrderItems.AddAsync(orderitem);

                await db.Orders.AddAsync(order);

                await db.SaveChangesAsync();


                HttpContext.Response.Cookies.Append("order-id", Convert.ToString(order.Id));
            }
            else
            {
                var cart = await db.Orders
                           .Include(i => i.OrderItems)
                           .SingleOrDefaultAsync(i => i.Id == Convert.ToInt32(cartId));

                var prodInCart = cart.OrderItems
                                 .SingleOrDefault(i => i.ProductId == ProductId && i.OrderId == Convert.ToInt32(cartId));
                if (prodInCart == null)
                {
                    await db.OrderItems.AddAsync(orderitem);

                    cart.OrderItems.Add(orderitem);
                }
                else
                {
                    prodInCart.Quantity += Quantity;
                }
                await db.SaveChangesAsync();
            }


            return(View("~/Views/Home/Success.cshtml"));
        }
示例#11
0
        public async Task <ActionResult> EditProduct(Product product, string Price_string, string Weight_string, string Volume_string, string IsEdit)
        {
            var path = await UploadImage(product.ImagePath);

            if (String.IsNullOrEmpty(path))
            {
                if (String.IsNullOrEmpty(product.ImagePath))
                {
                    product.ImagePath = $"/Products/Images/{product.Name}.jpg";
                }
            }
            else
            {
                product.ImagePath = path;
            }

            if (Volume_string != null)
            {
                if (Volume_string.Contains('.'))
                {
                    Volume_string = Volume_string.Replace('.', ',');
                }
            }


            product.Price  = Convert.ToDouble(Price_string);
            product.Weight = Convert.ToDouble(Weight_string);
            Console.WriteLine(Volume_string);
            product.Volume = Convert.ToDouble(Volume_string);

            if (Convert.ToBoolean(IsEdit))
            {
                db.Products.Update(product);
            }
            else
            {
                await db.Products.AddAsync(product);
            }

            await db.SaveChangesAsync();

            //return View("~/Views/Home/Index.cshtml");
            var vm = new EditorProductVM
            {
                Categories = await db.Categories
                             .Include(c => c.SubCategories)
                             .ToListAsync()
            };

            return(View("~/Views/Editor/EditProduct.cshtml", vm));
        }
        public async Task <IActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl = null)
        {
            if (ModelState.IsValid)
            {
                // Get the information about the user from the external login provider
                var info = await _signInManager.GetExternalLoginInfoAsync();

                if (info == null)
                {
                    return(View("ExternalLoginFailure"));
                }
                var user = new ApplicationUser {
                    UserName = model.Username, Email = model.Email, Register = DateTime.Now, SlotForCompanion = 0
                };
                var result = await _userManager.CreateAsync(user);

                if (result.Succeeded)
                {
                    result = await _userManager.AddLoginAsync(user, info);

                    if (result.Succeeded)
                    {
                        await _signInManager.SignInAsync(user, isPersistent : false);

                        _logger.LogInformation(6, "User created an account using {Name} provider.", info.LoginProvider);

                        // Setup Artifacts
                        Artifacts artifact = new Artifacts()
                        {
                            UserId = user.Id,
                            Number = 10
                        };

                        using (var context = new SiteDbContext())
                        {
                            context.Add(artifact);
                            await context.SaveChangesAsync();
                        }

                        // Redirect
                        return(RedirectToLocal(returnUrl));
                    }
                }
                AddErrors(result);
            }

            ViewData["ReturnUrl"] = returnUrl;
            return(View(model));
        }
示例#13
0
        public async Task <IActionResult> Login(string Login, string Password) //TODO: user service to do this work
        {
            var enc  = new ServerEncryptor(Password);                          //md-hash encryptor
            var pass = enc.Hash;

            var selUser = await db.Users.SingleOrDefaultAsync(u => u.Login == Login);

            if (selUser.Password.ToString() == pass.ToString())
            {
                ViewBag.Login = Login;

                enc.GetHash(Login + DateTime.Now.ToString());
                var sessionId    = enc.Hash;
                var sessionIdStr = Encoding.UTF8.GetString(sessionId);

                var encCookie = new ServerEncryptor(Login + DateTime.Now.ToString() + "sdsd" + "random string" + "54POdsxc");
                var cookie    = encCookie.Hash;
                var cookieStr = Encoding.UTF8.GetString(cookie);

                HttpContext.Session.SetString("sessionId", sessionIdStr);              //save session
                HttpContext.Session.SetString("userId", Convert.ToString(selUser.Id)); //save user id in session



                selUser.CookieAuthToken = cookie;                                           //save cookies on client and server for every auth
                HttpContext.Response.Cookies.Append("cookieAuth", cookieStr);
                HttpContext.Response.Cookies.Append("userId", Convert.ToString(selUser.Id));

                if (selUser.IsFirstAuth)
                {
                    selUser.IsFirstAuth = false;
                }


                HttpContext.Session.GetString("sessionId");

                selUser.SessionId = sessionId;
                await db.SaveChangesAsync();

                return(View("~/Views/Auth/LoginSuccess.cshtml"));
            }
            else
            {
                return(View());
            }
        }
示例#14
0
 public async Task CommitAsycn()
 {
     await _context.SaveChangesAsync();
 }
        public async Task <IActionResult> Login(LoginViewModel model, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            if (ModelState.IsValid)
            {
                string item;
                using (var context = new SiteDbContext())
                {
                    item = context.Conf
                           .Where(r => r.Id == 1)
                           .Select(r => r.Value).First();
                }

                if (item == "1" || item == "2")
                {
                    ApplicationUser userData = await _userManager.FindByNameAsync(model.UserName);

                    if (!await _userManager.IsInRoleAsync(userData, "Administrator"))
                    {
                        ModelState.AddModelError(string.Empty, Util.LanguageSelection("The site is currently under maintenance.", "Le site est actuellement en maintenance."));
                        return(View(model));
                    }
                }

                var result = await _signInManager.PasswordSignInAsync(model.UserName, model.Password, model.RememberMe, lockoutOnFailure : true);

                if (result.Succeeded)
                {
                    ApplicationUser userData = await _userManager.FindByNameAsync(model.UserName);

                    Connections_statistics loginStat = new Connections_statistics()
                    {
                        UserId = userData.Id,
                        Date   = DateTime.Now
                    };

                    using (var context = new SiteDbContext())
                    {
                        context.Add(loginStat);
                        await context.SaveChangesAsync();
                    }

                    _logger.LogInformation(1, "User logged in.");

                    if (Url.IsLocalUrl(returnUrl))
                    {
                        return(Redirect(returnUrl));
                    }
                    else
                    {
                        return(RedirectToAction(nameof(GameController.Index), "Game"));
                    }
                }
                if (result.RequiresTwoFactor)
                {
                    return(RedirectToAction(nameof(SendCode), new { ReturnUrl = returnUrl, RememberMe = model.RememberMe }));
                }
                if (result.IsLockedOut)
                {
                    _logger.LogWarning(2, "User account locked out.");
                    return(View("Lockout"));
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "Invalid login attempt.");
                    return(View(model));
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }