public HomePageImageOutput(HomePageImage image)
 {
     this.Id         = image.Id;
     this.Width      = image.Width;
     this.Height     = image.Height;
     this.ImageUrl   = image.ImageUrl;
     this.NaviateUrl = image.NavigateUrl;
     this.Localized  = image.Localized.Select(l => new LocalizedHomePageImageOutput(l)).ToArray();
 }
Exemplo n.º 2
0
        public HomePageImageOutput Create()
        {
            var httpRequest = HttpContext.Current.Request;

            var formData = httpRequest.Form["image"];

            if (formData.IsNullOrEmpty())
            {
                throw new Exception("missing image data");
            }

            if (httpRequest.Files.Count == 0)
            {
                throw new Exception("missing image file");
            }

            var input = JsonConvert.DeserializeObject <HomePageImageInput>(formData);
            var image = new HomePageImage
            {
                Id          = input.Id,
                Width       = input.Width,
                Height      = input.Height,
                NavigateUrl = input.NaviateUrl,
                Localized   = input.Localized.Select(l => new LocalizedHomePageImage
                {
                    HomePageImageId = input.Id,
                    LanguageCode    = l.LanguageCode,
                    Title           = l.Title,
                    Description     = l.Descrption
                }).ToList()
            };

            var file      = httpRequest.Files[0];
            var extension = new System.IO.FileInfo(file.FileName).Extension;
            var imageUrl  = "/UploadImages/" + Guid.NewGuid().ToString() + extension;
            var imageFile = Image.FromStream(file.InputStream);

            imageFile.Save(HttpContext.Current.Server.MapPath("~" + imageUrl));
            image.ImageUrl = imageUrl;

            using (var dbContext = new AllureContext())
            {
                dbContext.Set <HomePageImage>().Add(image);
                dbContext.SaveChanges();
            }

            return(Id(image.Id));
        }
Exemplo n.º 3
0
 //Metoda sprawdzająca czy strona glowna sie poprawnie zaladowala
 public override bool IsValid() => StartButton.Displayed && HomePageImage.GetAttributeSrc() != null && Footer.Text.Equals(Configurator3DConsts.FOOTER) && Header.Text.Equals(Configurator3DConsts.HEADER);