예제 #1
0
        public static R1Employee Insert(this R1Employee entity, RSMLubrizolDataModelDataContext context)
        {
            context.Lubrizol_Employees.InsertOnSubmit(entity);

            context.SubmitChanges();

            return(entity);
        }
예제 #2
0
        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);
        }