public HttpResponseMessage Mockup([FromBody] PictureRequestData data) { var product = data.Product; var surface = product.Surfaces.First(); var mockupContainer = surface.Mockup.UnderContainers[0]; var mockupUrl = data.PicturePath; var filepath = System.Web.Hosting.HostingEnvironment.MapPath(mockupUrl); var newSource = new ImageItem.ImageSource(new FileInfo(filepath), 0); if (mockupContainer.Items.Count > 0) { ((ImageItem)mockupContainer.Items[0]).Source = newSource; } else { mockupContainer.Items.Add(new ImageItem(newSource)); } var productJson = JsonConvert.SerializeObject(product, _productJsonConverter); return(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(productJson, Encoding.UTF8, "application/json") }); }
public HttpResponseMessage Picture([FromBody] PictureRequestData data) { var product = data.Product; var surface = product.Surfaces.First(); var filePath = System.Web.Hosting.HostingEnvironment.MapPath(data.PicturePath); var newSource = new ImageItem.ImageSource(new FileInfo(filePath), 0); var newContent = new ImageItem(newSource, null, surface.Width, surface.Height); var imageItemHandler = _itemHandlerFactory.CreateItemHandler(newContent) as ImageItemHandler; var bgItem = surface.BgContainer.Items[0] as PlaceholderItem; bgItem.Content = newContent; bgItem.FillColor = new RgbColor(); imageItemHandler?.UpdateRectangle(false, bgItem.ContentResizeMode, bgItem, newContent.SourceRectangle.Width, newContent.SourceRectangle.Height); var productJson = JsonConvert.SerializeObject(product, _productJsonConverter); return(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(productJson, Encoding.UTF8, "application/json") }); }