Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
Extend PictureService
Browse files Browse the repository at this point in the history
  • Loading branch information
KrzysztofPajak committed Jun 25, 2020
1 parent b132ba9 commit 52ff58e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
7 changes: 7 additions & 0 deletions Grand.Services/Media/IPictureService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,13 @@ Task<Picture> UpdatePicture(string pictureId, byte[] pictureBinary, string mimeT
string seoFilename, string altAttribute = null, string titleAttribute = null,
bool isNew = true, bool validateBinary = true);

/// <summary>
/// Updates the picture
/// </summary>
/// <param name="picture">Picture</param>
/// <returns>Picture</returns>
Task<Picture> UpdatePicture(Picture picture);

/// <summary>
/// Updates a SEO filename of a picture
/// </summary>
Expand Down
18 changes: 18 additions & 0 deletions Grand.Services/Media/PictureService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,24 @@ public virtual async Task<Picture> UpdatePicture(string pictureId, byte[] pictur
return picture;
}

/// <summary>
/// Updates the picture
/// </summary>
/// <param name="picture">Picture</param>
/// <returns>Picture</returns>
public virtual async Task<Picture> UpdatePicture(Picture picture)
{
if (picture == null)
throw new ArgumentNullException("picture");

await _pictureRepository.UpdateAsync(picture);

//event notification
await _mediator.EntityUpdated(picture);

return picture;
}

/// <summary>
/// Save picture on file system
/// </summary>
Expand Down
9 changes: 4 additions & 5 deletions Grand.Web/Areas/Admin/Controllers/SettingController.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Grand.Core;
using Grand.Core.Caching;
using Grand.Core.Configuration;
using Grand.Core.Data;
using Grand.Core.Domain;
using Grand.Core.Domain.AdminSearch;
using Grand.Core.Domain.Blogs;
Expand Down Expand Up @@ -1434,15 +1433,15 @@ public async Task<IActionResult> Media(MediaSettingsModel model)
}
[HttpPost, ActionName("Media")]
[FormValueRequired("change-picture-storage")]
public async Task<IActionResult> ChangePictureStorage([FromServices] IRepository<Picture> pictureRepository, [FromServices] MediaSettings mediaSettings)
public async Task<IActionResult> ChangePictureStorage([FromServices] MediaSettings mediaSettings)
{
var storeIdDb = !mediaSettings.StoreInDb;

//save the new setting value
await _settingService.SetSetting("MediaSettings.StoreInDb", storeIdDb, "");

int pageIndex = 0;
const int pageSize = 400;
const int pageSize = 100;
try
{
while (true)
Expand All @@ -1462,9 +1461,9 @@ public async Task<IActionResult> ChangePictureStorage([FromServices] IRepository
_pictureService.SavePictureInFile(picture.Id, pictureBinary, picture.MimeType);
picture.PictureBinary = storeIdDb ? pictureBinary : new byte[0];
picture.IsNew = true;

await _pictureService.UpdatePicture(picture);
}
//save all at once
pictureRepository.Update(pictures);
}
}
finally
Expand Down

0 comments on commit 52ff58e

Please sign in to comment.