public static EmployeeByBusinessPartner ConvertToEmployeeByBusinessPartner(this EmployeeByBusinessPartnerViewModel employeeByBusinessPartnerViewModel)
        {
            EmployeeByBusinessPartner employeeByBusinessPartner = new EmployeeByBusinessPartner()
            {
                Id         = employeeByBusinessPartnerViewModel.Id,
                Identifier = employeeByBusinessPartnerViewModel.Identifier,

                Code        = employeeByBusinessPartnerViewModel.Code,
                StartDate   = employeeByBusinessPartnerViewModel.StartDate,
                EndDate     = employeeByBusinessPartnerViewModel.EndDate,
                RealEndDate = employeeByBusinessPartnerViewModel.RealEndDate,

                EmployeeId        = employeeByBusinessPartnerViewModel.Employee?.Id ?? null,
                EmployeeCount     = employeeByBusinessPartnerViewModel.EmployeeCount,
                BusinessPartnerId = employeeByBusinessPartnerViewModel.BusinessPartner?.Id ?? null,

                CreatedById = employeeByBusinessPartnerViewModel.CreatedBy?.Id ?? null,
                CompanyId   = employeeByBusinessPartnerViewModel.Company?.Id ?? null,

                CreatedAt = employeeByBusinessPartnerViewModel.CreatedAt,
                UpdatedAt = employeeByBusinessPartnerViewModel.UpdatedAt
            };

            return(employeeByBusinessPartner);
        }
Beispiel #2
0
        public EmployeeByBusinessPartner Delete(EmployeeByBusinessPartner employeeByBusinessPartner)
        {
            // Load EmployeeByBusinessPartner that will be deleted
            EmployeeByBusinessPartner dbEntry = context.EmployeeByBusinessPartners
                                                .FirstOrDefault(x => x.Identifier == employeeByBusinessPartner.Identifier);

            if (dbEntry != null)
            {
                // Set activity
                dbEntry.Active      = false;
                dbEntry.RealEndDate = employeeByBusinessPartner.RealEndDate;
                // Set timestamp
                dbEntry.UpdatedAt = DateTime.Now;
            }

            return(dbEntry);
        }
Beispiel #3
0
        public EmployeeByBusinessPartner Create(EmployeeByBusinessPartner employeeByBusinessPartner)
        {
            if (context.EmployeeByBusinessPartners.Where(x => x.Identifier != null && x.Identifier == employeeByBusinessPartner.Identifier).Count() == 0)
            {
                employeeByBusinessPartner.Id = 0;

                employeeByBusinessPartner.Code   = GetNewCodeValue(employeeByBusinessPartner.CompanyId ?? 0);
                employeeByBusinessPartner.Active = true;

                employeeByBusinessPartner.UpdatedAt = DateTime.Now;
                employeeByBusinessPartner.CreatedAt = DateTime.Now;

                context.EmployeeByBusinessPartners.Add(employeeByBusinessPartner);
                return(employeeByBusinessPartner);
            }
            else
            {
                // Load employeeByBusinessPartner that will be updated
                EmployeeByBusinessPartner dbEntry = context.EmployeeByBusinessPartners
                                                    .FirstOrDefault(x => x.Identifier == employeeByBusinessPartner.Identifier && x.Active == true);

                if (dbEntry != null)
                {
                    dbEntry.EmployeeId        = employeeByBusinessPartner.EmployeeId ?? null;
                    dbEntry.BusinessPartnerId = employeeByBusinessPartner.BusinessPartnerId ?? null;
                    dbEntry.CompanyId         = employeeByBusinessPartner.CompanyId ?? null;
                    dbEntry.CreatedById       = employeeByBusinessPartner.CreatedById ?? null;

                    // Set properties
                    dbEntry.StartDate     = employeeByBusinessPartner.StartDate;
                    dbEntry.EndDate       = employeeByBusinessPartner.EndDate;
                    dbEntry.RealEndDate   = employeeByBusinessPartner.RealEndDate;
                    dbEntry.EmployeeCount = employeeByBusinessPartner.EmployeeCount;

                    // Set timestamp
                    dbEntry.UpdatedAt = DateTime.Now;
                }

                return(dbEntry);
            }
        }
Beispiel #4
0
        public EmployeeByBusinessPartnerResponse Delete(EmployeeByBusinessPartnerViewModel employeeByBysinessPartner)
        {
            EmployeeByBusinessPartnerResponse response = new EmployeeByBusinessPartnerResponse();

            try
            {
                EmployeeByBusinessPartner deletedEmployeeByBusinessPartner = unitOfWork.GetEmployeeByBusinessPartnerRepository()
                                                                             .Delete(employeeByBysinessPartner.ConvertToEmployeeByBusinessPartner());

                Employee        employee        = unitOfWork.GetEmployeeRepository().GetEmployee((int)deletedEmployeeByBusinessPartner.EmployeeId);
                BusinessPartner businessPartner = unitOfWork.GetBusinessPartnerRepository().GetBusinessPartner((int)deletedEmployeeByBusinessPartner.BusinessPartnerId);

                EmployeeCard ec = new EmployeeCard()
                {
                    Identifier  = Guid.NewGuid(),
                    EmployeeId  = deletedEmployeeByBusinessPartner.EmployeeId,
                    CardDate    = (DateTime)deletedEmployeeByBusinessPartner.RealEndDate,
                    Description = "Radnik " + employee?.Name + " " + employee?.SurName + " je raskinuo ugovor sa firmom " + businessPartner?.Name + ". Prestanak je od: " + ((DateTime)deletedEmployeeByBusinessPartner.RealEndDate).ToString("dd.MM.yyyy"),
                    PlusMinus   = "-",
                    CreatedById = deletedEmployeeByBusinessPartner.CreatedById,
                    CompanyId   = deletedEmployeeByBusinessPartner.CompanyId,
                    CreatedAt   = DateTime.Now,
                    UpdatedAt   = DateTime.Now
                };
                unitOfWork.GetEmployeeCardRepository().Create(ec);

                unitOfWork.Save();

                response.EmployeeByBusinessPartner = deletedEmployeeByBusinessPartner.ConvertToEmployeeByBusinessPartnerViewModel();
                response.Success = true;
            }
            catch (Exception ex)
            {
                response.EmployeeByBusinessPartner = new EmployeeByBusinessPartnerViewModel();
                response.Success = false;
                response.Message = ex.Message;
            }

            return(response);
        }
Beispiel #5
0
        public EmployeeByBusinessPartnerResponse Create(EmployeeByBusinessPartnerViewModel re)
        {
            EmployeeByBusinessPartnerResponse response = new EmployeeByBusinessPartnerResponse();

            try
            {
                EmployeeByBusinessPartner addedEmployeeByBusinessPartner = unitOfWork.GetEmployeeByBusinessPartnerRepository()
                                                                           .Create(re.ConvertToEmployeeByBusinessPartner());

                EmployeeCard ec = new EmployeeCard()
                {
                    Identifier  = Guid.NewGuid(),
                    EmployeeId  = re.Employee.Id,
                    CardDate    = re.StartDate,
                    Description = "Radnik " + re.Employee?.Name + " " + re.Employee?.SurName + " je sklopio ugovor sa firmom " + re.BusinessPartner?.Name + ". Radnik je u firmi od: " + re.StartDate.ToString("dd.MM.yyyy") + " do " + re.EndDate.ToString("dd.MM.yyyy"),
                    PlusMinus   = "+",
                    CreatedById = re.CreatedBy?.Id,
                    CompanyId   = re.Company?.Id,
                    CreatedAt   = DateTime.Now,
                    UpdatedAt   = DateTime.Now
                };
                unitOfWork.GetEmployeeCardRepository().Create(ec);

                unitOfWork.Save();

                response.EmployeeByBusinessPartner = addedEmployeeByBusinessPartner.ConvertToEmployeeByBusinessPartnerViewModel();
                response.Success = true;
            }
            catch (Exception ex)
            {
                response.EmployeeByBusinessPartner = new EmployeeByBusinessPartnerViewModel();
                response.Success = false;
                response.Message = ex.Message;
            }

            return(response);
        }
        public static EmployeeByBusinessPartnerViewModel ConvertToEmployeeByBusinessPartnerViewModelLite(this EmployeeByBusinessPartner employeeByBusinessPartner)
        {
            EmployeeByBusinessPartnerViewModel remedyViewModel = new EmployeeByBusinessPartnerViewModel()
            {
                Id         = employeeByBusinessPartner.Id,
                Identifier = employeeByBusinessPartner.Identifier,

                Code = employeeByBusinessPartner.Code,

                StartDate   = employeeByBusinessPartner.StartDate,
                EndDate     = employeeByBusinessPartner.EndDate,
                RealEndDate = employeeByBusinessPartner.RealEndDate,

                EmployeeCount = employeeByBusinessPartner.EmployeeCount,

                IsActive = employeeByBusinessPartner.Active,

                UpdatedAt = employeeByBusinessPartner.UpdatedAt,
                CreatedAt = employeeByBusinessPartner.CreatedAt
            };


            return(remedyViewModel);
        }
Beispiel #7
0
        private EmployeeByBusinessPartner Read(SqlDataReader reader)
        {
            EmployeeByBusinessPartner employeeByBusinessPartner = new EmployeeByBusinessPartner();

            employeeByBusinessPartner.Id         = Int32.Parse(reader["EmployeeByBusinessPartnerId"].ToString());
            employeeByBusinessPartner.Identifier = Guid.Parse(reader["EmployeeByBusinessPartnerIdentifier"].ToString());
            employeeByBusinessPartner.Code       = reader["EmployeeByBusinessPartnerCode"].ToString();
            if (reader["StartDate"] != DBNull.Value)
            {
                employeeByBusinessPartner.StartDate = DateTime.Parse(reader["StartDate"].ToString());
            }
            if (reader["EndDate"] != DBNull.Value)
            {
                employeeByBusinessPartner.EndDate = DateTime.Parse(reader["EndDate"].ToString());
            }
            if (reader["RealEndDate"] != DBNull.Value)
            {
                employeeByBusinessPartner.RealEndDate = DateTime.Parse(reader["RealEndDate"]?.ToString());
            }

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

            if (reader["EmployeeCount"] != DBNull.Value)
            {
                employeeByBusinessPartner.EmployeeCount = Int32.Parse(reader["EmployeeCount"].ToString());
            }

            if (reader["BusinessPartnerId"] != DBNull.Value)
            {
                employeeByBusinessPartner.BusinessPartner              = new BusinessPartner();
                employeeByBusinessPartner.BusinessPartnerId            = Int32.Parse(reader["BusinessPartnerId"].ToString());
                employeeByBusinessPartner.BusinessPartner.Id           = Int32.Parse(reader["BusinessPartnerId"].ToString());
                employeeByBusinessPartner.BusinessPartner.Identifier   = Guid.Parse(reader["BusinessPartnerIdentifier"].ToString());
                employeeByBusinessPartner.BusinessPartner.Code         = reader["BusinessPartnerCode"].ToString();
                employeeByBusinessPartner.BusinessPartner.Name         = reader["BusinessPartnerName"].ToString();
                employeeByBusinessPartner.BusinessPartner.InternalCode = reader["BusinessPartnerInternalCode"].ToString();
                employeeByBusinessPartner.BusinessPartner.NameGer      = reader["BusinessPartnerNameGer"].ToString();
            }

            employeeByBusinessPartner.Active    = bool.Parse(reader["Active"].ToString());
            employeeByBusinessPartner.UpdatedAt = DateTime.Parse(reader["UpdatedAt"].ToString());

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

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

            return(employeeByBusinessPartner);
        }