private void btnAdd_Click(object sender, System.EventArgs e) { var addForm = new AddPhoto(_repository); addForm.ShowDialog(); Reload(); }
private void GetPhotoContentLocking(string imageRelativePath) { List <Organism> organismsOnPhoto; List <Person> peopleOnPhoto; lock (_photoContentContext) { (organismsOnPhoto, peopleOnPhoto) = AddPhoto.GetPhotoContent(_photoContentContext, imageRelativePath); } // Invoke viewing the results in the listboxes Invoke(new Action(() => { organismsOnPhotoListBox.DataSource = organismsOnPhoto; peopleOnPhotoListBox.DataSource = peopleOnPhoto; })); }
private void TryAddPhotoLocking(Photo tryPhoto) { string result; // Lock the DbContext until finished lock (_photoAddingContext) { result = AddPhoto.TryAddPhoto(_photoAddingContext, tryPhoto); } // Invoke showing result on the main thread Invoke(new Action(() => Global.ShowOnButtonForTwoSecs(result, "Přidat fotku do databáze", addPhotoToDbButton))); }
private void RemoveContentFromPhotoLocking(string imageRelativePath, int index, bool removingOrganism) { lock (_photoContentContext) { if (removingOrganism) { AddPhoto.RemoveOrganismFromPhoto(_photoContentContext, imageRelativePath, index); } else { AddPhoto.RemovePersonFromPhoto(_photoContentContext, imageRelativePath, index); } } }
public IActionResult AddPhoto([FromForm] AddPhoto model) { var userId = _http.HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier) ?? "00000000-0000-0000-0000-000000000000"; var authenticated = _http.HttpContext.User.Identity.IsAuthenticated; if (model == null) { return(BadRequest()); } if (model.UserId != userId || !authenticated || model.Photo == null) { return(BadRequest()); } var user = _db.Users.Find(userId); if (user == null) { return(BadRequest()); } Photo photo = new Photo { Id = Guid.NewGuid().ToString(), Date = Tools.GetLocalTime(user.TimeZone), HasPrice = model.HasPrice, Price = model.HasPrice ? model.Price : null, Title = model.Title, UserId = user.Id }; string fileName = $"yaillo-item-{photo.Id}.jpg"; photo.Url = Tools.SaveImageProduction(model.Photo, fileName); photo.PhotoName = fileName; _db.Photos.Add(photo); _db.SaveChanges(); return(Ok()); }
public IActionResult ProcessNewPhoto(AddPhoto add) { if (ActiveUser == null) { return(RedirectToAction("Login", "Home")); } if (ModelState.IsValid) { Photo photo = new Photo { user_id = ActiveUser.user_id, image = add.image, img_alt = add.img_alt, description = add.description }; _iContext.photos.Add(photo); _iContext.SaveChanges(); return(RedirectToAction("Dashboard", "Insta")); } return(View("AddNewPhoto")); }
private void TryAddContentToPhotoLocking(string[] names, bool addingOrganism, string imageRelativePath) { bool successfull; lock (_photoContentContext) { if (addingOrganism) { successfull = AddPhoto.TryAddOrganismToPhoto(_photoContentContext, imageRelativePath, names[0], names[1]); } else { successfull = AddPhoto.TryAddPersonToPhoto(_photoContentContext, imageRelativePath, names[0], names[2]); } } if (successfull) { if (addingOrganism) { Invoke(new Action(() => Global.ShowOnButtonForTwoSecs("Úspěšně přidáno!", "Přidat na fotku", addOrganismToPhotoButton))); } else { Invoke(new Action(() => Global.ShowOnButtonForTwoSecs("Úspěšně přidáno!", "Přidat na fotku", addPersonToPhotoButton))); } Task.Run(() => GetPhotoContentLocking(_showedImageRelativePath)); } else { if (addingOrganism) { Invoke(new Action(() => Global.ShowOnButtonForTwoSecs("Nešlo přidat.", "Přidat na fotku", addOrganismToPhotoButton))); } else { Invoke(new Action(() => Global.ShowOnButtonForTwoSecs("Nešlo přidat.", "Přidat na fotku", addPersonToPhotoButton))); } } }