Example #1
0
 protected override IApprovalDto Create(int performingUserId, IApprovalDto approvalDto)
 {
     using (var context = new PrometheusContext())
     {
         var approval = context.Approvals.Find(approvalDto.Id);
         if (approval != null)
         {
             throw new InvalidOperationException(string.Format("Approval with ID {0} already exists.", approvalDto.Id));
         }
         var saved = context.Approvals.Add(ManualMapper.MapDtoToApproval(approvalDto));
         context.SaveChanges(performingUserId);
         return(ManualMapper.MapApprovalToDto(saved));
     }
 }
Example #2
0
 protected override IApprovalDto Update(int performingUserId, IApprovalDto approvalDto)
 {
     using (var context = new PrometheusContext())
     {
         if (!context.Approvals.Any(x => x.Id == approvalDto.Id))
         {
             throw new InvalidOperationException(string.Format("Approval with ID {0} cannot be updated since it does not exist.", approvalDto.Id));
         }
         var updated = ManualMapper.MapDtoToApproval(approvalDto);
         context.Approvals.Attach(updated);
         context.Entry(updated).State = EntityState.Modified;
         context.SaveChanges(performingUserId);
         return(ManualMapper.MapApprovalToDto(updated));
     }
 }