예제 #1
0
 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;
 }
예제 #2
0
 public Request Save(Request request)
 {
     using (var dataContext = _dataContextFactory.Create()) {
         if (request.Id == 0) {
             return _createRequest(request, dataContext);
         }
         return _updateRequest(request, dataContext);
     }
 }
예제 #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;
 }
예제 #4
0
 private RequestViewModel _toViewModel(Request request)
 {
     return new RequestViewModel {
         Id = request.Id,
         Author = _toViewModel(request.Author),
         DateCreated = request.DateCreated.ToString("g")
     };
 }
예제 #5
0
 private static Request _createRequest(Request request, IDataContext dataContext)
 {
     dataContext.CreateRequest(request);
     dataContext.SaveChanges();
     return request;
 }
예제 #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;
 }
예제 #7
0
 void IDataContext.DeleteRequest(Request request)
 {
     Requests.Remove(request);
 }
예제 #8
0
 void IDataContext.CreateRequest(Request request)
 {
     Users.Attach(request.Author);
     Requests.Add(request);
 }