public async Task <IActionResult> Edit(int id, [Bind("Id,AuthorEmail,Image,UploadedImageURL,AppliedTemplate,ConvertedImageURL,BluredImageURL")] Muck muck) { if (id != muck.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(muck); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MuckExists(muck.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(muck)); }
public async Task <IActionResult> Create([Bind("Id,AuthorEmail,Image,UploadedImageURL,AppliedTemplate,ConvertedImageURL,BluredImageURL")] Muck muck) { if (ModelState.IsValid) { _context.Add(muck); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(muck)); }
// finds all muck in scene and adds them to list. private void MuckInstantiate() { muck = new List <Muck>(Muck.FindObjectsOfType <Muck>()); muck.Remove(this); if (muck.Count == 0) { isMuck = false; } else { isMuck = true; distances = new List <float>(); for (int i = 0; i < muck.Count; i++) { distances.Add(0); } } }
public async Task <IActionResult> Post(List <IFormFile> files) { int tmpltId = 0; if (!string.IsNullOrWhiteSpace(Request.Form["tmpltId"])) { int.TryParse(Request.Form["tmpltId"], out tmpltId); } var Templates = new Dictionary <string, string>() { { "Zombie", "2187" }, }; long size = files.Sum(f => f.Length); // full path to file in temp location if (1 == files.Count) { var formFile = files[0]; var filePath = Path.GetTempFileName() + Path.GetExtension(formFile.FileName); if (formFile.Length > 0) { using (var stream = new FileStream(filePath, FileMode.Create)) { await formFile.CopyToAsync(stream); } } string uploadedImageUrl; using (var uploadImageWebClient = new WebClient()) { byte[] responseArray = uploadImageWebClient.UploadFile(c_api_upload_endpoint, filePath); uploadedImageUrl = Encoding.UTF8.GetString(responseArray); } string transformedImageUrl; using (var httpClient = new HttpClient()) { var values = new Dictionary <string, string> { { "image_url[1]", uploadedImageUrl }, { "template_name", Templates.ToList()[tmpltId].Value } }; var content = new FormUrlEncodedContent(values); var response = await httpClient.PostAsync(c_api_photolab_tmplt_endpoint, content); transformedImageUrl = await response.Content.ReadAsStringAsync(); } string bluredImageUrl; using (var httpClient = new HttpClient()) { var values = new Dictionary <string, string> { { "image_url[1]", transformedImageUrl }, //{ "template_name", "DD406536-1D2F-B0D4-7D0F-51828625B52D" /* blur1 */ } { "template_name", "BC75E995-B4CF-7854-E165-C734EEC2A775" /* blur2 */ } }; var content = new FormUrlEncodedContent(values); var response = await httpClient.PostAsync(c_api_custom_tmplt_endpoint, content); bluredImageUrl = await response.Content.ReadAsStringAsync(); } Muck muck = new Muck { AppliedTemplate = Templates.ToList()[tmpltId].Key, AuthorEmail = User.Identity.Name, UploadedImageURL = uploadedImageUrl, ConvertedImageURL = transformedImageUrl, BluredImageURL = bluredImageUrl, Image = System.IO.File.ReadAllBytes(filePath) }; { _context.Muck.Add(muck); _context.SaveChanges(); } return(RedirectToAction("Details", "Mucks", new { id = muck.Id })); //Response.Redirect("~/Mucks/Details/" + muck.Id,); //return Ok(new { count = files.Count, size, filePath, uploadedImageUrl, transformedImageUrl, bluredImageUrl, insertedId = muck.Id }); } else { return(Ok(new { count = 0 })); } // process uploaded files // Don't rely on or trust the FileName property without validation. }