示例#1
0
        public async Task <IResponse <int> > AddRangeAsync(ProductAddRangeModel model)
        {
            var products = model.Posts.Select(x => new Product
            {
                ProductCategoryId = null,
                StoreId           = model.StoreId,
                Name          = x.Description.Length > 35 ? x.Description.Substring(0, 34) : x.Description,
                Description   = x.Description,
                Price         = x.Price,
                IsActive      = true,
                ProductAssets = x.Assets?.Select(a => new ProductAsset
                {
                    FileType     = a.Type,
                    Extention    = ".png",
                    Name         = "post-image",
                    UniqueId     = a.UniqueId,
                    FileUrl      = a.FileUrl,
                    ThumbnailUrl = a.ThumbnailUrl
                }).OrderByDescending(x => x.UniqueId).Take(3).ToList()
            }).ToList();
            await _productRepo.AddRangeAsync(products);

            var save = await _appUow.ElkSaveChangesAsync();

            return(new Response <int>
            {
                IsSuccessful = save.IsSuccessful,
                Result = save.Result,
                Message = save.Message
            });
        }