private bool ValidateStringLength(ExamProgram examProgram) { if (string.IsNullOrEmpty(examProgram.Name)) { examProgram.AddError(nameof(ExamProgramValidator), nameof(examProgram.Name), ERROR.StringEmpty); return(false); } else if (examProgram.Name.Length > 100) { examProgram.AddError(nameof(ExamProgramValidator), nameof(examProgram.Name), ERROR.StringLimited); return(false); } if (string.IsNullOrEmpty(examProgram.SemesterCode)) { examProgram.AddError(nameof(ExamProgramValidator), nameof(examProgram.SemesterCode), ERROR.SemesterCodeEmpty); return(false); } else if (Regex.IsMatch(examProgram.SemesterCode, @"^\d{4}_\d{4}_\d") == false) { examProgram.AddError(nameof(ExamProgramValidator), nameof(examProgram.SemesterCode), ERROR.SemesterCodeInValid); return(false); } return(true); }
public async Task <ExamProgram> Delete(ExamProgram examProgram) { if (!await ExamProgramValidator.Delete(examProgram)) { return(examProgram); } using (UOW.Begin()) { try { examProgram = await UOW.ExamProgramRepository.Get(examProgram.Id); await UOW.ExamProgramRepository.Delete(examProgram.Id); await UOW.Commit(); } catch (Exception e) { await UOW.Rollback(); examProgram.AddError(nameof(ExamProgramService), nameof(Delete), CommonEnum.ErrorCode.SystemError); } } return(examProgram); }
public async Task <ExamProgram> Create(ExamProgram examProgram) { if (!await ExamProgramValidator.Create(examProgram)) { return(examProgram); } using (UOW.Begin()) { try { examProgram.Id = Guid.NewGuid(); examProgram = await GetSemesterId(examProgram); await UOW.ExamProgramRepository.Create(examProgram); await UOW.Commit(); return(examProgram); } catch (Exception e) { await UOW.Rollback(); examProgram.AddError(nameof(ExamProgramService), nameof(Create), CommonEnum.ErrorCode.SystemError); return(examProgram); } } }
/*private async Task<bool> ValidateExist(ExamProgram ExamProgram) * { * ExamProgramFilter filter = new ExamProgramFilter * { * Name = new StringFilter { Equal = ExamProgram.Name }, * SemesterCode = new StringFilter { Equal = ExamProgram.SemesterCode } * }; * * int count = await UOW.ExamProgramRepository.Count(filter); * if (count == 0) * { * ExamProgram.AddError(nameof(ExamProgramValidator), nameof(ExamProgram), ERROR.NotExisted); * return false; * } * return true; * }*/ public async Task <bool> ValidateId(ExamProgram examProgram) { ExamProgramFilter filter = new ExamProgramFilter { Id = new GuidFilter { Equal = examProgram.Id }, }; int count = await UOW.ExamProgramRepository.Count(filter); if (count == 0) { examProgram.AddError(nameof(ExamProgramValidator), nameof(examProgram), ERROR.IdNotFound); } return(count == 1); }
private async Task <bool> ValidateNotExist(ExamProgram ExamProgram) { ExamProgramFilter filter = new ExamProgramFilter { Take = Int32.MaxValue, Name = new StringFilter { Equal = ExamProgram.Name }, SemesterCode = new StringFilter { Equal = ExamProgram.SemesterCode } }; int count = await UOW.ExamProgramRepository.Count(filter); if (count > 0) { ExamProgram.AddError(nameof(ExamProgramValidator), nameof(ExamProgram), ERROR.ExamProgramExisted); return(false); } return(true); }
public async Task <ExamProgram> SetCurrentExamProgram(ExamProgram examProgram) { // Không cần validator // Đặt tất cả các ExamProgram có current==true về false và đặt ExamProgram trong params thành true using (UOW.Begin()) { try { ExamProgramFilter filter = new ExamProgramFilter { IsCurrent = true }; ExamProgram currentExamProgram = await UOW.ExamProgramRepository.Get(filter); if (currentExamProgram != null) { currentExamProgram.IsCurrent = false; await UOW.ExamProgramRepository.Update(currentExamProgram); } examProgram = await UOW.ExamProgramRepository.Get(examProgram.Id); examProgram.IsCurrent = true; await UOW.ExamProgramRepository.Update(examProgram); //await UOW.ExamProgramRepository.Active(examProgram.Id); await UOW.Commit(); return(examProgram); } catch (Exception) { await UOW.Rollback(); examProgram.AddError(nameof(ExamProgramService), nameof(SetCurrentExamProgram), CommonEnum.ErrorCode.SystemError); return(examProgram); } } }