예제 #1
0
        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);
        }
예제 #2
0
 public static bool SameAs(this R1Employee from, R1Employee to)
 {
     try
     {
         return(to.FirstName == from.FirstName &&
                to.LastName == from.LastName &&
                to.MiddleName == from.MiddleName &&
                to.Company == from.Company &&
                to.Country == from.Country &&
                to.Department == from.Department &&
                to.DepartmentName == from.DepartmentName &&
                to.Division == from.Division &&
                to.EmployeeClassDesc == from.EmployeeClassDesc &&
                to.EmployeeStatus == from.EmployeeStatus &&
                to.EmployeeStatusDesc == from.EmployeeStatusDesc &&
                to.Initials == from.Initials &&
                to.JobDescr == from.JobDescr &&
                to.LegalEntity == from.LegalEntity &&
                to.Name == from.Name &&
                to.PhysicalLocation == from.PhysicalLocation &&
                to.PhysicalLocationName == from.PhysicalLocationName &&
                to.ReportingLocation == from.ReportingLocation &&
                to.ReportingLocationName == from.ReportingLocationName &&
                to.SupervisorID == from.SupervisorID &&
                to.SupervisorInitials == from.SupervisorInitials &&
                to.SupervisorName == from.SupervisorName);
     }
     catch (Exception e)
     {
         return(false);
     }
 }
예제 #3
0
        public static R1Employee Insert(this R1Employee entity, RSMLubrizolDataModelDataContext context)
        {
            context.Lubrizol_Employees.InsertOnSubmit(entity);

            context.SubmitChanges();

            return(entity);
        }
예제 #4
0
        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);
        }
예제 #5
0
        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);
        }
예제 #6
0
 partial void DeleteLubrizol_Employee(Lubrizol_Employee instance);
예제 #7
0
 partial void UpdateLubrizol_Employee(Lubrizol_Employee instance);
예제 #8
0
 partial void InsertLubrizol_Employee(Lubrizol_Employee instance);
예제 #9
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);
        }
예제 #10
0
        private Result <Person> ExportPicture(Person entity, R1Employee employee)
        {
            var results = new Result <Person>();

            if (entity == null)
            {
                return(results.Merge(new Result <Person>(ResultType.ValidationError, "Missing Person Data")));
            }

            if (employee == null)
            {
                return(results.Merge(new Result <Person>(ResultType.ValidationError, "Missing Employee Data")));
            }

            if (entity.Image == null)
            {
                return(results.Merge(new Result <Person>(ResultType.ValidationError, "Missing Person Image")));
            }

            var libraryName = (employee.EmployeeStatus.Equals('T') || employee.EmployeeStatus.Equals('R'))
                                                ? ExportConfig.InactiveEmployeeLibrary.TrimEnd('/')
                                                : ExportConfig.ActiveEmployeeLibrary.TrimEnd('/');

            var destinationFile = string.Format("{0}/{1}/{2}.jpg", ExportConfig.Link.TrimEnd('/'), Uri.EscapeDataString(libraryName), Uri.EscapeDataString(employee.Initials.Trim()));
            var destinationUrls = new[] { destinationFile };

            #region SharePoint Fields
            //Author  Single line of text
            //Comments  Multiple lines of text Image
            //Company  Single line of text Image
            //Copyright  Single line of text Image
            //Country  Single line of text Image
            //Date Picture Taken  Date and Time Image
            //Department  Single line of text Image
            //DepartmentName  Single line of text Image
            //Division  Single line of text Image
            //EmployeeClassDesc  Single line of text Image
            //EmployeeID  Single line of text Image
            //EmployeeStatus  Single line of text Image
            //EmployeeStatusDesc  Single line of text Image
            //FirstName  Single line of text Image
            //FullName  Single line of text Image
            //Initials  Single line of text Image
            //JobDescr  Single line of text Image
            //Keywords  Multiple lines of text Image
            //LastName  Single line of text Image
            //LegalEntity  Single line of text Image
            //MiddleName  Single line of text Image
            //PhysicalLocation  Single line of text Image
            //PhysicalLocationName  Single line of text Image
            //Preview Image URL  Hyperlink or Picture
            //ReportingLocation  Single line of text Image
            //ReportingLocationName  Single line of text Image
            //Scheduling End Date  Publishing Schedule End Date
            //Scheduling Start Date  Publishing Schedule Start Date
            //SupervisorID  Single line of text Image
            //SupervisorInitials  Single line of text Image
            //SupervisorName  Single line of text Image
            //Created By  Person or Group
            //Modified By  Person or Group
            //Checked Out To  Person
            #endregion

            FieldInformation[] metaData =
            {
                ServiceField("Company",               employee.Company),
                ServiceField("Country",               employee.Country),
                ServiceField("Department",            employee.Department),
                ServiceField("DepartmentName",        employee.DepartmentName),
                ServiceField("Division",              employee.Division),
                ServiceField("EmployeeClassDesc",     employee.EmployeeClassDesc),
                ServiceField("EmployeeID",            employee.EmployeeID),
                ServiceField("EmployeeStatus",        employee.EmployeeStatus.ToString()),
                ServiceField("EmployeeStatusDesc",    employee.EmployeeStatusDesc),
                ServiceField("FirstName",             employee.FirstName),
                ServiceField("FullName",              employee.Name),
                ServiceField("Initials",              employee.Initials),
                ServiceField("JobDescr",              employee.JobDescr),
                ServiceField("LastName",              employee.LastName),
                ServiceField("LegalEntity",           employee.LegalEntity),
                ServiceField("MiddleName",            employee.MiddleName),
                ServiceField("PhysicalLocation",      employee.PhysicalLocation),
                ServiceField("PhysicalLocationName",  employee.PhysicalLocationName),
                ServiceField("ReportingLocation",     employee.ReportingLocation),
                ServiceField("ReportingLocationName", employee.ReportingLocationName),
                ServiceField("SupervisorID",          employee.SupervisorID),
                ServiceField("SupervisorInitials",    employee.SupervisorInitials),
                ServiceField("SupervisorName",        employee.SupervisorName),
                ServiceField("ImageCreateDate",       entity.udf1)
            };

            try
            {
                var proxyWs = new Copy {
                    Url = string.Format("{0}/_vti_bin/copy.asmx", ExportConfig.Link.TrimEnd('/'))
                };

                if (string.IsNullOrWhiteSpace(ExportConfig.Username) || string.IsNullOrWhiteSpace(ExportConfig.Password))
                {
                    proxyWs.UseDefaultCredentials = true;
                }
                else
                {
                    proxyWs.UseDefaultCredentials = false;
                    proxyWs.Credentials           = CreateCredentials(ExportConfig.Username, ExportConfig.Password, true);
                }

                CopyResult[] result;
                proxyWs.CopyIntoItems("http://null", destinationUrls, metaData, entity.Image, out result);

                if (result != null)
                {
                    var row = 0;
                    foreach (var copyResult in result.Where(copyResult => copyResult.ErrorCode != CopyErrorCode.Success))
                    {
                        results.Fail(copyResult.ErrorMessage, string.Format("E{0}", row));
                        row++;
                    }
                }

                return(results);
            }
            catch (Exception ex)
            {
                var errors = new Dictionary <string, string> {
                    { "StackTrace", ex.StackTrace }
                };
                return(results.Merge(new Result <Person>(ResultType.TechnicalError, ex.Message, errors)));
            }
        }
예제 #11
0
 public static R1Employee Select(this R1Employee entity, RSMLubrizolDataModelDataContext context)
 {
     return(context.Lubrizol_Employees.FirstOrDefault(x => x.EmployeeID == entity.EmployeeID));
 }