public static Result <R1Employee> Get(this R1Employee from) { var result = Result <R1Employee> .Success(); try { using (var db = new RSMLubrizolDataModelDataContext()) { var row = from.Select(db); if (row == null) { return(result.Fail("R1Employee not found", "NotFound")); } result.Entity = row; } } catch (Exception e) { return(result.Set(ResultType.TechnicalError, e, "Get R1Employee failed. {0}", e.ToString())); } return(result); }
public static R1Employee Insert(this R1Employee entity, RSMLubrizolDataModelDataContext context) { context.Lubrizol_Employees.InsertOnSubmit(entity); context.SubmitChanges(); return(entity); }
public Result <R1Employee> GetEmployee(string id, bool internalLookup = false) { var result = Result <R1Employee> .Success(); if (internalLookup) { using (var context = new RSMLubrizolDataModelDataContext()) { var entity = context.Lubrizol_Employees.FirstOrDefault(x => x.EmployeeID == id); if (entity == null) { return(result.Fail(string.Format("Unable to locate Employee id ({0})", id), "NotFound")); } result.Entity = entity; } } else { var connectionName = ImportConfig.ConnectionString; if (string.IsNullOrWhiteSpace(connectionName)) { return(result.Fail(string.Format("Unable to reach the database for Employee id ({0})", id), "NotFound")); } using (var context = new LubrizolDataModelDataContext(connectionName)) { var entity = context.tblzILMDatas.FirstOrDefault(x => x.EmployeeID == id); if (entity == null) { return(result.Fail(string.Format("Unable to locate Employee id ({0})", id), "NotFound")); } var employee = new R1Employee(entity); result.Entity = employee; } } return(result); }
public static Result <R1Employee> Add(this R1Employee from) { var result = Result <R1Employee> .Success(); var exists = from.Get(); if (exists.Succeeded) { exists.Set(ResultType.Warning, "R1Employee already exists {0}", from.EmployeeID); return(exists); } try { using (var db = new RSMLubrizolDataModelDataContext()) { using (var transaction = new TransactionScope(TransactionScopeOption.Required, TransactionTimeout)) { var row = from.Insert(db); if (row == null) { return(result.Fail("Add R1Employee failed")); } result.Entity = row; transaction.Complete(); } } } catch (Exception e) { return(result.Set(ResultType.TechnicalError, e, "Add R1Employee failed {0}", e.ToString())); } return(result); }
public static Result <R1Employee> Update(this R1Employee from, ModelMapper <R1Employee> mapper = null) { var result = Result <R1Employee> .Success(); try { using (var db = new RSMLubrizolDataModelDataContext()) { using (var transaction = new TransactionScope(TransactionScopeOption.Required, TransactionTimeout)) { var row = DataExtensions.Select(from, db); if (row == null) { return(result.Fail("Update R1Employee failed")); } if (!row.SameAs(from)) { if (mapper != null) { mapper.MapProperties(from, row); } else { row.FirstName = from.FirstName; row.LastName = from.LastName; row.MiddleName = from.MiddleName; row.Company = from.Company; row.Country = from.Country; row.Department = from.Department; row.DepartmentName = from.DepartmentName; row.Division = from.Division; row.EmployeeClassDesc = from.EmployeeClassDesc; row.EmployeeStatus = from.EmployeeStatus; row.EmployeeStatusDesc = from.EmployeeStatusDesc; row.Initials = from.Initials; row.JobDescr = from.JobDescr; row.LastLoadDate = from.LastLoadDate; row.LegalEntity = from.LegalEntity; row.Name = from.Name; row.PhysicalLocation = from.PhysicalLocation; row.PhysicalLocationName = from.PhysicalLocationName; row.ReportingLocation = from.ReportingLocation; row.ReportingLocationName = from.ReportingLocationName; row.SupervisorID = from.SupervisorID; row.SupervisorInitials = from.SupervisorInitials; row.SupervisorName = from.SupervisorName; } row.LastUpdated = DateTime.Now; db.SubmitChanges(); transaction.Complete(); result.Entity = row; } else { result.Entity = from; } } } } catch (Exception e) { return(result.Set(ResultType.TechnicalError, e, "Update R1Employee failed {0}", e.ToString())); } return(result); }
public static R1Employee Select(this R1Employee entity, RSMLubrizolDataModelDataContext context) { return(context.Lubrizol_Employees.FirstOrDefault(x => x.EmployeeID == entity.EmployeeID)); }