Example #1
0
 protected override IRoleDto Create(int performingUserId, IRoleDto roleDto)
 {
     using (var context = new PrometheusContext())
     {
         var role = context.Roles.Find(roleDto.Id);
         if (role != null)
         {
             throw new InvalidOperationException(string.Format("Role with ID {0} already exists.", roleDto.Id));
         }
         var savedRole = context.Roles.Add(ManualMapper.MapDtoToRole(roleDto));
         context.SaveChanges(performingUserId);
         return(ManualMapper.MapRoleToDto(savedRole));
     }
 }
Example #2
0
 protected override IRoleDto Update(int performingUserId, IRoleDto roleDto)
 {
     using (var context = new PrometheusContext())
     {
         if (!context.Roles.Any(x => x.Id == roleDto.Id))
         {
             throw new InvalidOperationException(string.Format("Role with ID {0} cannot be updated since it does not exist.",
                                                               roleDto.Id));
         }
         var updatedRole = ManualMapper.MapDtoToRole(roleDto);
         context.Roles.Attach(updatedRole);
         context.Entry(updatedRole).State = EntityState.Modified;
         context.SaveChanges(performingUserId);
         return(ManualMapper.MapRoleToDto(updatedRole));
     }
 }