コード例 #1
0
        //Add ImageFileUrl (async)
        public async Task <int> AddImageFileUrlAsync(ImageFileUrlDTO modelDTO)
        {
            try
            {
                using (var unitOfWork = unitOfWorkFactory.Create())
                {
                    //var tempImageType = await unitOfWork.ImageFileTypeRepository.GetSingleOrDefaultAsync(x => x.Type.Contains("BookImage"));

                    //modelDTO.ImageFileUrl = new ImageFileUrlDTO()
                    //{
                    //    Url = modelDTO._ImageFileUrl,
                    //    CreateDate = DateTime.Now,
                    //    ImageFileType = new ImageFileTypeDTO { ImageFileTypeId = tempImageType.ImageFileTypeId, Type = tempImageType.Type }
                    //};

                    ImageFileUrlModel model = _Mapper_ToModel.Map <ImageFileUrlDTO, ImageFileUrlModel>(modelDTO);

                    unitOfWork.ImageFileUrlRepository.Add(model);
                    //unitOfWork.Repository.Add<ImageFileUrlModel>(model);
                    await unitOfWork.SaveChangesAsync();

                    return(model.ImageFileUrlId);
                }
            }
            catch (Exception ex)
            {
                LogException(ex);
                throw ex;
            }
        }
コード例 #2
0
 public void Add(ImageFileUrlModel entity)
 {
     try
     {
         _dbContext.Entry(entity).State = EntityState.Added;
     }
     catch (Exception ex)
     {
         LogException(ex);
         throw ex;
     }
 }
コード例 #3
0
        public void Remove(ImageFileUrlModel entity)
        {
            try
            {
                _dbContext.Entry(entity).State = EntityState.Deleted;

                //return await (_dbContext.SaveChangesAsync());
            }
            catch (Exception ex)
            {
                LogException(ex);
                throw ex;
            }
        }
コード例 #4
0
        //Find Single Homework base on "term" (async)
        public async Task <ImageFileUrlDTO> SearchSingleImageFileUrlByIdAsync(int Id)
        {
            try
            {
                using (var unitOfWork = unitOfWorkFactory.Create())
                {
                    ImageFileUrlModel model = await Task.Run(() => unitOfWork.ImageFileUrlRepository.GetSingleOrDefaultImageFileUrl(x => x.ImageFileUrlId == Id));

                    return(_Mapper_ToDTO.Map <ImageFileUrlModel, ImageFileUrlDTO>(model));
                }
            }
            catch (Exception ex)
            {
                LogException(ex);
                throw ex;
            }
        }
コード例 #5
0
        public bool Update(ImageFileUrlModel entity)
        {
            try
            {
                var currentEntity = _dbContext.Set <ImageFileUrlModel>().AsQueryable().FirstOrDefault(x => x.ImageFileUrlId == entity.ImageFileUrlId);
                if (currentEntity == null)
                {
                    return(false);
                }
                currentEntity.Url            = entity.Url;
                currentEntity.CreateDate     = entity.CreateDate;
                currentEntity.ImageFileUrlId = entity.ImageFileUrlId;

                return(true);
            }
            catch (Exception ex)
            {
                LogException(ex);
                throw ex;
            }
        }