Beispiel #1
0
        public NoteDTO Replace(long id, NoteEntity newEntity)
        {
            var        transaction = _humanManagerContext.Database.BeginTransaction();
            NoteEntity oldEntity   = null;

            try
            {
                NoteEntity entity = _humanManagerContext.Notes.SingleOrDefault(item => item.Id == id);
                if (entity != null)
                {
                    entity.Id      = newEntity.Id;
                    entity.Content = newEntity.Content;
                    _humanManagerContext.SaveChanges();
                }

                transaction.Commit();

                NoteDTO dto = _mapper.Map <NoteDTO>(entity);

                return(dto);
            }
            catch
            {
                transaction.Rollback();
                return(null);
            }
        }
Beispiel #2
0
        public WardDTO Edit(long id, WardEntity ward)
        {
            var transaction = _humanManagerContext.Database.BeginTransaction();

            try
            {
                WardEntity entity = _humanManagerContext.Wards.SingleOrDefault(item => item.Id == id);
                if (entity != null)
                {
                    // entity.Id = ward.Id;
                    entity.Name        = ward.Name;
                    entity.District_Id = ward.District_Id;
                    _humanManagerContext.SaveChanges();
                }

                transaction.Commit();

                WardDTO dto = _mapper.Map <WardDTO>(entity);

                return(dto);
            }
            catch
            {
                transaction.Rollback();
                return(null);
            }
        }
Beispiel #3
0
        public List <TimeKeepingDTO> Save()
        {
            var transaction = _humanManagerContext.Database.BeginTransaction();

            //lấy ngày hiện tại trong máy
            DateTime nowDate = DateTime.Now;
            String   date    = nowDate.ToString("dd/MM/yyyy");

            List <EmployeeEntity> entities = _humanManagerContext.Employees.ToList();
            List <TimeKeepingDTO> listDTO  = new List <TimeKeepingDTO>();

            entities.ForEach(entity =>
            {
                TimeKeepingEntity entityTimeKeeping = new TimeKeepingEntity();
                entityTimeKeeping.idEmployee        = entity.Id;
                entityTimeKeeping.minimumTime       = 6;
                entityTimeKeeping.status            = 1;
                entityTimeKeeping.morning           = 1;
                entityTimeKeeping.afternoon         = 1;
                entityTimeKeeping.dateStart         = date;

                entityTimeKeeping = _humanManagerContext.Timekeepings.Add(entityTimeKeeping).Entity;

                listDTO.Add(_mapper.Map <TimeKeepingDTO>(entityTimeKeeping));
                // dtos.Add(_mapper.Map<EmployeeDTO>(entity));
            });

            _humanManagerContext.SaveChanges();
            transaction.Commit();
            //



            return(listDTO);
        }
        public CandidateDTO Save(CandidateForm canForm)
        {
            CandidateEntity entity = null;
            NoteDTO         note   = new NoteDTO();

            note.Content = "";
            note.Id      = 0;
            canForm.Note = note;
            note         = _noteService.Save(_mapper.Map <NoteEntity>(canForm.Note));
            canForm.Note = note;
            var transaction = _humanManagerContext.Database.BeginTransaction();

            try
            {
                string folderName             = SystemContant.Candidate_Uploading_Path;
                string uploadPath             = _hostingEnvironment.ContentRootPath;
                string newPath                = Path.Combine(uploadPath, folderName);
                UploadUtil.Uploader uploader  = _uploadUtil.DoFileUploading(newPath, canForm.UploadedFile);
                CandidateEntity     newEntity = _mapper.Map <CandidateEntity>(canForm);
                newEntity.ImageName = uploader.fileName;
                entity = _humanManagerContext.Candidates.Add(newEntity).Entity;
                _humanManagerContext.SaveChanges();

                transaction.Commit();
                CandidateDTO dto = _mapper.Map <CandidateDTO>(entity);
                return(dto);
            }
            catch
            {
                transaction.Rollback();
                return(null);
            }
        }
        // chức năng kết thúc ngày công
        public TimeKeepingDetailDTO endTimeKeepingforOneDay(TimeKeepingDetailEntity oldEntity)
        {
            var      transaction = _humanManagerContext.Database.BeginTransaction();
            DateTime nowDate     = DateTime.Now;

            //  DateTime endDate = new DateTime('8/11/2020 10:06:00 PM');
            try
            {
                TimeKeepingDetailEntity old = _humanManagerContext.TimeKeepingDetails.Where(tkd => tkd.Id == oldEntity.Id).SingleOrDefault();

                TimeKeepingEntity oldTimeKeeping = _humanManagerContext.Timekeepings.Where(tk => tk.Id == old.timeKeepingId).SingleOrDefault();
                String            test           = oldTimeKeeping.Id + "";
                DateTime          oldDateTime    = old.timeStart;
                TimeSpan          t = nowDate - oldDateTime;
                int count           = t.Hours;

                //Cộng thời gian làm lên
                oldTimeKeeping.plusWorkingTime(count);

                old.status      = 0;
                old.timeEnd     = nowDate;
                old.timeWorking = count;

                _humanManagerContext.SaveChanges();

                //Cộng thời gian làm lên
                oldTimeKeeping.plusWorkingTime(count);

                old.status      = 0;
                old.timeEnd     = nowDate;
                old.timeWorking = count;

                _humanManagerContext.SaveChanges();
                return(_mapper.Map <TimeKeepingDetailDTO>(old));
            }
            catch
            {
                transaction.Rollback();
                return(null);
            }
        }
Beispiel #6
0
        public JobDTO Save(JobEntity newEntity)
        {
            var       transaction = _humanManagerContext.Database.BeginTransaction();
            JobEntity entity      = null;

            try
            {
                entity = _humanManagerContext.Jobs.Add(newEntity).Entity;
                _humanManagerContext.SaveChanges();

                transaction.Commit();

                JobDTO dto = _mapper.Map <JobDTO>(entity);

                return(dto);
            }
            catch
            {
                transaction.Rollback();
                return(null);
            }
        }
Beispiel #7
0
        public EmployeeDTO Save(EmployeeEntity emp)
        {
            emp.Job = null;
            var            transaction = _humanManagerContext.Database.BeginTransaction();
            EmployeeEntity entity      = null;


            try
            {
                entity = _humanManagerContext.Employees.Add(emp).Entity;
                _humanManagerContext.SaveChanges();
                transaction.Commit();

                EmployeeDTO dto = _mapper.Map <EmployeeDTO>(entity);
                return(dto);
            }
            catch (Exception ex)
            {
                transaction.Rollback();
                throw ex;
            }
        }
Beispiel #8
0
        public LogDTO Save(LogEntity entity)
        {
            var transaction = _humanManagerContext.Database.BeginTransaction();

            try
            {
                entity = _humanManagerContext.Logs.Add(entity).Entity;
                _humanManagerContext.SaveChanges();

                transaction.Commit();
                LogDTO dto = _mapper.Map <LogDTO>(entity);
                return(dto);
            }
            catch
            {
                transaction.Rollback();
                return(null);
            }
        }
        public ProvinceDTO save(ProvinceEntity entity)
        {
            var transaction = _humanManagerContext.Database.BeginTransaction();

            try
            {
                entity = _humanManagerContext.Provinces.Add(entity).Entity;
                _humanManagerContext.SaveChanges();

                transaction.Commit();
                ProvinceDTO dto = _mapper.Map <ProvinceDTO>(entity);
                return(dto);
            }
            catch
            {
                transaction.Rollback();
                return(null);
            }
        }
        public DistrictDTO Save(DistrictEntity district)
        {
            var transaction = _humanManagerContext.Database.BeginTransaction();

            try
            {
                district = _humanManagerContext.Districts.Add(district).Entity;
                _humanManagerContext.SaveChanges();

                transaction.Commit();
                DistrictDTO dto = _mapper.Map <DistrictDTO>(district);
                return(dto);
            }
            catch
            {
                transaction.Rollback();
                return(null);
            }
        }
        public ScheduleDTO Save(ScheduleEntity schedule)
        {
            var            transaction = _humanManagerContext.Database.BeginTransaction();
            ScheduleEntity entity      = null;

            try
            {
                entity = _humanManagerContext.Schedules.Add(schedule).Entity;
                _humanManagerContext.SaveChanges();

                transaction.Commit();

                ScheduleDTO dto = _mapper.Map <ScheduleDTO>(entity);
                transaction.Dispose();

                return(dto);
            }
            catch
            {
                transaction.Rollback();
                return(null);
            }
        }
Beispiel #12
0
        public bool DoSalaryCounting(long empId, Date countingDate)
        {
            var transaction = _humanManagerContext.Database.BeginTransaction();

            try
            {
                // Lấy cấu hình
                ConfigureEntity configure = _humanManagerContext.Configures.SingleOrDefault();

                // lấy nhân viên
                EmployeeEntity employeeEntity = _humanManagerContext.Employees
                                                .Where(e => e.Id == empId)
                                                .Include(e => e.Job)
                                                .ThenInclude(j => j.JobLevel)
                                                .Include(e => e.RewardPunishes)
                                                .SingleOrDefault();
                // Lấy bảo hiểm
                List <InsurranceEntity> insurrances = _humanManagerContext.Insurrances.ToList();

                // Lấy lương quy định tối thiểu
                int miniumSalary = (int)configure.MinimumSalary;

                // Tính hệ số lương
                double salaryCoefficient = SalaryUtil.GetSalaryCoefficient(employeeEntity.Job.JobLevel, employeeEntity.JobLevel);

                // Lây số ngày công quy định
                int regulationWorkDay = (int)configure.RegulationWorkDay;

                // Lấy số ngày công thực tế
                int empWorkDay = 30;

                // Tính phụ cấp

                // Tính thưởng phạt
                int rewardMoney  = SalaryUtil.DoRewardMoneyCounting(employeeEntity.RewardPunishes);
                int publishMoney = SalaryUtil.DoPublishMoneyCounting(employeeEntity.RewardPunishes);

                // Tính bảo hiểm
                double totalInsurranceRatio = SalaryUtil.CountTotalInsurranceRatio(insurrances);

                // Lấy bảng thuế
                List <TaxEntity> taxs = _humanManagerContext.Taxs.ToList();

                // Tính lương
                SalaryHistoryEntity salaryHistoryEntity =//
                                                          SalaryUtil.DoSalaryConting(employeeEntity, new DateTime(countingDate.year, countingDate.month, countingDate.day), miniumSalary, salaryCoefficient, regulationWorkDay, empWorkDay, rewardMoney, publishMoney, totalInsurranceRatio, taxs);

                // kiểm tra thay đổi lương
                SalaryHistoryEntity oldSalaryHistory = _humanManagerContext.SalaryHistories.Where(sh => sh.EmployeeId == employeeEntity.Id && sh.CountedDate.Month == countingDate.month && sh.CountedDate.Year == countingDate.year && sh.IsActive == true).SingleOrDefault();
                if (oldSalaryHistory == null || salaryHistoryEntity.NetSalary != oldSalaryHistory.NetSalary)
                {
                    // Chuyển trạng thái lương cũ
                    if (oldSalaryHistory != null)
                    {
                        oldSalaryHistory.IsActive = false;
                    }
                    // Lưu lương mới
                    salaryHistoryEntity = _humanManagerContext.SalaryHistories.Add(salaryHistoryEntity).Entity;
                    _humanManagerContext.SaveChanges();
                    transaction.Commit();
                }
                else
                {
                    transaction.Rollback();
                    return(false);
                }
                return(true);
            }
            catch (Exception ex)
            {
                transaction.Rollback();
                throw ex;
            }
        }