private static Request _updateRequest(Request request, IDataContext dataContext) { var dbRequest = dataContext.Requests.Single(_ => _.Id == request.Id); var dbAuthor = dataContext.Users.Single(_ => _.Id == request.Author.Id); dbRequest.Author = dbAuthor; dbRequest.Description = request.Description; dataContext.SaveChanges(); return dbRequest; }
public Request Save(Request request) { using (var dataContext = _dataContextFactory.Create()) { if (request.Id == 0) { return _createRequest(request, dataContext); } return _updateRequest(request, dataContext); } }
private RequestCreateViewModel _toCreateViewModel(Request request) { var requestUpdateViewModel = new RequestCreateViewModel { Id = request.Id, Author = _toViewModel(request.Author), DateCreated = request.DateCreated.ToString("g"), Description = request.Description, }; _setUsersCollection(requestUpdateViewModel); return requestUpdateViewModel; }
private RequestViewModel _toViewModel(Request request) { return new RequestViewModel { Id = request.Id, Author = _toViewModel(request.Author), DateCreated = request.DateCreated.ToString("g") }; }
private static Request _createRequest(Request request, IDataContext dataContext) { dataContext.CreateRequest(request); dataContext.SaveChanges(); return request; }
public void UpdateRequest(Request request) { Users.Attach(request.Author); Requests.Attach(request); Entry(request).State = EntityState.Modified; Entry(request).Property(_ => _.DateCreated).IsModified = false; }
void IDataContext.DeleteRequest(Request request) { Requests.Remove(request); }
void IDataContext.CreateRequest(Request request) { Users.Attach(request.Author); Requests.Add(request); }