[Fact] // 2. string GetPublicId(int id)
        public async void GetPublicId_shouldReturnImagePublicId()
        {
            // Arrange
            var imageUrl      = Guid.NewGuid().ToString();
            var imagePublicId = Guid.NewGuid().ToString();
            var image         = new CloudImage
            {
                PictureUrl      = imageUrl,
                PicturePublicId = imagePublicId,
            };

            await this.Context.CloudImages.AddAsync(image);

            await this.Context.SaveChangesAsync();

            var service = new ImageDbService(this.Context);

            // Act
            var result   = service.GetPublicId(image.Id);
            var expected = await this.Context.CloudImages
                           .Where(i => i.PicturePublicId == imagePublicId)
                           .Select(i => i.Id)
                           .FirstOrDefaultAsync();

            // Assert
            result.Should().Equals(expected);
        }
        public async Task <IActionResult> CreatePostAsync(OwnerListingCreateInputModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(model));
            }

            var userId = this.userManager.GetUserId(this.User);
            var user   = await this.userManager.FindByIdAsync(userId);

            // Upload the Image
            var imgResult = await this.imageService
                            .UploadImageAsync(model.Image);

            string imgUrl   = imgResult.SecureUri.AbsoluteUri;
            string imgPubId = imgResult.PublicId;

            var imageToWrite = new CloudImage
            {
                PictureUrl      = imgUrl,
                PicturePublicId = imgPubId,
            };

            var homeCreateServiceModel = new OwnerCreateListingServiceModel
            {
                Name        = model.Name,
                Description = model.Description,
                Address     = model.Address,
                Price       = model.Price,
                CityId      = model.CityId,
                Category    = model.Category,
                Status      = model.Status,
                Owner       = user,
                Image       = imageToWrite,
            };

            // Create Listing
            bool isCreated = await this.ownerListingService.CreateListingAsync(homeCreateServiceModel);

            if (!isCreated)
            {
                return(this.RedirectToAction("Index", "Dashboard", new { area = string.Empty })
                       .WithWarning(string.Empty, CouldNotCreateRecord));
            }

            // Add To Role
            await this.userManager.AddToRoleAsync(user, OwnerRoleName);

            // Referesh authorization since redirect requires the new role auth
            await this.signInManager.RefreshSignInAsync(user);

            // Write Image to DB
            await this.imageDbService.WriteToDatabasebAsync(imgUrl, imgPubId);

            return(this.RedirectToAction("Index", "Dashboard", new { area = ManagementArea })
                   .WithSuccess(string.Empty, RecordCreatedSuccessfully));
        }
        public async Task <IActionResult> CreateAsync(AdminListingCreateInputModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(model));
            }

            var imgResult = await this.imageService
                            .UploadImageAsync(model.Image);

            string imgUrl   = imgResult.SecureUri.AbsoluteUri;
            string imgPubId = imgResult.PublicId;

            var imageToWrite = new CloudImage
            {
                PictureUrl      = imgUrl,
                PicturePublicId = imgPubId,
            };

            var homeCreateServiceModel = new AdminHomeCreateServiceModel
            {
                Name        = model.Name,
                Description = model.Description,
                Address     = model.Address,
                Price       = model.Price,
                City        = model.City,
                Category    = model.Category,
                Status      = model.Status,
                Owner       = model.Owner,
                Image       = imageToWrite,
            };

            bool isCreated = await this.adminListingService.CreateListingAsync(homeCreateServiceModel);

            if (!isCreated)
            {
                return(this.RedirectToAction("Index", "Dashboard", new { area = AdminArea }).WithWarning(string.Empty, CouldNotCreateRecord));
            }

            var owner = await this.adminUserService.GetUserByUsername(model.Owner);

            if (!await this.userManager.IsInRoleAsync(owner, OwnerRoleName))
            {
                await this.userManager.AddToRoleAsync(owner, OwnerRoleName);
            }

            await this.imageDbService.WriteToDatabasebAsync(imgUrl, imgPubId);

            return(this.RedirectToAction("Index", "Dashboard", new { area = AdminArea })
                   .WithSuccess(string.Empty, RecordCreatedSuccessfully));
        }
        public async Task <int> WriteToDatabasebAsync(string imageUrl, string imagePublicId)
        {
            var image = new CloudImage
            {
                PictureUrl      = imageUrl,
                PicturePublicId = imagePublicId,
            };

            await this.context.CloudImages.AddAsync(image);

            await this.context.SaveChangesAsync();

            return(image.Id);
        }
    //Do something on image load failed
    private void DisplayMessageAndRetryToLoad(CloudImage cloudImage, CloudImageErrorType errorType, string message)
    {
        messageText.text = message;

        switch (errorType)
        {
        case CloudImageErrorType.CloudFail:
            cloudImage.RefreshImage();
            break;

        case CloudImageErrorType.LocalFail:
            cloudImage.RefreshImage();
            break;
        }
    }
Example #6
0
        private async Task UpdateCloudsInfoAsync(bool update)
        {
            if (CloudsList == null)
            {
                CloudsList = new ObservableCollection <CloudImage>();
            }

            CloudsList.Clear();

            /*
             * TimeSpan begin = new TimeSpan(DateTime.Now.Hour-1,0,0);
             * TimeSpan now = DateTime.Now.TimeOfDay;
             * for (TimeSpan span = begin; span < now; span = span.Add(new TimeSpan(0,5,0)))
             * {
             *  CloudImage gpsimage = null;
             *
             *  string gpscloud = "http://www2.buienradar.nl/gps/maps_00000_{0}.png";
             *  //if (i < 1000)
             *  gpsimage = new CloudImage(new Uri(string.Format(gpscloud, span.ToString("hhmm"))));
             *  //else
             *  //    image = new CloudImage(new Uri(string.Format(cloud, i)));
             *
             *  if (gpsimage != null)
             *      CloudsList.Add(gpsimage);
             * }
             */

            long filetime    = DateTime.Now.ToFileTime();
            long filetimeutc = DateTime.Now.ToFileTimeUtc();

            for (int i = 0; i < 25; i++)
            {
                CloudImage forecastimage = null;
                string     forecastcloud = "http://mijn.buienradar.nl/forecast/forecast_gps_{0}.png?{1}";

                forecastimage = new CloudImage(new Uri(string.Format(forecastcloud, i, filetime)));
                if (forecastimage != null)
                {
                    CloudsList.Add(forecastimage);
                }
            }
            //
            //}
        }
 private void BuscarImagen()
 {
     Banco.Path = CloudImage.BuscarImagen();
 }
 private void BuscarImagen()
 {
     Contratista.Path = CloudImage.BuscarImagen();
 }
Example #9
0
 private void BuscarImagen()
 {
     Material.Path = CloudImage.BuscarImagen();
 }
Example #10
0
 private void BuscarImagen()
 {
     Empresa.Path = CloudImage.BuscarImagen();
 }
 //Do something on image load failed
 private void OnSuccessLoad(CloudImage cloudImage)
 {
     messageText.text += cloudImage.mediaName + ": successfuly Loaded\n";
 }
        public async Task <IActionResult> EditPostAsync(OwnerListingEditInputModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(model));
            }

            var userId = this.userManager.GetUserId(this.User);
            var user   = await this.userManager.FindByIdAsync(userId);

            var    homeEditModel = new OwnerEditListingServiceModel();
            string imgUrl        = string.Empty;
            string imgPubId      = string.Empty;

            var files = this.HttpContext.Request.Form.Files;

            if (model.Image != null)
            {
                var imgResult = await this.imageService
                                .UploadImageAsync(model.Image);

                imgUrl   = imgResult.SecureUri.AbsoluteUri;
                imgPubId = imgResult.PublicId;

                var imageToWrite = new CloudImage
                {
                    PictureUrl      = imgUrl,
                    PicturePublicId = imgPubId,
                };

                homeEditModel = new OwnerEditListingServiceModel
                {
                    Id          = model.Id,
                    Name        = model.Name,
                    Description = model.Description,
                    Price       = model.Price,
                    Category    = model.Category,
                    Status      = model.Status,
                    Image       = imageToWrite,
                };
            }
            else
            {
                homeEditModel = new OwnerEditListingServiceModel
                {
                    Id          = model.Id,
                    Name        = model.Name,
                    Description = model.Description,
                    Price       = model.Price,
                    Category    = model.Category,
                    Status      = model.Status,
                };
            }

            bool isEdited = await this.listingService.EditListingAsync(homeEditModel);

            if (!isEdited)
            {
                return(this.RedirectToAction("Details", "Listings", new { id = model.Id, Area = ManagementArea })
                       .WithWarning(string.Empty, CouldNotUpdateRecord));
            }

            await this.imageDbService.WriteToDatabasebAsync(imgUrl, imgPubId);

            return(this.RedirectToAction("Details", "Listings", new { id = model.Id, area = ManagementArea })
                   .WithSuccess(string.Empty, RecordUpdatedSuccessfully));
        }
 public Login()
 {
     InitializeComponent();
     WebServices.InitializeCliente();
     CloudImage.Inicializar();
 }