public IEnumerable <ProductImageDto> GetAllProductImage(ProductImageDto request, int RequestUserId, string TokenKey) { try { CheckAuthentication(RequestUserId, TokenKey); var data = GetAllCachedData <ProductImageEntity>().Where(q => q.ProductId == request.ProductId).AsQueryable(); var predicate = PredicateBuilderHelper.True <ProductImageEntity>(); if (request.Id.HasValue) { predicate = predicate.And(q => q.Id == request.Id); } if (request.ActivationStatus > 0) { predicate = predicate.And(q => q.ActivationStatus == request.ActivationStatus); } if (!request.ImageUrl.IsNullOrEmpty()) { predicate = predicate.And(q => q.ImageUrl.Contains(request.ImageUrl)); } var result = data.Where(predicate).AsEnumerable(); return(result.ConvertTo <IEnumerable <ProductImageDto> >()); } catch (KnownException ex) { throw ex; } catch (Exception ex) { Logger.AddLog(LogTypeEnum.Error, "ProductManager.GetAllProductImage", RequestUserId, ex.Message, request.ToJson(), ex); throw new KnownException(ErrorTypeEnum.UnexpectedExeption, ex.Message, ex); } }
public ProductImageDto CreateOrUpdateProductImage(ProductImageDto dto, int RequestUserId, string TokenKey) { try { CheckAuthentication(RequestUserId, TokenKey); #region Empty Control if (dto.ImageUrl.IsNullOrEmpty()) { throw new RequestWarningException(ErrorTypeEnum.WarningException, ExceptionCodeHelper.CannotEmptyField, ExceptionMessageHelper.CannotEmptyField("ImageUrl")); } #endregion var data = GetAllCachedData <ProductTypeEntity>().ToList(); var entity = dto.ConvertTo <ProductTypeEntity>(); var conn = Db.CreateConnection(true); if (dto.Id > 0) { entity.UpdateUser = RequestUserId; entity.UpdateDate = DateTimeHelper.Now; conn.Update(entity, Db._DbTransaction); data.RemoveAt(data.FindIndex(q => q.Id == entity.Id)); } else { int Id = conn.Insert(entity, Db._DbTransaction).ToInt(); entity = conn.Get <ProductTypeEntity>(Id); } data.Add(entity); FillCacheData(data); return(entity.ConvertTo <ProductImageDto>()); } catch (KnownException ex) { throw ex; } catch (Exception ex) { Logger.AddLog(LogTypeEnum.Error, "ProductManager.CreateOrUpdateProductImage", RequestUserId, ex.Message, dto.ToJson(), ex); throw new KnownException(ErrorTypeEnum.UnexpectedExeption, ex.Message, ex); } }