コード例 #1
0
        private async Task <IResult> Update(UpdateUserLessonModel updateUserLessonModel, Expression <Func <UserLessonEntity, bool> > where)
        {
            var validation = new UserLessonModelValidator().Valid(updateUserLessonModel);

            if (!validation.Success)
            {
                return(new ErrorDataResult <long>(validation.Message));
            }

            var userLessonEntity = await UserLessonRepository.SingleOrDefaultAsync(where);

            var nullObjectValidation = new NullObjectValidation <UserLessonEntity>().Valid(userLessonEntity);

            if (!nullObjectValidation.Success)
            {
                return(new ErrorResult(nullObjectValidation.Message));
            }

            var userLessonDomain = UserLessonDomainFactory.Create(updateUserLessonModel);

            userLessonDomain.Update(updateUserLessonModel);

            userLessonEntity = userLessonDomain.Map <UserLessonEntity>();

            await UserLessonRepository.UpdateAsync(userLessonEntity, userLessonEntity.UserLessonId);

            await DatabaseUnitOfWork.SaveChangesAsync();

            return(new SuccessResult());
        }
コード例 #2
0
        public async Task <IDataResult <long> > AddAsync(AddUserLessonModel addUserLessonModel)
        {
            var validation = new AddUserLessonModelValidator().Valid(addUserLessonModel);

            if (!validation.Success)
            {
                return(new ErrorDataResult <long>(validation.Message));
            }

            var userLessonDomain = UserLessonDomainFactory.Create(addUserLessonModel);

            var userLessonEntity = userLessonDomain.Map <UserLessonEntity>();

            await UserLessonRepository.AddAsync(userLessonEntity);

            await DatabaseUnitOfWork.SaveChangesAsync();

            return(new SuccessDataResult <long>(userLessonEntity.UserLessonId));
        }