예제 #1
0
 private bool ValidateStringLength(Semester Semester)
 {
     if (Semester.StartYear < 0 || Semester.StartYear.ToString().Length > 4)
     {
         Semester.AddError(nameof(SemesterValidator), nameof(Semester.StartYear), ERROR.StartYearInvalid);
         return(false);
     }
     if (Semester.EndYear < 0 || Semester.EndYear.ToString().Length > 4)
     {
         Semester.AddError(nameof(SemesterValidator), nameof(Semester.EndYear), ERROR.EndYearInvalid);
         return(false);
     }
     return(true);
 }
예제 #2
0
        public async Task <Semester> Create(Semester semester)
        {
            if (!await SemesterValidator.Create(semester))
            {
                return(semester);
            }

            using (UOW.Begin())
            {
                try
                {
                    semester.Id = Guid.NewGuid();

                    await UOW.SemesterRepository.Create(semester);

                    await UOW.Commit();

                    return(await Get(semester.Id));
                }
                catch (Exception e)
                {
                    await UOW.Rollback();

                    semester.AddError(nameof(SemesterService), nameof(Create), CommonEnum.ErrorCode.SystemError);
                    return(semester);
                }
            }
        }
예제 #3
0
        private async Task <bool> ValidateId(Semester Semester)
        {
            SemesterFilter filter = new SemesterFilter
            {
                Id = new GuidFilter {
                    Equal = Semester.Id
                }
            };

            int count = await UOW.SemesterRepository.Count(filter);

            if (count == 0)
            {
                Semester.AddError(nameof(SemesterValidator), nameof(Semester), ERROR.IdNotFound);
            }

            return(count == 1);
        }
예제 #4
0
        private async Task <bool> ValidateNotExist(Semester semester)
        {
            SemesterFilter filter = new SemesterFilter
            {
                StartYear = new ShortFilter {
                    Equal = semester.StartYear
                },
                EndYear = new ShortFilter {
                    Equal = semester.EndYear
                },
                IsFirstHalf = semester.IsFirstHalf
            };

            int count = await UOW.SemesterRepository.Count(filter);

            if (count > 0)
            {
                semester.AddError(nameof(SemesterValidator), nameof(semester), ERROR.SemesterExisted);
                return(false);
            }
            return(true);
        }
예제 #5
0
        public async Task <Semester> Delete(Semester semester)
        {
            if (!await SemesterValidator.Delete(semester))
            {
                return(semester);
            }

            using (UOW.Begin())
            {
                try
                {
                    await UOW.SemesterRepository.Delete(semester.Id);

                    await UOW.Commit();
                }
                catch (Exception e)
                {
                    await UOW.Rollback();

                    semester.AddError(nameof(SemesterService), nameof(Delete), CommonEnum.ErrorCode.SystemError);
                }
            }
            return(semester);
        }