public void Update(AppObj entity) { try { if (GetById(entity.Id) != null) { _context.Update(entity); _context.SaveChanges(); _logger.LogInformation(LoggingEvents.UpdateItem, "App updated: ID: {ID}, Login: {LOGIN}, FirstName: {FIRSTNAME}, LastName: {LASTNAME}, MiddleName: {MIDDLENAME}, Password: {PASSWORD}", entity.Id ); } else { _logger.LogInformation(LoggingEvents.UpdateItemNotFound, "App id: {ID}", entity.Id); throw new KeyNotFoundException(); } } catch (Exception ex) { _logger.LogError(LoggingEvents.UpdateItem, ex, "Error updating user ID: {ID}, Login: {LOGIN}, FirstName: {FIRSTNAME}, LastName: {LASTNAME}, MiddleName: {MIDDLENAME}, Password: {PASSWORD}", entity.Id ); throw; } }
public async Task <IActionResult> Edit(AllAppsAndProject all) { Project temp = all.project; if (all.selected != null && all.selectedInst != null) { List <int> list = all.selected.Split(',').Select(Int32.Parse).ToList(); List <int> numlist = all.selectedInst.Split(',').Select(Int32.Parse).ToList(); temp.projectApps = new List <ProjectApp>(); foreach (int current in list) { temp.projectApps.Add(new ProjectApp() { appId = current, instances = numlist[list.IndexOf(current)] }); } if (ModelState.IsValid) { List <ProjectApp> pal = _context.ProjectAppDbSet.Where(m => m.projectId == temp.Id).ToList(); foreach (ProjectApp current in pal) { _context.ProjectAppDbSet.Remove(current); } _context.Update(temp); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } } all.apps = _context.AppObjDbSet.ToList(); return(View(all)); }
public async Task <IActionResult> Edit(int id, [Bind("name, flag, load")] AppObj appData, List <AppParameters> appParameters) { if (ModelState.IsValid) { try { appData.Id = id; appData.AppParameters = appParameters; var param = _context.AppParameterDbSet.Where(e => e.AppId == appData.Id); foreach (AppParameters current in param) { _context.AppParameterDbSet.Remove(current); } _context.Update(appData); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AppDataExists(appData.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } appData.AppParameters = appParameters; return(View(appData)); }