public JsonResult ChangeOrder(PhotoSortModel model) { try { _photoService.ChangeOrder(model); return(Json(MyAjaxHelper.GetSuccessResponse())); } catch (Exception exception) { Log.RegisterError(exception); return(Json(MyAjaxHelper.GetErrorResponse(exception.Message))); } }
public void ChangeOrder(PhotoSortModel model) { var photos = GetAll(); var currentPhoto = photos.FirstOrDefault(x => x.Id == model.CurrentId); var swappedPhoto = photos.FirstOrDefault(x => x.Id == model.SwappedId); currentPhoto.Order = currentPhoto.Order == default(int) ? model.CurrentId : currentPhoto.Order; swappedPhoto.Order = swappedPhoto.Order == default(int) ? model.SwappedId : swappedPhoto.Order; int temp = currentPhoto.Order; currentPhoto.Order = swappedPhoto.Order; swappedPhoto.Order = temp; _providerPhoto.UpdateOne(currentPhoto); _providerPhoto.Commit(); _providerPhoto.UpdateOne(swappedPhoto); _providerPhoto.Commit(); }