public async Task<JObject> SavePicture(CreateModel model) { var bytes = await _client.GetByteArrayAsync(model.Url); var box = _packer.PackBox(bytes, Identity.Name, model.Facets); _attic.AddBox(box); await _dropbox.Delete(Identity.AccessToken, model.File); var metadata = await _dropbox.GetMetaData(Identity.AccessToken); var list = GetFileListFromMetaData(metadata); var json = new JObject(); json.Add("total", list.Count); if (list.Count > 0) { var media = await _dropbox.GetMedia(Identity.AccessToken, list[0]); var url = GetUrlFromMedia(media); json.Add("width", Constants.IMG_WIDTH); json.Add("height", Constants.IMG_HEIGHT); json.Add("file", list[0]); json.Add("url", url); json.Add("src", string.Format(Constants.GET_PICTURE_URL_FORMAT, url)); json.Add("resizedSrc", string.Format(Constants.GET_RESIZE_PICTURE_URL_FORMAT, url, Constants.IMG_WIDTH, Constants.IMG_HEIGHT)); } return json; }
public async Task<ActionResult> Index() { var metadata = await _dropbox.GetMetaData(Identity.AccessToken); var facets = Identity.Facets; var list = GetFileListFromMetaData(metadata); var model = new CreateModel { Facets = facets, TotalFileCount = 0, Url = "", ResizedHeight = Constants.IMG_HEIGHT, ResizedWidth = Constants.IMG_WIDTH, File = "" }; if (list.Count > 0) { var media = await _dropbox.GetMedia(Identity.AccessToken, list[0]); var url = GetUrlFromMedia(media); model.TotalFileCount = list.Count(); model.Url = url; model.File = list[0]; } ViewBag.IsMobile = Identity.IsMobile; return View(model); }