Пример #1
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Shoe = await _context.Shoe.FindAsync(id);

            if (Shoe != null)
            {
                _context.Shoe.Remove(Shoe);

                if (await _context.SaveChangesAsync() > 0)
                {
                    var auditrecord = new AuditRecord();
                    auditrecord.AuditActionType = "Delete Shoe Record";
                    auditrecord.DateTimeStamp   = DateTime.Now;

                    var userID = User.Identity.Name.ToString();
                    auditrecord.Desc     = String.Format("Shoe record with shoe id:{0} was deleted by {1}", Shoe.ShoeID, userID);
                    auditrecord.Username = userID;
                    _context.AuditRecords.Add(auditrecord);
                    await _context.SaveChangesAsync();
                }
            }

            return(RedirectToPage("./Manage"));
        }
        public async Task <IActionResult> OnPostAsync(int reviewId, int shoeId)
        {
            Shoe = await _context.Shoe.FirstOrDefaultAsync(m => m.ShoeID == shoeId);

            if (Shoe == null)
            {
                IsDisplayable = true;
                return(RedirectToPage("../Manage"));
            }

            Review = await _context.ReviewFinals.FirstOrDefaultAsync(m => m.ReviewID == reviewId);

            if (Review == null)
            {
                return(Page());
            }
            _context.ReviewFinals.Remove(Review);
            await _context.SaveChangesAsync();

            var auditrecord = new AuditRecord();

            auditrecord.AuditActionType = "Remove review";
            auditrecord.DateTimeStamp   = DateTime.Now;

            var userID = User.Identity.Name.ToString();

            auditrecord.Desc = String.Format("Shoe review with Review id:{0} from Shoe id:{2} was removed by {1}", reviewId, userID, shoeId);

            auditrecord.Username = userID;

            _context.AuditRecords.Add(auditrecord);
            await _context.SaveChangesAsync();

            return(RedirectToPage("../Reviews/ManageAllReviews"));
        }
Пример #3
0
        public async Task<IActionResult> OnPostAsync(IFormFile uploadfiles)
        {
            if (!ModelState.IsValid)
            {
                return Page();
            }


            if (uploadfiles != null)
            {
                string imgext = Path.GetExtension(uploadfiles.FileName);
                if (imgext == ".jpg" || imgext == ".png")
                {
                    var img = Path.Combine(_iweb.WebRootPath, "images", uploadfiles.FileName);
                    var stream = new FileStream(img, FileMode.Create);
                    await uploadfiles.CopyToAsync(stream);
                    stream.Close();

                    Shoe.Image = uploadfiles.FileName;
                }
            }            

            _context.Attach(Shoe).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
                
                    var auditrecord = new AuditRecord();
                    auditrecord.AuditActionType = "Edit Shoe Record";
                    auditrecord.DateTimeStamp = DateTime.Now;
                    var userID = User.Identity.Name.ToString();
                    auditrecord.Desc = String.Format("Shoe record with shoe id:{0} was edited by {1}", Shoe.ShoeID, userID);

                    auditrecord.Username = userID;

                    _context.AuditRecords.Add(auditrecord);
                    await _context.SaveChangesAsync();
                
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ShoeExists(Shoe.ShoeID))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return RedirectToPage("./Manage");
        }
Пример #4
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            ApplicationRole appRole = await _roleManager.FindByIdAsync(ApplicationRole.Id);

            appRole.Id          = ApplicationRole.Id;
            appRole.Name        = ApplicationRole.Name;
            appRole.Description = ApplicationRole.Description;

            IdentityResult roleRuslt = await _roleManager.UpdateAsync(appRole);

            var auditrecord = new AuditRecord();

            auditrecord.AuditActionType = "Edit Role";
            auditrecord.DateTimeStamp   = DateTime.Now;

            var userID = User.Identity.Name.ToString();

            auditrecord.Desc = String.Format("User Role called '{0}' was edited by {1}", ApplicationRole.Name, userID);

            auditrecord.Username = userID;

            _context.AuditRecords.Add(auditrecord);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Пример #5
0
        public async Task <IActionResult> OnPostAsync(string id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            ApplicationRole = await _roleManager.FindByIdAsync(id);

            IdentityResult roleRuslt = await _roleManager.DeleteAsync(ApplicationRole);

            var auditrecord = new AuditRecord();

            auditrecord.AuditActionType = "Delete Role";
            auditrecord.DateTimeStamp   = DateTime.Now;

            var userID = User.Identity.Name.ToString();

            auditrecord.Desc     = String.Format("User Role called '{0}' was deleted by {1}", ApplicationRole.Name, userID);
            auditrecord.Username = userID;

            _context.AuditRecords.Add(auditrecord);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Пример #6
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            ApplicationRole.CreatedDate = DateTime.UtcNow;
            ApplicationRole.IPAddress   = Request.HttpContext.Connection.RemoteIpAddress.ToString();

            IdentityResult roleRuslt = await _roleManager.CreateAsync(ApplicationRole);

            var auditrecord = new AuditRecord();

            auditrecord.AuditActionType = "Create Role";
            auditrecord.DateTimeStamp   = DateTime.Now;

            var userID = User.Identity.Name.ToString();

            auditrecord.Desc = String.Format("User Role called '{0}' was created by {1}", ApplicationRole.Name, userID);

            auditrecord.Username = userID;

            _context.AuditRecords.Add(auditrecord);
            await _context.SaveChangesAsync();

            return(RedirectToPage("Index"));
        }
Пример #7
0
        public async Task <IActionResult> OnPostAsync(IFormFile uploadfiles)
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            if (uploadfiles != null)
            {
                string imgext = Path.GetExtension(uploadfiles.FileName);
                if (imgext == ".jpg" || imgext == ".png")
                {
                    var img    = Path.Combine(_iweb.WebRootPath, "images", uploadfiles.FileName);
                    var stream = new FileStream(img, FileMode.Create);
                    await uploadfiles.CopyToAsync(stream);

                    stream.Close();

                    Shoe.Image = uploadfiles.FileName;
                    _context.Shoe.Add(Shoe);
                }
            }

            if (await _context.SaveChangesAsync() > 0)
            {
                var auditrecord = new AuditRecord();
                auditrecord.AuditActionType = "Add Shoe Record";
                auditrecord.DateTimeStamp   = DateTime.Now;

                var userID = User.Identity.Name.ToString();
                auditrecord.Desc = String.Format("Shoe record with shoe id:{0} was added by {1}", Shoe.ShoeID, userID);

                auditrecord.Username = userID;

                _context.AuditRecords.Add(auditrecord);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Manage"));
        }
Пример #8
0
        public async Task <IActionResult> OnPostAsync(int id)
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            Review.ShoeID = id;
            _context.ReviewFinals.Add(Review);
            await _context.SaveChangesAsync();

            return(RedirectToPage("../Shoes/Details/", new { id = id }));
        }
Пример #9
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl = returnUrl ?? Url.Content("~/");

            string recaptchaResponse = this.Request.Form["g-recaptcha-response"];
            var    client            = HttpClientFactory.Create();

            try
            {
                var parameters = new Dictionary <string, string>
                {
                    { "secret", configuration.GetSection("reCAPTCHA").GetValue <string>("SecretKey") },
                    { "response", recaptchaResponse },
                    { "remoteip", this.HttpContext.Connection.RemoteIpAddress.ToString() }
                };

                HttpResponseMessage response = await client.PostAsync("https://www.google.com/recaptcha/api/siteverify", new FormUrlEncodedContent(parameters));

                response.EnsureSuccessStatusCode();

                string apiResponse = await response.Content.ReadAsStringAsync();

                dynamic apiJson = JObject.Parse(apiResponse);
                if (apiJson.success != true)
                {
                    this.ModelState.AddModelError(string.Empty, "Please verify that you are a human.");
                }
            }
            catch (HttpRequestException ex)
            {
                // Something went wrong with the API. Let the request through.
                _logger.LogError(ex, "Unexpected error calling reCAPTCHA api.");
            }

            if (ModelState.IsValid)
            {
                // This doesn't count login failures towards account lockout
                // To enable password failures to trigger account lockout, set lockoutOnFailure: true
                var result = await _signInManager.PasswordSignInAsync(Input.Email, Input.Password, Input.RememberMe, lockoutOnFailure : true);

                if (result.Succeeded)
                {
                    _logger.LogInformation("User logged in.");
                    return(LocalRedirect(returnUrl));
                }
                else
                {
                    var auditrecord = new AuditRecord();
                    auditrecord.AuditActionType = "Failed Login";
                    auditrecord.DateTimeStamp   = DateTime.Now;
                    auditrecord.Desc            = String.Format("{0} failed to log in", Input.Email);

                    auditrecord.Username = Input.Email;
                    _context.AuditRecords.Add(auditrecord);
                    await _context.SaveChangesAsync();
                }
                if (result.RequiresTwoFactor)
                {
                    return(RedirectToPage("./LoginWith2fa", new { ReturnUrl = returnUrl, RememberMe = Input.RememberMe }));
                }
                if (result.IsLockedOut)
                {
                    _logger.LogWarning("User account locked out.");
                    return(RedirectToPage("./Lockout"));
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "Invalid login attempt.");
                    return(Page());
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }
Пример #10
0
        public async Task <IActionResult> OnPostAsync(string stripeEmail, string stripeToken, int?id)
        {
            shoe = await _context.Shoe.FirstOrDefaultAsync(m => m.ShoeID == id);

            if (shoe == null)
            {
                return(NotFound());
            }

            var customers = new CustomerService();
            var charges   = new ChargeService();

            try {
                var customer = customers.Create(new CustomerCreateOptions
                {
                    Email  = stripeEmail,
                    Source = stripeToken
                });



                var charge = charges.Create(new ChargeCreateOptions
                {
                    Amount       = Convert.ToInt64(shoe.Price) * 100, //Need to change the amount to shopping cart page
                    Description  = shoe.Name,
                    Currency     = "sgd",
                    Customer     = customer.Id,
                    ReceiptEmail = stripeEmail // Send email receipt to customer
                });


                if (charge.Status == "succeeded")
                {
                    var user = await _userManager.GetUserAsync(User);

                    Bought QueryBought = new Bought {
                        Id = user.Id, ShoeID = shoe.ShoeID
                    };
                    var bought = await _context.bought.FirstOrDefaultAsync(m => m.Id == QueryBought.Id && m.ShoeID == QueryBought.ShoeID);

                    if (bought == null)
                    {
                        _context.bought.Add(QueryBought);
                        await _context.SaveChangesAsync();
                    }
                    string      receipturl = charge.ReceiptUrl;
                    string      subject    = "Cinderella Order Confirmation";
                    string      To         = charge.ReceiptEmail;
                    string      Body       = string.Format("Thanks for shopping with Cinderella \nTransaction No. :{0}\nAmount paid: ${1}\nYour order for {2} will be shipped to you shortly. Alternatively, you may view your e-receipt at {3}.", charge.Id, charge.Amount / 100, shoe.Name, receipturl);
                    MailMessage mail       = new MailMessage();
                    mail.To.Add(To);
                    mail.Subject    = subject;
                    mail.Body       = Body;
                    mail.IsBodyHtml = false;
                    mail.From       = new MailAddress("*****@*****.**");
                    SmtpClient smtp = new SmtpClient("smtp.gmail.com")
                    {
                        Port = 587,
                        UseDefaultCredentials = true,
                        EnableSsl             = true, //use SSL to secure connection
                        Credentials           = new System.Net.NetworkCredential("*****@*****.**", "Cinderella123!")
                    };
                    await smtp.SendMailAsync(mail);

                    if (charge.ReceiptEmail != user.Email)
                    {
                        string      nsubject = "Cinderella Order Confirmation";
                        string      nTo      = user.Email;
                        string      nBody    = string.Format("An order for {0} was made from your account\nIf this is not you, please contact us immediately", shoe.Name);
                        MailMessage nmail    = new MailMessage();
                        nmail.To.Add(nTo);
                        nmail.Subject    = nsubject;
                        nmail.Body       = nBody;
                        nmail.IsBodyHtml = false;
                        nmail.From       = new MailAddress("*****@*****.**");
                        await smtp.SendMailAsync(nmail);
                    }
                    TransactionLog log = new TransactionLog {
                        Id = user.Id, TransactionNumber = charge.Id, Time = DateTime.Now
                    };
                    _context.TransactionLogs.Add(log);
                    await _context.SaveChangesAsync();

                    return(RedirectToPage("./Success_Page"));
                }
                else
                {
                    //should make this display the error, like 'insufficient funds' or smth
                    return(RedirectToPage("./Fail_Transaction"));
                }
            }
            catch
            {
                return(RedirectToPage("./Fail_Transaction"));
            }
        }