Пример #1
0
        public EmployeeLicence Create(EmployeeLicence EmployeeLicence)
        {
            if (context.EmployeeLicences.Where(x => x.Identifier != null && x.Identifier == EmployeeLicence.Identifier).Count() == 0)
            {
                EmployeeLicence.Id = 0;

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

                if (dbEntry != null)
                {
                    dbEntry.LicenceId   = EmployeeLicence.LicenceId ?? null;
                    dbEntry.CountryId   = EmployeeLicence.CountryId ?? null;
                    dbEntry.CompanyId   = EmployeeLicence.CompanyId ?? null;
                    dbEntry.CreatedById = EmployeeLicence.CreatedById ?? null;

                    dbEntry.ValidFrom  = EmployeeLicence.ValidFrom;
                    dbEntry.ValidTo    = EmployeeLicence.ValidTo;
                    dbEntry.ItemStatus = EmployeeLicence.ItemStatus;
                    // Set timestamp
                    dbEntry.UpdatedAt = DateTime.Now;
                }

                return(dbEntry);
            }
        }
Пример #2
0
        public static EmployeeLicenceItemViewModel ConvertToEmployeeLicenceViewModel(this EmployeeLicence EmployeeItem)
        {
            EmployeeLicenceItemViewModel EmployeeItemViewModel = new EmployeeLicenceItemViewModel()
            {
                Id         = EmployeeItem.Id,
                Identifier = EmployeeItem.Identifier,

                Employee = EmployeeItem.Employee?.ConvertToEmployeeViewModelLite(),
                Licence  = EmployeeItem.Licence?.ConvertToLicenceTypeViewModelLite(),
                Country  = EmployeeItem.Country?.ConvertToCountryViewModelLite(),

                ValidFrom  = EmployeeItem.ValidFrom,
                ValidTo    = EmployeeItem.ValidTo,
                ItemStatus = EmployeeItem.ItemStatus,
                IsActive   = EmployeeItem.Active,

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

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

            return(EmployeeItemViewModel);
        }
Пример #3
0
        public EmployeeLicence Delete(Guid identifier)
        {
            EmployeeLicence dbEntry = context.EmployeeLicences
                                      .Union(context.ChangeTracker.Entries()
                                             .Where(x => x.State == EntityState.Added && x.Entity.GetType() == typeof(EmployeeLicence))
                                             .Select(x => x.Entity as EmployeeLicence))
                                      .FirstOrDefault(x => x.Identifier == identifier);

            if (dbEntry != null)
            {
                dbEntry.Active    = false;
                dbEntry.UpdatedAt = DateTime.Now;
            }
            return(dbEntry);
        }
Пример #4
0
        public static EmployeeLicence ConvertToEmployeeLicence(this EmployeeLicenceItemViewModel EmployeeItemViewModel)
        {
            EmployeeLicence EmployeeItem = new EmployeeLicence()
            {
                Id         = EmployeeItemViewModel.Id,
                Identifier = EmployeeItemViewModel.Identifier,

                EmployeeId = EmployeeItemViewModel.Employee?.Id ?? null,
                LicenceId  = EmployeeItemViewModel.Licence?.Id ?? null,
                CountryId  = EmployeeItemViewModel.Country?.Id ?? null,

                ValidFrom   = EmployeeItemViewModel.ValidFrom,
                ValidTo     = EmployeeItemViewModel.ValidTo,
                ItemStatus  = EmployeeItemViewModel.ItemStatus,
                Active      = EmployeeItemViewModel.IsActive,
                CreatedById = EmployeeItemViewModel.CreatedBy?.Id ?? null,
                CompanyId   = EmployeeItemViewModel.Company?.Id ?? null,

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

            return(EmployeeItem);
        }
Пример #5
0
        public List <EmployeeLicence> GetEmployeeItems(int companyId)  // izmene u IEmployeeLicenceRepository -> GetEmployeeLicences?
        {
            List <EmployeeLicence> EmployeeLicences = new List <EmployeeLicence>();

            string queryString =
                "SELECT EmployeeLicenceId, EmployeeLicenceIdentifier, " +
                "EmployeeId, EmployeeIdentifier, EmployeeCode, EmployeeName, " +
                "LicenceId, LicenceIdentifier, LicenceCode, LicenceCategory, LicenceDescription, " +
                "CountryId, CountryIdentifier, CountryCode, CountryName, " +
                "ValidFrom, ValidTo, ItemStatus, " +
                "Active, UpdatedAt, CreatedById, CreatedByFirstName, CreatedByLastName, " +
                "CompanyId, CompanyName " +
                "FROM vEmployeeLicences " +
                "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())
                {
                    EmployeeLicence employeeLicence;
                    while (reader.Read())
                    {
                        employeeLicence            = new EmployeeLicence();
                        employeeLicence.Id         = Int32.Parse(reader["EmployeeLicenceId"].ToString());
                        employeeLicence.Identifier = Guid.Parse(reader["EmployeeLicenceIdentifier"].ToString());

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

                        if (reader["LicenceId"] != DBNull.Value)
                        {
                            employeeLicence.Licence             = new LicenceType();
                            employeeLicence.LicenceId           = Int32.Parse(reader["LicenceId"].ToString());
                            employeeLicence.Licence.Id          = Int32.Parse(reader["LicenceId"].ToString());
                            employeeLicence.Licence.Identifier  = Guid.Parse(reader["LicenceIdentifier"].ToString());
                            employeeLicence.Licence.Code        = reader["LicenceCode"].ToString();
                            employeeLicence.Licence.Category    = reader["LicenceCategory"].ToString();
                            employeeLicence.Licence.Description = reader["LicenceDescription"].ToString();
                        }

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

                        if (reader["ValidFrom"] != DBNull.Value)
                        {
                            employeeLicence.ValidFrom = DateTime.Parse(reader["ValidFrom"].ToString());
                        }
                        if (reader["ValidTo"] != DBNull.Value)
                        {
                            employeeLicence.ValidTo = DateTime.Parse(reader["ValidTo"].ToString());
                        }
                        if (reader["ItemStatus"] != DBNull.Value)
                        {
                            employeeLicence.ItemStatus = Int32.Parse(reader["ItemStatus"].ToString());
                        }
                        employeeLicence.Active    = bool.Parse(reader["Active"].ToString());
                        employeeLicence.UpdatedAt = DateTime.Parse(reader["UpdatedAt"].ToString());

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

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

                        EmployeeLicences.Add(employeeLicence);
                    }
                }
            }
            return(EmployeeLicences);

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

            //return EmployeeLicences;
        }
Пример #6
0
        public static EmployeeLicenceItemViewModel ConvertToEmployeeLicenceViewModelLite(this EmployeeLicence EmployeeItem)
        {
            EmployeeLicenceItemViewModel EmployeeItemViewModel = new EmployeeLicenceItemViewModel()
            {
                Id         = EmployeeItem.Id,
                Identifier = EmployeeItem.Identifier,

                ValidFrom  = EmployeeItem.ValidFrom,
                ValidTo    = EmployeeItem.ValidTo,
                ItemStatus = EmployeeItem.ItemStatus,
                IsActive   = EmployeeItem.Active,

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

            return(EmployeeItemViewModel);
        }