public static void UpdateClaim(Claim claim) { using (FinanceDBContext db = new FinanceDBContext()) { try { Claim oldClaim = db.Claims.SingleOrDefault(c => c.ClaimId == claim.ClaimId); if (oldClaim != null) { oldClaim.ClaimantLiable = claim.ClaimantLiable; oldClaim.ClaimDate = claim.ClaimDate; oldClaim.EmployeeId = claim.EmployeeId; oldClaim.ReferenceNum = claim.ReferenceNum; oldClaim.RequestType = claim.RequestType; oldClaim.StatusDate = claim.StatusDate; oldClaim.WorkLocation = claim.WorkLocation; UpdateEmployee(claim.Employee); db.SaveChanges(); } else { InsertEmployee(claim.Employee); InsertClaim(claim); } } catch (Exception ex) { Console.WriteLine(ex.Message); } } }
public bool Save() { if (db.SaveChanges() > 0) { return(true); } return(false); }
public static bool InsertEmployee(Employee employee) { bool result = false; using (var db = new FinanceDBContext()) { employee.Center = null; db.Employees.Add(employee); int numRows = db.SaveChanges(); if (numRows > 0) { result = true; } } return(result); }
public static bool InsertClaim(Claim claim) { bool result = false; using (var db = new FinanceDBContext()) { claim.EmployeeId = claim.Employee.EmployeeId; claim.Employee = null; db.Claims.Add(claim); int numRows = db.SaveChanges(); if (numRows > 0) { result = true; } } return(result); }
public static bool Insert <T>(T item) where T : class { bool result = false; using (FinanceDBContext context = new FinanceDBContext()) { try { context.Set <T>().Add(item); int numRows = context.SaveChanges(); result = numRows > 0 ? true : false; } catch (Exception ex) { result = false; Console.WriteLine(ex.Message); } } return(result); }
public static void UpdateEmployee(Employee employee) { using (FinanceDBContext db = new FinanceDBContext()) { try { Employee oldEmployee = db.Employees.SingleOrDefault(e => e.EmployeeId == employee.EmployeeId); if (oldEmployee != null) { oldEmployee.EmployeeId = employee.EmployeeId; oldEmployee.CenterId = employee.CenterId; oldEmployee.FirstName = employee.FirstName; oldEmployee.LastName = employee.LastName; oldEmployee.SSN = employee.SSN; db.SaveChanges(); } } catch (Exception ex) { Console.WriteLine(ex.Message); } } }
public bool CreateUser(UserVM userVM) { using (FinanceDBContext _context = new FinanceDBContext()) { User newUser = new User { Email = userVM.Email, FirstName = userVM.FirstName, LastName = userVM.LastName, Id = 0, Password = userVM.Password, PhoneNo = userVM.PhoneNo, CreatedDate = DateTime.Now, IsDeleted = false, ModifiedDate = DateTime.Now, UserName = userVM.Email }; _context.User.Add(newUser); _context.SaveChanges(); return(true); } }