Exemple #1
0
        public KpiPeriodConfigDTO Add(KpiPeriodConfigDTO dto)
        {
            var entity = AutoMapperHelper.Map <KpiPeriodConfigDTO, Sys_KpiPeriodConfig>(dto);
            var kpi    = _repo.SelectWhere(k => k.YearMonth == dto.YearMonth).FirstOrDefault();

            if (kpi != null)
            {
                var yearMonthstr = "";
                try
                {
                    yearMonthstr = dto.YearMonth.ToString();
                    yearMonthstr = dto.YearMonth.ToString().Substring(4) + "/" + dto.YearMonth.ToString().Substring(0, 4);
                }
                catch (Exception)
                {
                }
                throw new Exception("Kỳ đánh giá đã tồn tại");
            }


            if (string.IsNullOrWhiteSpace(dto.Code))
            {
                throw new Exception("Chưa nhập mã");
            }

            if (string.IsNullOrWhiteSpace(dto.PeriodConfig))
            {
                throw new Exception("Chưa nhập kỳ đánh giá");
            }

            // khong cho ngay bat dau truoc ngay ket thuc
            if (dto.FromDate.Date >= dto.ToDate.Date)
            {
                throw new Exception("Ngày bắt đầu phải nhỏ hơn ngày kết thúc");
            }

            // khong cho ngay bat dau truoc ngay ket thuc
            if (dto.FromDate.Date >= dto.ToDate.Date)
            {
                throw new Exception("Ngày bắt đầu phải nhỏ hơn ngày kết thúc");
            }

            dto.MonthNumber = dto.ToDate.Month;
            IKpiEvaluationRepository kpiRepo = new KpiEvaluationRepository(_unitOfWork);

            kpiRepo.CreateKpiGlobal(dto);

            //using (var transaction = _unitOfWork.BeginTransaction())
            //{
            //    // add kpi period config
            //    entity = _repo.Add(entity);
            //    _unitOfWork.SaveChanges();
            //    transaction.Commit();
            //}

            return(AutoMapperHelper.Map <Sys_KpiPeriodConfig, KpiPeriodConfigDTO>(entity));
        }
Exemple #2
0
        public KpiEvaluationRepoIntergrationTest()
        {
            var uow = new UnitOfWork();

            _repo = new KpiEvaluationRepository(uow);
        }