public EmployeeProfession Create(EmployeeProfession EmployeeProfession)
        {
            if (context.EmployeeProfessions.Where(x => x.Identifier != null && x.Identifier == EmployeeProfession.Identifier).Count() == 0)
            {
                EmployeeProfession.Id = 0;

                EmployeeProfession.Active    = true;
                EmployeeProfession.UpdatedAt = DateTime.Now;
                EmployeeProfession.CreatedAt = DateTime.Now;
                context.EmployeeProfessions.Add(EmployeeProfession);
                return(EmployeeProfession);
            }
            else
            {
                // Load item that will be updated
                EmployeeProfession dbEntry = context.EmployeeProfessions
                                             .FirstOrDefault(x => x.Identifier == EmployeeProfession.Identifier && x.Active == true);

                if (dbEntry != null)
                {
                    dbEntry.ProfessionId = EmployeeProfession.ProfessionId ?? null;
                    dbEntry.CountryId    = EmployeeProfession.CountryId ?? null;
                    dbEntry.CompanyId    = EmployeeProfession.CompanyId ?? null;
                    dbEntry.CreatedById  = EmployeeProfession.CreatedById ?? null;
                    dbEntry.ItemStatus   = EmployeeProfession.ItemStatus;
                    // Set timestamp
                    dbEntry.UpdatedAt = DateTime.Now;
                }

                return(dbEntry);
            }
        }
コード例 #2
0
 public IActionResult DeleteEmployeeProfession(EmployeeProfession employeeProfession)
 {
     return(this.RunWithErrorHandling(() =>
     {
         databaseProvider.Execute("base.employeeprofession_delete", employeeProfession);
         return Ok(true);
     }));
 }
コード例 #3
0
 public IActionResult InsertEmployeeProfession(EmployeeProfession employeeProfession)
 {
     return(this.RunWithErrorHandling(() =>
     {
         return Ok
         (
             databaseProvider.Query <EmployeeProfession>("base.employeeprofession_insert", employeeProfession).FirstOrDefault()
         );
     }));
 }
        public EmployeeProfession Delete(Guid identifier)
        {
            EmployeeProfession dbEntry = context.EmployeeProfessions
                                         .Union(context.ChangeTracker.Entries()
                                                .Where(x => x.State == EntityState.Added && x.Entity.GetType() == typeof(EmployeeProfession))
                                                .Select(x => x.Entity as EmployeeProfession))
                                         .FirstOrDefault(x => x.Identifier == identifier);

            if (dbEntry != null)
            {
                dbEntry.Active    = false;
                dbEntry.UpdatedAt = DateTime.Now;
            }
            return(dbEntry);
        }
コード例 #5
0
        public static EmployeeProfession ConvertToEmployeeProfession(this EmployeeProfessionItemViewModel EmployeeItemViewModel)
        {
            EmployeeProfession EmployeeItem = new EmployeeProfession()
            {
                Id         = EmployeeItemViewModel.Id,
                Identifier = EmployeeItemViewModel.Identifier,

                EmployeeId   = EmployeeItemViewModel.Employee?.Id ?? null,
                ProfessionId = EmployeeItemViewModel.Profession?.Id ?? null,
                CountryId    = EmployeeItemViewModel.Country?.Id ?? null,
                ItemStatus   = EmployeeItemViewModel.ItemStatus,
                Active       = EmployeeItemViewModel.IsActive,
                CreatedById  = EmployeeItemViewModel.CreatedBy?.Id ?? null,
                CompanyId    = EmployeeItemViewModel.Company?.Id ?? null,

                CreatedAt = EmployeeItemViewModel.CreatedAt,
                UpdatedAt = EmployeeItemViewModel.UpdatedAt
            };

            return(EmployeeItem);
        }
        public List <EmployeeProfession> GetEmployeeItems(int companyId)
        {
            List <EmployeeProfession> EmployeeProfessions = new List <EmployeeProfession>();

            string queryString =
                "SELECT EmployeeProfessionId, EmployeeProfessionIdentifier, " +
                "EmployeeId, EmployeeIdentifier, EmployeeCode, EmployeeName, " +
                "ProfessionId, ProfessionIdentifier, ProfessionCode, ProfessionName, ProfessionSecondCode, " +
                "CountryId, CountryIdentifier, CountryCode, CountryName, " +
                "ItemStatus, Active, UpdatedAt, CreatedById, CreatedByFirstName, CreatedByLastName, CompanyId, CompanyName " +
                "FROM vEmployeeProfessions " +
                "WHERE CompanyId = @CompanyId;";

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                SqlCommand command = connection.CreateCommand();
                command.CommandText = queryString;
                command.Parameters.Add(new SqlParameter("@CompanyId", companyId));

                connection.Open();
                using (SqlDataReader reader = command.ExecuteReader())
                {
                    EmployeeProfession employeeProfession;
                    while (reader.Read())
                    {
                        employeeProfession            = new EmployeeProfession();
                        employeeProfession.Id         = Int32.Parse(reader["EmployeeProfessionId"].ToString());
                        employeeProfession.Identifier = Guid.Parse(reader["EmployeeProfessionIdentifier"].ToString());

                        if (reader["EmployeeId"] != DBNull.Value)
                        {
                            employeeProfession.Employee            = new Employee();
                            employeeProfession.EmployeeId          = Int32.Parse(reader["EmployeeId"].ToString());
                            employeeProfession.Employee.Id         = Int32.Parse(reader["EmployeeId"].ToString());
                            employeeProfession.Employee.Identifier = Guid.Parse(reader["EmployeeIdentifier"].ToString());
                            employeeProfession.Employee.Code       = reader["EmployeeCode"].ToString();
                            employeeProfession.Employee.Name       = reader["EmployeeName"].ToString();
                        }

                        if (reader["ProfessionId"] != DBNull.Value)
                        {
                            employeeProfession.Profession            = new Profession();
                            employeeProfession.ProfessionId          = Int32.Parse(reader["ProfessionId"].ToString());
                            employeeProfession.Profession.Id         = Int32.Parse(reader["ProfessionId"].ToString());
                            employeeProfession.Profession.Identifier = Guid.Parse(reader["ProfessionIdentifier"].ToString());
                            employeeProfession.Profession.Code       = reader["ProfessionCode"].ToString();
                            employeeProfession.Profession.Name       = reader["ProfessionName"].ToString();
                            employeeProfession.Profession.SecondCode = reader["ProfessionSecondCode"].ToString();
                        }

                        if (reader["CountryId"] != DBNull.Value)
                        {
                            employeeProfession.Country            = new Country();
                            employeeProfession.CountryId          = Int32.Parse(reader["CountryId"].ToString());
                            employeeProfession.Country.Id         = Int32.Parse(reader["CountryId"].ToString());
                            employeeProfession.Country.Identifier = Guid.Parse(reader["CountryIdentifier"].ToString());
                            employeeProfession.Country.Mark       = reader["CountryCode"].ToString();
                            employeeProfession.Country.Name       = reader["CountryName"].ToString();
                        }
                        if (reader["ItemStatus"] != DBNull.Value)
                        {
                            employeeProfession.ItemStatus = Int32.Parse(reader["ItemStatus"].ToString());
                        }
                        employeeProfession.Active    = bool.Parse(reader["Active"].ToString());
                        employeeProfession.UpdatedAt = DateTime.Parse(reader["UpdatedAt"].ToString());

                        if (reader["CreatedById"] != DBNull.Value)
                        {
                            employeeProfession.CreatedBy           = new User();
                            employeeProfession.CreatedById         = Int32.Parse(reader["CreatedById"].ToString());
                            employeeProfession.CreatedBy.Id        = Int32.Parse(reader["CreatedById"].ToString());
                            employeeProfession.CreatedBy.FirstName = reader["CreatedByFirstName"]?.ToString();
                            employeeProfession.CreatedBy.LastName  = reader["CreatedByLastName"]?.ToString();
                        }

                        if (reader["CompanyId"] != DBNull.Value)
                        {
                            employeeProfession.Company      = new Company();
                            employeeProfession.CompanyId    = Int32.Parse(reader["CompanyId"].ToString());
                            employeeProfession.Company.Id   = Int32.Parse(reader["CompanyId"].ToString());
                            employeeProfession.Company.Name = reader["CompanyName"].ToString();
                        }

                        EmployeeProfessions.Add(employeeProfession);
                    }
                }
            }
            return(EmployeeProfessions);


            //List<EmployeeProfession> EmployeeProfessions = context.EmployeeProfessions
            //    .Include(x => x.Employee)
            //    .Include(x => x.Profession)
            //    .Include(x => x.Country)
            //    .Include(x => x.Company)
            //    .Include(x => x.CreatedBy)
            //    .Where(x => x.Active == true && x.CompanyId == companyId)
            //    .AsNoTracking()
            //    .ToList();

            //return EmployeeProfessions;
        }
コード例 #7
0
        public static EmployeeProfessionItemViewModel ConvertToEmployeeProfessionViewModelLite(this EmployeeProfession EmployeeItem)
        {
            EmployeeProfessionItemViewModel EmployeeItemViewModel = new EmployeeProfessionItemViewModel()
            {
                Id         = EmployeeItem.Id,
                Identifier = EmployeeItem.Identifier,
                ItemStatus = EmployeeItem.ItemStatus,
                IsActive   = EmployeeItem.Active,

                UpdatedAt = EmployeeItem.UpdatedAt,
                CreatedAt = EmployeeItem.CreatedAt
            };

            return(EmployeeItemViewModel);
        }
コード例 #8
0
        public static EmployeeProfessionItemViewModel ConvertToEmployeeProfessionViewModel(this EmployeeProfession EmployeeItem)
        {
            EmployeeProfessionItemViewModel EmployeeItemViewModel = new EmployeeProfessionItemViewModel()
            {
                Id         = EmployeeItem.Id,
                Identifier = EmployeeItem.Identifier,

                Employee   = EmployeeItem.Employee?.ConvertToEmployeeViewModelLite(),
                Profession = EmployeeItem.Profession?.ConvertToProfessionViewModelLite(),
                Country    = EmployeeItem.Country?.ConvertToCountryViewModelLite(),
                ItemStatus = EmployeeItem.ItemStatus,
                IsActive   = EmployeeItem.Active,

                CreatedBy = EmployeeItem.CreatedBy?.ConvertToUserViewModelLite(),
                Company   = EmployeeItem.Company?.ConvertToCompanyViewModelLite(),

                UpdatedAt = EmployeeItem.UpdatedAt,
                CreatedAt = EmployeeItem.CreatedAt
            };

            return(EmployeeItemViewModel);
        }