public bool Update(Position position) { try { List <Position> positions = _mgmtContext.Position.Where(p => p.Id != position.Id && p.Position_Type == position.Position_Type).ToList(); if (positions.Count() == 1) { return(false); } _mgmtContext.Update(position); _mgmtContext.SaveChangesAsync(); return(true); } catch (InvalidOperationException ioe) { Debug.WriteLine("Message " + ioe.Message); return(false); } catch (DbUpdateConcurrencyException dce) { Debug.WriteLine("Message " + dce.Message); return(false); } }
public async Task <IActionResult> Edit(int id, [Bind("Cus_ID,Cus_lname,Cus_fname,Cus_phone,Cus_email,Cus_street,Cus_city,Cus_pro,Cus_country,Inv_ID")] Customer customer) { if (id != customer.Cus_ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(customer); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CustomerExists(customer.Cus_ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["Inv_ID"] = new SelectList(_context.Invoices, "Inv_ID", "Inv_ID", customer.Inv_ID); return(View(customer)); }
public async Task <IActionResult> Edit(int id, [Bind("MemberID,MemberName,InductionDate,Age")] Member member) { if (id != member.MemberID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(member); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MemberExists(member.MemberID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(member)); }
public async Task <IActionResult> Edit(int id, [Bind("Emp_ID,Emp_lname,Emp_fname,Emp_phone,Emp_email,Cus_ID")] Employee employee) { if (id != employee.Emp_ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(employee); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EmployeeExists(employee.Emp_ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["Cus_ID"] = new SelectList(_context.Customers, "Cus_ID", "Cus_ID", employee.Cus_ID); return(View(employee)); }
public async Task <IActionResult> Edit(int id, [Bind("Inv_ID,Inv_des,Inv_amount,Inv_date")] Invoice invoice) { if (id != invoice.Inv_ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(invoice); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!InvoiceExists(invoice.Inv_ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(invoice)); }
public bool Update(SubCompany subCompany) { try { _mgmtContext.Update(subCompany); _mgmtContext.SaveChangesAsync(); return(true); } catch (InvalidOperationException ioe) { Debug.WriteLine("Message " + ioe.Message); return(false); } catch (DbUpdateConcurrencyException dce) { Debug.WriteLine("Message " + dce.Message); return(false); } }
public bool Update(Company company) { try { _mgmtContext.Update(company); _mgmtContext.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (GetCompany(company.Id) == null) { return(false); } else { throw; } } return(true); }
public bool Update(EmployeeViewModel employeeViewModel) { try { HashSet <string> addressSet = new HashSet <string>(); HashSet <string> phoneNumberSet = new HashSet <string>(); Employee employee = _mgmtContext.Employee.Where(e => e._EmpId == employeeViewModel.Id).ToList()[0]; employee.Name = employeeViewModel.EmployeeName; employee.Joined_Date = employeeViewModel.Joined_Date; employee.Salary = employeeViewModel.Salary; employee.SubCompany = _mgmtContext.SubCompany.Where(s => s.Id == employeeViewModel.SubCompanyId).ToList()[0]; employee.Positions = _mgmtContext.Position.Where(p => p.Id == employeeViewModel.PositionId).ToList()[0]; List <Address> addresses = _mgmtContext.Address.Where(a => a.Employee._EmpId == employeeViewModel.Id).ToList(); List <Phone> phones = _mgmtContext.Phone.Where(p => p.Employee._EmpId == employeeViewModel.Id).ToList(); phoneNumberSet.Add(employeeViewModel._PhoneNumber); addressSet.Add(employeeViewModel._Address); //checking phone numbers list is not null && empty //adding only unique phone number only if (employeeViewModel.PhoneNumbers != null && employeeViewModel.PhoneNumbers.Count() > 0) { foreach (string addr in employeeViewModel.PhoneNumbers) { if (!String.IsNullOrEmpty(addr)) { phoneNumberSet.Add(addr); } } } //checking address list is not null && empty //adding unique address only if (employeeViewModel.Addresses != null && employeeViewModel.Addresses.Count() > 0) { foreach (string phn in employeeViewModel.Addresses) { if (!String.IsNullOrEmpty(phn)) { addressSet.Add(phn); } } } int i = 0; try { foreach (string phn in phoneNumberSet) { phones[i].Phone_Number = phn; i++; } if (phoneNumberSet.Count() < phones.Count()) { phones.RemoveRange(i, phones.Count() - i); } } catch (ArgumentOutOfRangeException aor) { Console.WriteLine("Message " + aor.Message); if (phoneNumberSet.Count() > phones.Count()) { while (i < phoneNumberSet.Count()) { phones.Add(new Phone { Phone_Number = phoneNumberSet.ElementAt(i), Employee = employee }); i++; } } } employee.Phones = phones; int j = 0; try { foreach (string addr in addressSet) { addresses[j].Location = addr; j++; } if (addressSet.Count() < addresses.Count()) { addresses.RemoveRange(j, addresses.Count() - j); } } catch (ArgumentOutOfRangeException aor) { Console.WriteLine("Message " + aor.Message); if (addressSet.Count() > addresses.Count()) { while (j < addressSet.Count()) { addresses.Add(new Address { Location = addressSet.ElementAt(j), Employee = employee }); j++; } } } employee.Addresses = addresses; _mgmtContext.Update(employee); _mgmtContext.SaveChanges(); return(true); } catch (Exception ex) { Console.WriteLine("Message at the end " + ex.Message); return(false); } }