Ejemplo n.º 1
0
        protected void Login(IdentityUser user, UserManager <IdentityUser> manager)
        {
            var authenticationManager = HttpContext.Current.GetOwinContext().Authentication;
            var userIdentity          = manager.CreateIdentity(user, DefaultAuthenticationTypes.ApplicationCookie);

            authenticationManager.SignIn(new AuthenticationProperties()
            {
                IsPersistent = false
            }, userIdentity);

            // add items to basket if necessary
            if (Session["basketProductId"] != null)
            {
                DatabaseCO5027Entities db = new DatabaseCO5027Entities();
                var basketEntry           = new Basket();
                basketEntry.CustomerId = user.Id;
                basketEntry.ProductId  = (int)Session["basketProductId"];
                db.Baskets.Add(basketEntry);
                db.SaveChanges();

                Session.Remove("basketProductId");

                Response.Redirect("~/checkout.aspx");
            }

            if (Request.QueryString["ReturnUrl"] == null)
            {
                Response.Redirect("~/user/default.aspx");
            }
        }
Ejemplo n.º 2
0
        protected void btnRegister_Click(object sender, EventArgs e)
        {
            var userStore = new UserStore <IdentityUser>();
            var manager   = new UserManager <IdentityUser>(userStore);
            var user      = new IdentityUser()
            {
                UserName = txtRegisterUsername.Text
            };
            IdentityResult result = manager.Create(user, txtRegisterPassword.Text);

            if (result.Succeeded)
            {
                DatabaseCO5027Entities db = new DatabaseCO5027Entities();
                var userDetails           = new UserDetail();
                userDetails.UserId    = user.Id;
                userDetails.FirstName = txtRegisterFirstName.Text;
                userDetails.Surname   = txtRegisterSurname.Text;
                userDetails.Email     = txtRegisterEmail.Text;
                db.UserDetails.Add(userDetails);
                db.SaveChanges();
                db.Dispose();

                SendWelcomeEmailToCustomer(user);
                SendWelcomeEmailToAdmin(user);
                Login(user, manager);
            }
            else
            {
                litError.Text = result.Errors.FirstOrDefault();
            }
        }
Ejemplo n.º 3
0
        protected void sendEmailToCustomer(OrderedProduct orderedProduct, int remainingDownloads)
        {
            string userId = User.Identity.GetUserId();

            DatabaseCO5027Entities db       = new DatabaseCO5027Entities();
            UserDetail             customer = db.UserDetails.Single(u => u.UserId == userId);

            db.Dispose();

            string baseUrl = Request.Url.Scheme + "://" + Request.Url.Authority;

            string emailBody = customer.FirstName + "," + Environment.NewLine;

            emailBody += Environment.NewLine;
            emailBody += "Just a quick reminder of the remaining download allowance for your photo: " + Environment.NewLine;
            emailBody += Environment.NewLine;
            emailBody += "----------" + Environment.NewLine;
            emailBody += orderedProduct.Product.Name + Environment.NewLine;
            emailBody += "Remaining available downloads: " + remainingDownloads + Environment.NewLine;
            emailBody += "----------" + Environment.NewLine;
            emailBody += Environment.NewLine;
            emailBody += "Need to download this photo again? " + Environment.NewLine;
            emailBody += baseUrl + ResolveUrl("~/user/download.aspx?id=" + orderedProduct.ProductId) + Environment.NewLine;
            emailBody += Environment.NewLine;
            emailBody += "If you have trouble downloading, please contact us." + Environment.NewLine;
            emailBody += baseUrl + ResolveUrl("~/contact.aspx") + Environment.NewLine;
            emailBody += Environment.NewLine;
            emailBody += "Message sent though StunningSnaps website";

            string subject = "Downloaded: " + orderedProduct.Product.Name + " from StunningSnaps";

            Email.sendEmail(customer.Email, "*****@*****.**", subject, emailBody);
        }
Ejemplo n.º 4
0
        protected void btnUpload_Click(object sender, EventArgs e)
        {
            decimal price;

            if (!Decimal.TryParse(txtPrice.Text, out price))
            {
                litFeedback.Text = "Please enter a price in the formal: 5.20";
                return;
            }

            string idString = Request.QueryString["id"];
            int    id       = 0;

            if (int.TryParse(idString, out id))
            {
                DatabaseCO5027Entities db = new DatabaseCO5027Entities();
                var product = db.Products.Single(p => p.Id == id);
                product.Name        = txtName.Text;
                product.Description = txtDescription.Text;
                product.Price       = price;

                db.SaveChanges();
                Response.Redirect("~/admin");
            }
            else
            {
                if (uploadImage(txtName.Text, txtDescription.Text, price))
                {
                    txtName.Text        = "";
                    txtDescription.Text = "";
                    Response.Redirect("~/admin");
                }
            }
        }
Ejemplo n.º 5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string idString = Request.QueryString["id"];
                int    id       = 0;
                if (int.TryParse(idString, out id))
                {
                    try
                    {
                        DatabaseCO5027Entities db = new DatabaseCO5027Entities();
                        Product product           = db.Products.Single(p => p.Id == id);

                        txtName.Text        = product.Name;
                        txtDescription.Text = product.Description;
                        txtPrice.Text       = ((decimal)product.Price).ToString("0.00");

                        btnUpload.Text = "Update";
                    }
                    catch
                    {
                        litFeedback.Text       = "Error loading photo";
                        pnlInputFields.Visible = false;
                        btnUpload.Visible      = false;
                    }
                    pnlUploadControl.Visible = false;
                }
            }
        }
Ejemplo n.º 6
0
        private void BindRepeater()
        {
            DatabaseCO5027Entities db = new DatabaseCO5027Entities();
            var products = db.Products.ToList();

            rptPhotos.DataSource = products;
            rptPhotos.DataBind();
        }
Ejemplo n.º 7
0
        private void BindRepeater()
        {
            DatabaseCO5027Entities db = new DatabaseCO5027Entities();
            var orders = db.Orders.OrderByDescending(o => o.DateStamp).ToList();

            if (orders.Count < 1)
            {
                litNoOrders.Text = "<p>There are no orders.</p>";
            }

            rptOrders.DataSource = orders;
            rptOrders.DataBind();
        }
Ejemplo n.º 8
0
        protected void rptOrderedProducts_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            string idString = e.CommandArgument.ToString();

            int id = int.Parse(idString);
            DatabaseCO5027Entities db = new DatabaseCO5027Entities();

            var orderedProduct = db.OrderedProducts.Single(op => op.Id == id);

            orderedProduct.DownloadsAllowed += 1;

            db.SaveChanges();
            BindRepeater();
        }
Ejemplo n.º 9
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string customerId         = User.Identity.GetUserId();
            DatabaseCO5027Entities db = new DatabaseCO5027Entities();
            var orders = db.Orders.Where(o => o.CustomerId == customerId && o.Cancelled == false).OrderByDescending(o => o.DateStamp).ToList();

            if (orders.Count < 1)
            {
                litNoOrders.Text = "<p>You have no orders.</p>";
            }

            rptOrders.DataSource = orders;
            rptOrders.DataBind();
        }
Ejemplo n.º 10
0
        protected void SendWelcomeEmailToAdmin(IdentityUser user)
        {
            DatabaseCO5027Entities db = new DatabaseCO5027Entities();
            var userDetails           = db.UserDetails.Single(u => u.UserId == user.Id);
            var email     = userDetails.Email;
            var firstName = userDetails.FirstName;
            var lastName  = userDetails.Surname;

            string emailBody = "";

            emailBody += "New user created: " + firstName + " " + lastName + Environment.NewLine;
            emailBody += "(Username: "******", Email:" + email + ")" + Environment.NewLine;

            Email.sendEmail("*****@*****.**", "*****@*****.**", "New Account Created: " + user.UserName, emailBody);
        }
Ejemplo n.º 11
0
        protected void btnReprocessImages_Click(object sender, EventArgs e)
        {
            DatabaseCO5027Entities db = new DatabaseCO5027Entities();
            var imageProcessor        = new ImageProcessing();
            var products = db.Products.ToList();

            db.Dispose();
            foreach (Product p in products)
            {
                string path = Server.MapPath("~/files/images/original/" + p.Id.ToString() + p.Extension);
                var    img  = System.Drawing.Image.FromFile(path);
                imageProcessor.SaveWatermarkedImages(img, p.Id);
                img.Dispose();
            }
        }
Ejemplo n.º 12
0
        protected void rptOrders_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            string idString = e.CommandArgument.ToString();

            int id = int.Parse(idString);
            DatabaseCO5027Entities db = new DatabaseCO5027Entities();

            var order = db.Orders.Single(o => o.Id == id);

            order.Cancelled = true;
            foreach (var item in order.OrderedProducts)
            {
                item.DownloadsAllowed = 0;
            }

            db.SaveChanges();
            BindRepeater();
        }
Ejemplo n.º 13
0
        protected void rptPhotos_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            string idString = e.CommandArgument.ToString();

            int id = int.Parse(idString);

            DatabaseCO5027Entities db = new DatabaseCO5027Entities();
            var product = db.Products.Single(p => p.Id == id);

            if (product.Archived)
            {
                product.Archived = false;
            }
            else
            {
                product.Archived = true;
            }

            db.SaveChangesAsync();
            BindRepeater();
        }
Ejemplo n.º 14
0
        protected void SendWelcomeEmailToCustomer(IdentityUser user)
        {
            DatabaseCO5027Entities db = new DatabaseCO5027Entities();
            var    userDetails        = db.UserDetails.Single(u => u.UserId == user.Id);
            var    email     = userDetails.Email;
            var    firstName = userDetails.FirstName;
            var    lastName  = userDetails.Surname;
            string baseUrl   = Request.Url.Scheme + "://" + Request.Url.Authority;

            string emailBody = "";

            emailBody += "Hello " + firstName + "," + Environment.NewLine;
            emailBody += Environment.NewLine;
            emailBody += "Thank you for signing up for an account with StunningSnaps!" + Environment.NewLine;
            emailBody += Environment.NewLine;
            emailBody += "Your username is: " + user.UserName + Environment.NewLine;
            emailBody += "Your password was set during account creation. If you need to reset your password, please follow the reset password instructions on the Login page." + Environment.NewLine;
            emailBody += Environment.NewLine;
            emailBody += "Message sent though StunningSnaps website" + Environment.NewLine;
            emailBody += baseUrl + ResolveUrl("~/");

            Email.sendEmail(email, "*****@*****.**", "Welcome to StunningSnaps!", emailBody);
        }
Ejemplo n.º 15
0
        private bool uploadImage(string name, string description, decimal price)
        {
            bool   success       = false;
            string fileExtention = System.IO.Path.GetExtension(fUplPictureUpload.FileName).ToLower();

            if (fileExtention == ".jpeg" || fileExtention == ".jpg" || fileExtention == ".gif" || fileExtention == ".png" || fileExtention == ".tif" || fileExtention == ".tiff")
            {
                try
                {
                    // check image is readable & determine dimentions
                    System.Drawing.Image img = System.Drawing.Image.FromStream(fUplPictureUpload.PostedFile.InputStream);
                    int height = img.Height;
                    int width  = img.Width;

                    DatabaseCO5027Entities db = new DatabaseCO5027Entities();
                    Product product           = new Product();

                    product.Archived      = false;
                    product.Name          = name;
                    product.Description   = description;
                    product.Price         = price;
                    product.InitialHeight = height;
                    product.InitialWidth  = width;
                    product.Extension     = fileExtention;

                    db.Products.Add(product);
                    db.SaveChanges();

                    string filename = product.Id.ToString();

                    // save original image to disk
                    string filePath = Server.MapPath("~/files/images/original/" + filename + fileExtention);
                    img.Save(filePath);
                    product.SizeOfFile = (int)new System.IO.FileInfo(filePath).Length;
                    db.SaveChanges();

                    // save watermarked images to disk

                    ImageProcessing imageProcessor = new ImageProcessing();

                    if (imageProcessor.SaveWatermarkedImages(img, product.Id))
                    {
                        success = true;
                        return(success);
                    }
                    else
                    {
                        success          = false;
                        litFeedback.Text = "Unable to process image, please go to <a href='manage.aspx'>Admin Panel</a> and click 'Reprocess Images' to try again.";
                        return(success);
                    }
                }
                catch
                {
                    success          = false;
                    litFeedback.Text = "Image not readable";
                    return(success);
                }
            }
            else
            {
                success          = false;
                litFeedback.Text = "Images of " + fileExtention + " are not accepted. Please upload a JPEG, PNG, GIF or TIFF.";
                return(success);
            }
        }
Ejemplo n.º 16
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // fetch photo id
            int  id      = 0;
            bool idIsInt = int.TryParse(Request.QueryString["id"], out id);

            if ((!idIsInt || id == 0))
            {
                Response.Redirect("~/user/");
            }

            DatabaseCO5027Entities db             = new DatabaseCO5027Entities();
            OrderedProduct         orderedProduct = new OrderedProduct();

            string userId             = User.Identity.GetUserId();
            int    remainingDownloads = 0;

            try
            {
                var  orderedProducts = db.OrderedProducts.Where(op => op.Order.CustomerId == userId && op.ProductId == id);
                bool downloadAllowed = false;
                foreach (OrderedProduct item in orderedProducts)
                {
                    if ((item.DownloadCount < item.DownloadsAllowed))
                    {
                        downloadAllowed     = true;
                        orderedProduct      = item;
                        remainingDownloads += (item.DownloadsAllowed - item.DownloadCount);
                    }
                }
                if (!downloadAllowed)
                {
                    litMessage.Text = "<p>You are not permitted to download this photo. If you think this message is in error, please <a href=\"" + ResolveUrl("~/contact.aspx") + "\">contact us.</a></p>";
                    return;
                }
            }
            catch
            {
                Response.Redirect("~/user/");
            }

            // fetch from db
            Product photo = orderedProduct.Product;

            string extention    = photo.Extension;
            int    imageSize    = (int)photo.SizeOfFile;
            string downloadName = photo.Name + extention;
            string fileLocation = MapPath("~/files/images/original/" + id.ToString() + extention);

            // count download
            orderedProduct.DownloadCount += 1;
            remainingDownloads           -= 1;
            db.SaveChanges();

            sendEmailToCustomer(orderedProduct, remainingDownloads);

            try
            {
                // initiate download
                Response.ClearContent();
                Response.ClearHeaders();

                Response.ContentType = "image/jpeg";
                Response.AddHeader("Content-Disposition", "attachment; filename=" + downloadName + ";");
                Response.AddHeader("Content-Length", imageSize.ToString());
                Response.WriteFile(fileLocation);

                Response.Flush();
                Response.End();
            }
            catch
            {
            }
        }
Ejemplo n.º 17
0
        public bool SaveWatermarkedImages(System.Drawing.Image img, int photoId)
        {
            bool success = false;

            string filename = photoId.ToString();

            int height = img.Height;
            int width  = img.Width;

            string path = System.Web.Hosting.HostingEnvironment.MapPath("~/files/images/watermarked/");

            DatabaseCO5027Entities db = new DatabaseCO5027Entities();

            img = AddWatermark(img);

            var sizes = db.Sizes.Where(s => s.Archived == false).ToList();

            foreach (var size in sizes)
            {
                int maxWidth  = size.MaxWidth;
                int maxHeight = size.MaxHeight;

                var resizedImage = img;

                // prevents enlarging
                if (width > maxWidth || height > maxHeight)
                {
                    resizedImage = ImageManipulation.ResizeImage(img, maxWidth, maxHeight);
                }

                int newHeight = resizedImage.Height;
                int newWidth  = resizedImage.Width;

                string filePath = path + filename + "-" + size.Id + ".jpg";
                resizedImage.Save(filePath, System.Drawing.Imaging.ImageFormat.Jpeg);
                var fileSize = new System.IO.FileInfo(filePath).Length;

                var imageInDb = size.Images.FirstOrDefault(i => i.ProductId == photoId);
                if (imageInDb != null)
                {
                    imageInDb.Height     = newHeight;
                    imageInDb.Width      = newWidth;
                    imageInDb.SizeOfFile = (int)fileSize;
                    db.SaveChanges();
                }
                else
                {
                    imageInDb            = new CO5027.Image();
                    imageInDb.Height     = newHeight;
                    imageInDb.Width      = newWidth;
                    imageInDb.ProductId  = photoId;
                    imageInDb.SizeId     = size.Id;
                    imageInDb.SizeOfFile = (int)fileSize;
                    db.Images.Add(imageInDb);
                    db.SaveChanges();
                }
            }
            success = true;

            return(success);
        }