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);
     }
 }
Beispiel #3
0
 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;
 }
Beispiel #4
0
 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;
 }
Beispiel #6
0
 public void UpdateRequest(Request request)
 {
     Users.Attach(request.Author);
     Requests.Attach(request);
     Entry(request).State = EntityState.Modified;
     Entry(request).Property(_ => _.DateCreated).IsModified = false;
 }
Beispiel #7
0
 void IDataContext.DeleteRequest(Request request)
 {
     Requests.Remove(request);
 }
Beispiel #8
0
 void IDataContext.CreateRequest(Request request)
 {
     Users.Attach(request.Author);
     Requests.Add(request);
 }