From 5dd9857011021e6e8072e53339cf0ca4e0e002e1 Mon Sep 17 00:00:00 2001 From: tidusjar Date: Fri, 18 Mar 2016 11:51:35 +0000 Subject: [PATCH] Modified the adding of request to update the model with the added ID --- PlexRequests.Core/JsonRequestService.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/PlexRequests.Core/JsonRequestService.cs b/PlexRequests.Core/JsonRequestService.cs index 450dc8822..9980b1648 100644 --- a/PlexRequests.Core/JsonRequestService.cs +++ b/PlexRequests.Core/JsonRequestService.cs @@ -44,12 +44,16 @@ namespace PlexRequests.Core private IRequestRepository Repo { get; } public long AddRequest(int providerId, RequestedModel model) { - var latestId = Repo.GetAll().OrderByDescending(x => x.Id).Select(x => x.Id).FirstOrDefault(); - var newId = latestId + 1; - model.Id = newId; var entity = new RequestBlobs { Type = model.Type, Content = ReturnBytes(model), ProviderId = model.ProviderId}; - return Repo.Insert(entity); + var id = Repo.Insert(entity); + + model.Id = (int)id; + + entity = new RequestBlobs { Type = model.Type, Content = ReturnBytes(model), ProviderId = model.ProviderId, Id = (int)id}; + var result = Repo.Update(entity); + + return result ? id : -1; } public bool CheckRequest(int providerId)