예제 #1
0
        public bool CreateImage(ImageModel image, Guid productId)
        {
            AmazonService amzService = new AmazonService();

            bool isSuccess = false;

            try
            {
                using (_context)
                {
                    byte[] imageBytes = null;

                    var toUpdate = _context.tProducts.Where(p => p.ProductId == productId).FirstOrDefault();
                    toUpdate.ImageUrl = image.ImageName;

                    using (var binaryReader = new BinaryReader(image.InputStream))
                    {
                        imageBytes = binaryReader.ReadBytes(image.ContentLength);
                        MemoryStream memoryStream = new MemoryStream(imageBytes);
                        amzService.PutObjectToAmazon("Products/" + toUpdate.ProductId.ToString(), memoryStream);
                    }

                    _context.SaveChanges();
                }

                return(isSuccess = true);
            }
            catch (Exception ex)
            {
                return(isSuccess);
            }
        }
예제 #2
0
        private void Submit_Click(object sender, RoutedEventArgs e)
        {
            if (textBoxEmail.Text.Length == 0 || textBoxFirstName.Text.Length <= 0 ||
                textBoxLastName.Text.Length <= 0)
            {
                errormessage.Text = "Enter all fields.";
                textBoxEmail.Focus();
            }
            else if (!Regex.IsMatch(textBoxEmail.Text, @"^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$"))
            {
                errormessage.Text = "Enter a valid email.";
                textBoxEmail.Select(0, textBoxEmail.Text.Length);
                textBoxEmail.Focus();
            }
            else
            {
                string firstname = textBoxFirstName.Text.Trim().ToUpper();
                string lastname  = textBoxLastName.Text.Trim().ToUpper();
                string email     = textBoxEmail.Text;
                string password  = passwordBox1.Password;

                if (passwordBox1.Password.Length == 0)
                {
                    errormessage.Text = "Enter password.";
                    passwordBox1.Focus();
                }
                else if (passwordBoxConfirm.Password.Length == 0)
                {
                    errormessage.Text = "Enter Confirm password.";
                    passwordBoxConfirm.Focus();
                }
                else if (passwordBox1.Password != passwordBoxConfirm.Password)
                {
                    errormessage.Text = "Confirm password must be same as password.";
                    passwordBoxConfirm.Focus();
                }
                else
                {
                    errormessage.Text = "";
                    int added = 0;
                    aws = new AmazonService();
                    string bucketName = Guid.NewGuid().ToString("N");
                    if (aws.CreateABucket(bucketName))
                    {
                        added = dataservice.RegisterUser(email, firstname, lastname, password, bucketName);
                    }
                    if (added > 0)
                    {
                        errormessage.Text = "You have Registered successfully.";
                        Reset();
                    }
                    else
                    {
                        errormessage.Text = "Problem in Registeration";
                    }
                }
            }
        }
예제 #3
0
        public void TestUpdateInventory()
        {
            Dictionary <string, int> quantities = new Dictionary <string, int>();

            quantities["01SHC1004CBL"] = 11;
            AmazonService service = new AmazonService(null, null, "server=localhost;port=3306;user=root;password=EFDnpz8PeJ758VeN;database=v3-all");

            service.UpdateInventory("*****@*****.**", quantities);
        }
예제 #4
0
        //ToDo: Start WebDev.WebServer.exe before the tests are run in TestSetup then delete this test
        public void SanityTest()
        {
            var amazonService = new AmazonService();

            try
            {
                amazonService.DiscoverUsernameXml("Adam-Kahtava");
            }
            catch (Exception)
            {
                Assert.Fail("WebDev.WebServer.exe (cassini) probably isn't running, try starting up the ServiceHost project.");
            }
        }
        //ToDo: Start WebDev.WebServer.exe before the tests are run in TestSetup then delete this test
        public void SanityTest()
        {
            var amazonService = new AmazonService();

            try
            {
                amazonService.DiscoverUsernameXml("Adam-Kahtava");
            }
            catch(Exception)
            {
                Assert.Fail("WebDev.WebServer.exe (cassini) probably isn't running, try starting up the ServiceHost project.");
            }
        }
        public void ShouldVerifyProxyAndReturnReviews()
        {
            var amazonService = new AmazonService();

            var reviewsFromXmlRequest = amazonService.ReviewsByCustomerIdXml("A2JM0EQJELFL69");

            Assert.IsNotNull(reviewsFromXmlRequest);
            Assert.Greater(reviewsFromXmlRequest.Count, 1);
            
            var reviewsFromJsonRequest = amazonService.ReviewsByCustomerIdJson("A2JM0EQJELFL69");

            Assert.IsNotNull(reviewsFromJsonRequest);
            Assert.AreEqual(reviewsFromXmlRequest.Count, reviewsFromJsonRequest.Count);
        }
예제 #7
0
        public void ShouldVerifyProxyAndReturnReviews()
        {
            var amazonService = new AmazonService();

            var reviewsFromXmlRequest = amazonService.ReviewsByCustomerIdXml("A2JM0EQJELFL69");

            Assert.IsNotNull(reviewsFromXmlRequest);
            Assert.Greater(reviewsFromXmlRequest.Count, 1);

            var reviewsFromJsonRequest = amazonService.ReviewsByCustomerIdJson("A2JM0EQJELFL69");

            Assert.IsNotNull(reviewsFromJsonRequest);
            Assert.AreEqual(reviewsFromXmlRequest.Count, reviewsFromJsonRequest.Count);
        }
예제 #8
0
        public void ShouldVerifyProxyAndReturnWishlist()
        {
            var amazonService = new AmazonService();

            var wishlistFromXmlRequest = amazonService.WishlistByListIdXml("1XZDXVXHE3946");

            Assert.IsNotNull(wishlistFromXmlRequest);
            Assert.Greater(wishlistFromXmlRequest.Count, 1);

            var wishlistFromJsonRequest = amazonService.WishlistByListIdXml("1XZDXVXHE3946");

            Assert.IsNotNull(wishlistFromJsonRequest);
            Assert.AreEqual(wishlistFromXmlRequest.Count, wishlistFromJsonRequest.Count);
        }
        public void ShouldVerifyProxyAndReturnWishlist()
        {
            var amazonService = new AmazonService();

            var wishlistFromXmlRequest = amazonService.WishlistByListIdXml("1XZDXVXHE3946");

            Assert.IsNotNull(wishlistFromXmlRequest);
            Assert.Greater(wishlistFromXmlRequest.Count, 1);

            var wishlistFromJsonRequest = amazonService.WishlistByListIdXml("1XZDXVXHE3946");

            Assert.IsNotNull(wishlistFromJsonRequest);
            Assert.AreEqual(wishlistFromXmlRequest.Count, wishlistFromJsonRequest.Count);
        }
        public void ShouldVerifyProxyAndReturnProfile()
        {
            var amazonService = new AmazonService();

            var profileFromXmlRequest = amazonService.DiscoverUsernameXml("Adam-Kahtava");

            Assert.IsNotNull(profileFromXmlRequest);
            Assert.IsFalse(string.IsNullOrEmpty(profileFromXmlRequest.CustomerId));
            Assert.IsFalse(string.IsNullOrEmpty(profileFromXmlRequest.ListId));

            var profileFromJsonRequest = amazonService.DiscoverUsernameJson("Adam-Kahtava");

            Assert.AreEqual(profileFromXmlRequest.CustomerId, profileFromJsonRequest.CustomerId);
            Assert.AreEqual(profileFromXmlRequest.ListId, profileFromJsonRequest.ListId);
        }
예제 #11
0
        public void ShouldVerifyProxyAndReturnProfile()
        {
            var amazonService = new AmazonService();

            var profileFromXmlRequest = amazonService.DiscoverUsernameXml("Adam-Kahtava");

            Assert.IsNotNull(profileFromXmlRequest);
            Assert.IsFalse(string.IsNullOrEmpty(profileFromXmlRequest.CustomerId));
            Assert.IsFalse(string.IsNullOrEmpty(profileFromXmlRequest.ListId));

            var profileFromJsonRequest = amazonService.DiscoverUsernameJson("Adam-Kahtava");

            Assert.AreEqual(profileFromXmlRequest.CustomerId, profileFromJsonRequest.CustomerId);
            Assert.AreEqual(profileFromXmlRequest.ListId, profileFromJsonRequest.ListId);
        }
예제 #12
0
        public ActionResult Index()
        {
            SearchModel searchModel = new SearchModel();

            if (Request.Params["search"] != null)
            {
                String searchKeyword = Request.Params["search"];
                searchModel.SearchKeyword = searchKeyword;
                AmazonService     amazoneService = new AmazonService();
                String            searchMoreFormAmazoneUrl;
                List <AmazonItem> items = amazoneService.searchFormAmazone(searchKeyword, out searchMoreFormAmazoneUrl);
                searchModel.AmazonItem    = items;
                searchModel.SearchMoreUrl = searchMoreFormAmazoneUrl;
            }

            return(View(searchModel));
        }
예제 #13
0
        public async Task <JsonResult> UploadImage()
        {
            var promoId = Request["PromoId"].ToString();

            if (Request.Files.Count > 0)
            {
                var amazon = new AmazonService();
                for (var i = 0; i < Request.Files.Count; i++)
                {
                    var file     = Request.Files[i];
                    var filename = Path.GetFileName(file.FileName);

                    var tempFilePath = Server.MapPath("~/TempUpload/" + filename);
                    var s3Path       = string.Format("images/{0}", Guid.NewGuid());

                    file.SaveAs(tempFilePath);
                    using (var fileIO = System.IO.File.OpenRead(tempFilePath))
                    {
                        using (MemoryStream tempFileStream = new MemoryStream())
                        {
                            fileIO.CopyTo(tempFileStream);
                            amazon.S3Upload(s3Path, MimeMapping.GetMimeMapping(file.FileName), tempFileStream);
                        }
                    }
                    System.IO.File.Delete(tempFilePath);

                    var promo = await _promoRepository.Get(promoId);

                    if (promo.Images == null)
                    {
                        promo.Images = new List <PromoImages>();
                    }
                    promo.Images.Add(new PromoImages
                    {
                        Filename = filename,
                        IsMain   = false,
                        Path     = s3Path,
                        Sort     = 0
                    });
                    await _promoRepository.Update(promoId, promo);
                }
            }
            return(Json(""));
        }
예제 #14
0
        public bool CreateImage(List <ImageModel> images)
        {
            AmazonService amzService = new AmazonService();

            bool isSuccess = false;

            try
            {
                using (_context)
                {
                    foreach (var image in images)
                    {
                        byte[] imageBytes = null;

                        tImage newImage = new tImage();
                        newImage.Active     = true;
                        newImage.ImageId    = Guid.NewGuid();
                        newImage.Name       = image.ImageName;
                        newImage.AlbumId    = image.AlbumId;
                        newImage.IsFeatured = image.IsFeatured;

                        _context.tImages.Add(newImage);

                        using (var binaryReader = new BinaryReader(image.InputStream))
                        {
                            imageBytes = binaryReader.ReadBytes(image.ContentLength);
                            MemoryStream memoryStream = new MemoryStream(imageBytes);
                            amzService.PutObjectToAmazon("Gallery/" + newImage.ImageId.ToString(), memoryStream);
                        }
                    }

                    _context.SaveChanges();
                }

                return(isSuccess = true);
            }
            catch (Exception ex)
            {
                return(isSuccess);
            }
        }
예제 #15
0
        public MainWindow(User user)
        {
            InitializeComponent();
            string icon = ConfigurationManager.AppSettings["Icon"];

            Icon = new BitmapImage(new Uri(icon, UriKind.Relative));
            FeedBack.Visibility = Visibility.Hidden;
            _user      = user;
            timer      = new DispatcherTimer();
            amzservice = new AmazonService();

            timer.Start();
            timer.Interval = TimeSpan.FromMinutes(1);
            timer.Tick    += new EventHandler(TimerTicks);

            ni                 = new System.Windows.Forms.NotifyIcon();
            ni.Icon            = new System.Drawing.Icon(icon);
            ni.BalloonTipText  = "The app has been minimised. Click the tray icon to show.";
            ni.BalloonTipTitle = "The App";
            ni.Text            = "The App";
            ni.Click          += new EventHandler(m_notifyIcon_Click);
        }
예제 #16
0
        public bool DeleteProduct(Guid productId)
        {
            bool isSuccess = false;

            try
            {
                AmazonService amzService = new AmazonService();

                amzService.DeleteObjectFromAmazon("Products/" + productId.ToString());

                var toDelete = _context.tProducts.Where(p => p.ProductId == productId).FirstOrDefault();

                _context.tProducts.Remove(toDelete);
                _context.SaveChanges();

                isSuccess = true;
            }
            catch (Exception)
            {
                isSuccess = false;
            }
            return(isSuccess);
        }
예제 #17
0
 public FileResult DownloadFileByPath(string path, string filename, bool isEmbed)
 {
     if (!string.IsNullOrEmpty(path))
     {
         var amazon   = new AmazonService();
         var fileByte = amazon.ReteiveFile(path);
         if (isEmbed)
         {
             var cd = new System.Net.Mime.ContentDisposition
             {
                 FileName = filename,
                 Inline   = true,
             };
             string contentType = MimeMapping.GetMimeMapping(filename);
             Response.AppendHeader("Content-Disposition", cd.ToString());
             return(File(fileByte, contentType));
         }
         else
         {
             return(File(fileByte, System.Net.Mime.MediaTypeNames.Application.Octet, filename));
         }
     }
     return(null);
 }
예제 #18
0
        public bool DeleteImage(Guid imageId)
        {
            using (_context)
            {
                try
                {
                    AmazonService amzService = new AmazonService();

                    amzService.DeleteObjectFromAmazon("Gallery/" + imageId.ToString());

                    var imageToDelete = _context.tImages.Where(i => i.ImageId == imageId).First();

                    _context.tImages.Remove(imageToDelete);

                    _context.SaveChanges();

                    return(true);
                }
                catch (Exception ex)
                {
                    return(false);
                }
            }
        }
예제 #19
0
        public bool DeleteAlbum(Guid albumId)
        {
            bool isSuccess = true;

            try
            {
                var getImages = GetImages(albumId.ToString());


                using (_context)
                {
                    foreach (var image in getImages)
                    {
                        AmazonService amzService = new AmazonService();

                        amzService.DeleteObjectFromAmazon("Gallery/" + image.ImageId.ToString());

                        var imageToDelete = _context.tImages.Where(i => i.ImageId == image.ImageId).First();

                        _context.tImages.Remove(imageToDelete);
                    }

                    var albumToDelete = _context.tAlbums.Where(a => a.AlbumId == albumId).First();

                    _context.tAlbums.Remove(albumToDelete);

                    _context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                isSuccess = false;
            }

            return(isSuccess);
        }
예제 #20
0
        static void Main(string[] args)
        {
            var amazonService = new AmazonService();

            amazonService.CreateData().Wait();
        }