public async Task <IActionResult> Edit(int?id, [Bind("Id,Name,Desc")] ConfigurationValue configurationValue) { if (id != configurationValue.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(configurationValue); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ConfigurationValueExists(configurationValue.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(configurationValue)); }
public async Task <IActionResult> Put([FromBody] Person person) { Db.Update(person); await Db.SaveChangesAsync(); return(Ok(person)); }
public IActionResult EditFocus(int id, [Bind("FocusId, FocusType")] AddFocusViewModel addFocusViewModel) { var findFocus = _repository.GetFocusById(id); findFocus.FocusType = addFocusViewModel.FocusType; if (ModelState.IsValid) { try { _context.Update(findFocus); _context.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (findFocus == null) { return(NotFound()); } else { throw; } } TempData["editFocusMessage"] = $"{findFocus.FocusType} has been saved"; return(View(addFocusViewModel)); } return(View(addFocusViewModel)); }
public async Task <IActionResult> Edit(int id, [Bind("ClienteId,RIF,RazonSocial")] Cliente cliente) { if (id != cliente.ClienteId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(cliente); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ClienteExists(cliente.ClienteId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(cliente)); }
public async Task <IActionResult> Edit(int id, [Bind("Type,Description,IsActive,IsDeleted,DeletedOn,Id,CreatedOn,ModifiedOn")] QuantityType quantityType) { if (id != quantityType.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(quantityType); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!QuantityTypeExists(quantityType.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(quantityType)); }
/// <summary> /// Updates the Companies table with the changes made. /// </summary> /// <param name="compToEdit"></param> /// <returns></returns> public async Task EditCompany(Companies compToEdit) { try { _context.Update(compToEdit); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException e) { Console.WriteLine(e.Message); throw; } }
public IActionResult EditEmployee(Employee updatedEmployee) { Employee dbEmployee = _context.Employees.Find(updatedEmployee.Id); if (ModelState.IsValid) { dbEmployee.FirstName = updatedEmployee.FirstName; dbEmployee.LastName = updatedEmployee.LastName; dbEmployee.Email = updatedEmployee.Email; _context.Entry(dbEmployee).State = Microsoft.EntityFrameworkCore.EntityState.Modified; _context.Update(dbEmployee); _context.SaveChanges(); } return(RedirectToAction("Index")); }
public async Task AssignUserToManager(int userId, int managerId) { var userRecord = await _rep.GetUserById(userId); var managerRecord = await _rep.GetUserById(managerId); Check.Value(userRecord).NotNull(ErrorMessages.NoUserWithIdMsg(userId)); Check.Value(managerRecord).NotNull(ErrorMessages.NoUserWithIdMsg(managerId)); var user = await _rep.GetUserById(userId); user.ManagerId = managerId; _dbContext.Update(user); await _dbContext.SaveChangesAsync(); }
public IActionResult EditDepartment(Department updatedDepartment) { Department dbDepartment = _context.Departments.Find(updatedDepartment.Id); if (ModelState.IsValid) { dbDepartment.Name = updatedDepartment.Name; dbDepartment.Location = updatedDepartment.Location; dbDepartment.Type = updatedDepartment.Type; dbDepartment.Budget = updatedDepartment.Budget; _context.Entry(dbDepartment).State = Microsoft.EntityFrameworkCore.EntityState.Modified; _context.Update(dbDepartment); _context.SaveChanges(); } return(RedirectToAction("Index")); }
public IActionResult UpdateDepartment(Department newDepartment) { if (ModelState.IsValid) { Department oldDepartment = _context.Departments.Find(newDepartment.DepartmentId); oldDepartment.Name = newDepartment.Name; oldDepartment.Location = newDepartment.Location; oldDepartment.Budget = newDepartment.Budget; oldDepartment.Type = newDepartment.Type; _context.Entry(oldDepartment).State = Microsoft.EntityFrameworkCore.EntityState.Modified; _context.Update(oldDepartment); _context.SaveChanges(); } return(RedirectToAction("DepartmentIndex")); }
public IActionResult Edit(int?id, EmployeeViewModel model) { if (id == null) { return(NotFound()); } var employee = _db.Employees.FirstOrDefault(x => x.Id == id); employee.Name = model.Name; employee.Position = model.Position; employee.PositionEnum = model.PositionEnum; _db.Update(employee); _db.SaveChanges(); return(RedirectToAction("Index")); }
public async Task <IActionResult> EditProfile(RegistrationRequestModel model, int Id) { try { bool mailChanged = false; var base64 = ""; if (model.Avatar != null) { var tempImage = System.Drawing.Image.FromStream(model.Avatar.OpenReadStream()); var result = Utility.ResizeImage(tempImage, 300, 300); base64 = string.Format("data:image/jpg; base64, {0}", Convert.ToBase64String(Utility.ImageToByte2(result))); model.UserImage = base64; } var user = _context.RegistrationRequests.FirstOrDefault(a => a.Id == Id); user.Name = string.IsNullOrEmpty(model.Name) ? user.Name : model.Name; user.SurName = string.IsNullOrEmpty(model.SurName) ? user.SurName : model.SurName; user.Phone = string.IsNullOrEmpty(model.Phone) ? user.Phone : model.Phone; user.About = string.IsNullOrEmpty(model.About) ? user.About : model.About; user.Image = string.IsNullOrEmpty(model.UserImage) ? user.Image : model.UserImage; IdentityUser currentUser = await _userManager.FindByEmailAsync(user.Email); if (!string.IsNullOrEmpty(model.Password)) { await _userManager.ChangePasswordAsync(currentUser, user.Password, model.Password); user.Password = model.Password; } if (!model.Email.Equals(user.Email)) { mailChanged = true; string token = await _userManager.GenerateChangeEmailTokenAsync(currentUser, model.Email); await _userManager.ChangeEmailAsync(currentUser, model.Email, token); await _userManager.SetUserNameAsync(currentUser, model.Email); user.Email = model.Email; } _context.Update(user); await _context.SaveChangesAsync(); if (mailChanged) { return(RedirectToAction("SignOut")); } if (User.IsInRole("Admin")) { return(RedirectToAction("UserRequestIndex")); } return(RedirectToAction("Profile", new { UserName = user.Email })); } catch (Exception ex) { string strMsg = "Something Went Wrong or not all required fileds are filled try again"; string script = "<script language=\"javascript\" type=\"text/javascript\">alert('" + strMsg + "'); window.location='EditProfile'; </script>"; await Response.WriteAsync(script); return(View(model)); } }
public Task MergeAsync <T>(T entry) where T : EntityBase { return(Task.Run(() => context.Update(entry))); }