public virtual async Task UpdateAsync(TEntity entity) { ArgumentGuard.NotNull(entity, nameof(entity)); _dbContext.Set <TEntity>().Attach(entity); _dbContext.Entry(entity).State = EntityState.Modified; await _dbContext.SaveChangesAsync(); }
public async Task <IActionResult> PutSlot(int id, Slot slot) { if (id != slot.SlotId) { return(BadRequest()); } _context.Entry(slot).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SlotExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutEducationInfo(long id, EducationInfo educationInfo) { if (id != educationInfo.Id) { return(BadRequest()); } _context.Entry(educationInfo).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!educationInfoExist(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutWorkingExperience(long id, WorkingExperience workingExperience) { if (id != workingExperience.Id) { return(BadRequest()); } _context.Entry(workingExperience).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!workingExperienceExist(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutFamilyData(long id, FamilyData familyData) { if (id != familyData.Id) { return(BadRequest()); } _context.Entry(familyData).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!accountProfileExist(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutParking(int id, Parking parking) { if (id != parking.ParkingId) { return(BadRequest()); } _context.Entry(parking).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ParkingExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <User> RegisterAccess(User user) { _context.Users.Attach(user); _context.Entry(user).Property(x => x.LastLogin).IsModified = true; await _context.SaveChangesAsync(); return(user); }
public void UpdateAccount(Account account) { using (var context = new AuthDbContext()) { context.Entry(account).State = EntityState.Modified; context.SaveChanges(); } }
public IActionResult Edit(Playlist playlist) { try { ClaimsPrincipal currentUser = this.User; var currentUserID = currentUser.FindFirst(ClaimTypes.NameIdentifier).Value; var renamedPlaylist = _context.Playlist.Find(playlist.PlaylistId); renamedPlaylist.Name = Request.Form["playlistName"]; if (renamedPlaylist.userID == currentUserID) { _context.Entry(renamedPlaylist).State = EntityState.Modified; _context.SaveChanges(); } } catch { } Index(); return(View("Index")); }
public void UpdateCategory(Category category) { _dbContext.Entry(category).State = EntityState.Modified; Save(); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Name,LatinName,Description,Kind,Type,Water,Light,ProductDate,Trade, Delivery,UserId,PublisherName")] Product product, IFormFile Picture, IFormFile PictureTwo, IFormFile PictureThree) { var pp = _context.Products.FirstOrDefault(p => p.Id.Equals(id)); // Avoid overriding the EF tracking by first finding the right product, //setting the image variable and detach the tracked product before updating the newer tracked product later on byte[] image = pp.Picture; if (pp != null) { // detach _context.Entry(pp).State = EntityState.Detached; } //if (id != product.Id) //{ // return NotFound(); //} //byte[] streamOutput; //string output = ""; //try //{ // using (MemoryStream ms = new MemoryStream()) // { // Picture.CopyTo(ms); // streamOutput = ms.ToArray(); // } // foreach (byte b in streamOutput) // { // string number = Convert.ToString(Convert.ToInt32(b)); // while (number.Length < 3) // number = "0" + number; // output += number; // } //} //catch (NullReferenceException) //{ // output = ""; //} ////This clause is supposed to check if the only error is an empty Picture field, since I (Mattias) can't find a way to get rid of it. Any other error should still trigger the clause. //if (ModelState["Picture"].RawValue == null && ModelState.ErrorCount == 1) //{ // try // { // product.Picture = output; // _context.Update(product); // await _context.SaveChangesAsync(); // } // catch (DbUpdateConcurrencyException) // { // if (!ProductExists(product.Id)) // { // return NotFound(); // } // else // { // throw; // } // } // return RedirectToAction(nameof(Index)); //} if (id != product.Id) { return(NotFound()); } if (ModelState.IsValid) { if (Picture != null) { if (Picture.Length > 0) //Convert Image to byte and save to database { byte[] p1 = null; using (var fs1 = Picture.OpenReadStream()) { using (var ms1 = new MemoryStream()) { fs1.CopyTo(ms1); p1 = ms1.ToArray(); } product.Picture = p1; } } } if (Picture == null) { product.Picture = image; } if (PictureTwo != null) { if (PictureTwo.Length > 0) //Convert Image to byte and save to database { byte[] p2 = null; using (var fs2 = PictureTwo.OpenReadStream()) { using (var ms2 = new MemoryStream()) { fs2.CopyTo(ms2); p2 = ms2.ToArray(); } product.PictureTwo = p2; } } } if (PictureTwo == null) { product.PictureTwo = image; } if (PictureThree != null) { if (PictureThree.Length > 0) //Convert Image to byte and save to database { byte[] p3 = null; using (var fs3 = PictureThree.OpenReadStream()) { using (var ms3 = new MemoryStream()) { fs3.CopyTo(ms3); p3 = ms3.ToArray(); } product.PictureThree = p3; } } } if (PictureTwo == null) { product.PictureTwo = image; } _context.Update(product); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(product)); }
public void UpdateProduct(Product product) { _dbContext.Entry(product).State = EntityState.Modified; Save(); }
public void UpdateCountry(Country country) { _dbContext.Entry(country).State = EntityState.Modified; Save(); }